Support no backup file case.

If there is no backup file then `grep` exit with nonzero code.
So use `find` instead of it.
This commit is contained in:
Takeshi Takizawa 2019-08-28 19:22:42 +09:00
parent fed512873c
commit edf6307524
1 changed files with 2 additions and 2 deletions

View File

@ -10,6 +10,6 @@ do
sleep 10
if [[ ! -z "${BACKUP_COUNT}" ]]; then
echo "Trimming to only ${BACKUP_COUNT} recent backups in preparation for new backup"
ls ${BACKUP_DIR} | sort -gr | grep 'tar.gz' | tail -n +$((BACKUP_COUNT +1)) | xargs -I '{}' rm ${BACKUP_DIR}/'{}'
find ${BACKUP_DIR} -name '*.tar.gz' -exec basename {} \; | sort -gr | tail -n +$((BACKUP_COUNT +1)) | xargs -I '{}' rm ${BACKUP_DIR}/'{}'
fi
done
done