From bd6012dfb1cede1af1e2d384d8b1013dd7833c8d Mon Sep 17 00:00:00 2001 From: David Ashford Date: Wed, 7 Aug 2019 16:11:13 +0100 Subject: [PATCH] add grep command to only filter backups --- backup/pvc/bin/run.sh | 2 +- backup/pvc/e2e/limit_backup_count/test.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backup/pvc/bin/run.sh b/backup/pvc/bin/run.sh index c6cf2c9c..29f0eb96 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 | tail -n +$((BACKUP_COUNT +1)) | xargs -I '{}' rm ${BACKUP_DIR}/'{}' + ls ${BACKUP_DIR} | sort -gr | grep 'tar.gz' | tail -n +$((BACKUP_COUNT +1)) | xargs -I '{}' rm ${BACKUP_DIR}/'{}' fi done \ No newline at end of file diff --git a/backup/pvc/e2e/limit_backup_count/test.sh b/backup/pvc/e2e/limit_backup_count/test.sh index b364e8c6..b26a59fa 100755 --- a/backup/pvc/e2e/limit_backup_count/test.sh +++ b/backup/pvc/e2e/limit_backup_count/test.sh @@ -17,6 +17,7 @@ JENKINS_HOME="$(pwd)/jenkins_home" BACKUP_DIR="$(pwd)/backup" mkdir -p ${BACKUP_DIR} +mkdir -p ${BACKUP_DIR}/lost+found touch ${BACKUP_DIR}/1.tar.gz touch ${BACKUP_DIR}/2.tar.gz touch ${BACKUP_DIR}/3.tar.gz @@ -46,7 +47,7 @@ if [[ "${DEBUG}" ]]; then fi # only two latest backup should exists -[[ $(ls -1 ${BACKUP_DIR} | wc -l) -eq 2 ]] || exit 1 +[[ $(ls -1 ${BACKUP_DIR} | grep 'tar.gz' | wc -l) -eq 2 ]] || exit 1 [[ -f ${BACKUP_DIR}/11.tar.gz ]] || exit 2 [[ -f ${BACKUP_DIR}/12.tar.gz ]] || exit 3 echo PASS