allow passing prefix to limit pruning ops

This commit is contained in:
Frederik Ring 2021-08-19 13:41:19 +02:00
parent 8c7ffc3d99
commit 0069faa7fd
2 changed files with 16 additions and 2 deletions

View File

@ -51,11 +51,12 @@ AWS_S3_BUCKET_NAME="<xxx>"
# **IMPORTANT, PLEASE READ THIS BEFORE USING THIS FEATURE**: # **IMPORTANT, PLEASE READ THIS BEFORE USING THIS FEATURE**:
# The mechanism used for pruning backups is not very sophisticated # 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, # which means that if you are storing your backups next to other files,
# these might become subject to deletion too. When using this option # these might become subject to deletion too. When using this option
# make sure the backup files are stored in a directory used exclusively # 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 # Define this value to enable automatic pruning of old backups. The value
# declares the number of days for which a backup is kept. # declares the number of days for which a backup is kept.
@ -71,6 +72,15 @@ AWS_S3_BUCKET_NAME="<xxx>"
# BACKUP_PRUNING_LEEWAY="10m" # 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 ########### BACKUP ENCRYPTION
# Backups can be encrypted using gpg in case a passphrase is given # Backups can be encrypted using gpg in case a passphrase is given

View File

@ -105,6 +105,10 @@ echo "Will wait for next scheduled backup."
prune () { prune () {
target=$1 target=$1
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
target="$target/${BACKUP_PRUNING_PREFIX}"
fi
rule_applies_to=$( rule_applies_to=$(
mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \ mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \
--older-than "${BACKUP_RETENTION_DAYS}d" \ --older-than "${BACKUP_RETENTION_DAYS}d" \