From 0069faa7fd2aa802a00850b77fc50c43ea4a4b6f Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Thu, 19 Aug 2021 13:41:19 +0200 Subject: [PATCH] allow passing prefix to limit pruning ops --- README.md | 14 ++++++++++++-- src/backup.sh | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77a9925..5b14b02 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,12 @@ AWS_S3_BUCKET_NAME="" # **IMPORTANT, PLEASE READ THIS BEFORE USING THIS FEATURE**: # The mechanism used for pruning backups is not very sophisticated -# and applies its rules to **all files in the target directory**, +# and applies its rules to **all files in the target directory** by default, # which means that if you are storing your backups next to other files, # these might become subject to deletion too. When using this option # make sure the backup files are stored in a directory used exclusively -# for storing them or you might lose data. +# for storing them or to configure BACKUP_PRUNING_PREFIX to limit +# removal to certain files. # Define this value to enable automatic pruning of old backups. The value # declares the number of days for which a backup is kept. @@ -71,6 +72,15 @@ AWS_S3_BUCKET_NAME="" # BACKUP_PRUNING_LEEWAY="10m" +# In case your target bucket or directory contains other files than the ones +# managed by this container, you can limit the scope of rotation by setting +# a prefix value. This would usually be the non-parametrized part of your +# BACKUP_FILENAME. E.g. if BACKUP_FILENAME is `db-backup-%Y-%m-%dT%H-%M-%S.tar.gz`, +# you can set BACKUP_PRUNING_PREFIX to `db-backup-` and make sure +# unrelated files are not affected. + +# BACKUP_PRUNING_PREFIX="backup-" + ########### BACKUP ENCRYPTION # Backups can be encrypted using gpg in case a passphrase is given diff --git a/src/backup.sh b/src/backup.sh index 621d7cf..d68c0ea 100644 --- a/src/backup.sh +++ b/src/backup.sh @@ -105,6 +105,10 @@ echo "Will wait for next scheduled backup." prune () { target=$1 + if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then + target="$target/${BACKUP_PRUNING_PREFIX}" + fi + rule_applies_to=$( mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \ --older-than "${BACKUP_RETENTION_DAYS}d" \