From 2892369677b042262a13c52c3b8a1547bce94ebc Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Thu, 8 Apr 2021 08:17:55 +0200 Subject: [PATCH] sleep 10 minutes before pruning backups if pruning happens immediatley after taking the backup a race condition can occur where a backup that would theoretically be eligible won't be pruned as the current backup run was very fast, putting the potential candidate just at the very edge of the selected time window --- src/backup.sh | 1 + src/entrypoint.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/src/backup.sh b/src/backup.sh index cc679bb..7bac777 100644 --- a/src/backup.sh +++ b/src/backup.sh @@ -72,6 +72,7 @@ echo "Will wait for next scheduled backup." if [ ! -z "$BACKUP_RETENTION_DAYS" ]; then info "Pruning old backups" + echo "Sleeping ${BACKUP_PRUNING_LEEWAY} before checking eligibility." bucket=$AWS_S3_BUCKET_NAME rule_applies_to=$(mc rm --fake --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket" | wc -l) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 30c93de..dedd7e0 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -15,6 +15,7 @@ BACKUP_CRON_EXPRESSION="${BACKUP_CRON_EXPRESSION:-@daily}" BACKUP_FILENAME=${BACKUP_FILENAME:-"backup-%Y-%m-%dT%H-%M-%S.tar.gz"} BACKUP_RETENTION_DAYS="${BACKUP_RETENTION_DAYS:-}" +BACKUP_PRUNING_LEEWAY="${BACKUP_PRUNING_LEEWAY:-10m}" AWS_S3_BUCKET_NAME="${AWS_S3_BUCKET_NAME:-}" AWS_ENDPOINT="${AWS_ENDPOINT:-s3.amazonaws.com}"