From edf6307524829ccb41d8eda81478304fb2678768 Mon Sep 17 00:00:00 2001 From: Takeshi Takizawa Date: Wed, 28 Aug 2019 19:22:42 +0900 Subject: [PATCH] Support no backup file case. If there is no backup file then `grep` exit with nonzero code. So use `find` instead of it. --- backup/pvc/bin/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backup/pvc/bin/run.sh b/backup/pvc/bin/run.sh index 29f0eb96..e4649fb3 100644 --- a/backup/pvc/bin/run.sh +++ b/backup/pvc/bin/run.sh @@ -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 \ No newline at end of file +done