From b7ba0e08dfc383cc355166fa08fe12c7bb0ce11b Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 20 Aug 2021 21:51:45 +0200 Subject: [PATCH] prefix mtime param with a +, use -name param for passing pattern to find --- src/backup.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/backup.sh b/src/backup.sh index b93f954..08b600f 100644 --- a/src/backup.sh +++ b/src/backup.sh @@ -107,11 +107,14 @@ probe_expired () { local target=$1 local is_local=$2 if [ -z "$is_local" ]; then + if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then + target="${target}/${BACKUP_PRUNING_PREFIX}" + fi mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \ --older-than "${BACKUP_RETENTION_DAYS}d" \ "$target" else - find $target* -type f -mtime $BACKUP_RETENTION_DAYS + find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f -mtime "+${BACKUP_RETENTION_DAYS}" fi } @@ -119,9 +122,12 @@ probe_all () { local target=$1 local is_local=$2 if [ -z "$is_local" ]; then + if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then + target="${target}/${BACKUP_PRUNING_PREFIX}" + fi mc ls $MC_GLOBAL_OPTIONS "$target" else - find $target* -type f + find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f fi } @@ -129,21 +135,20 @@ delete () { local target=$1 local is_local=$2 if [ -z "$is_local" ]; then + if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then + target="${target}/${BACKUP_PRUNING_PREFIX}" + fi mc rm $MC_GLOBAL_OPTIONS --recursive --force \ --older-than "${BACKUP_RETENTION_DAYS}d" \ "$target" else - find $target* -delete -type f -mtime $BACKUP_RETENTION_DAYS + find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f -mtime "+${BACKUP_RETENTION_DAYS}" -delete fi } prune () { local target=$1 local is_local=$2 - if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then - target="$target/${BACKUP_PRUNING_PREFIX}" - fi - rule_applies_to=$(probe_expired "$target" "$is_local" | wc -l) if [ "$rule_applies_to" == "0" ]; then echo "No backups found older than the configured retention period of ${BACKUP_RETENTION_DAYS} days."