From 3a3354917439b64953e0df9461dc21b37c7b4533 Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 6 May 2020 09:46:45 -0500 Subject: [PATCH] Fix Nextcloud multipart backups being only slightly rotated --- roles/nextcloud/templates/backup.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/roles/nextcloud/templates/backup.sh b/roles/nextcloud/templates/backup.sh index f5169be..cbb3d42 100644 --- a/roles/nextcloud/templates/backup.sh +++ b/roles/nextcloud/templates/backup.sh @@ -29,11 +29,16 @@ chmod 770 "$OUTDIR" # Purge oldest backup if we need to currentbackupcount="$(ls -1 "$OUTDIR" | wc -l)" -if (( currentbackupcount >= retention )); then - lastbackup="$(find "$OUTDIR" -name \*.zip 2>/dev/null | sort | head -n 1)" - if [ -f "$lastbackup" ]; then - log "Removing old backup: $lastbackup" - rm "$lastbackup" +# Multiplying by three here because our backups are three-parters +if (( currentbackupcount >= retention * 3 )); then + lastbackup="$(find "$OUTDIR" -name \*.tar.gz 2>/dev/null | sort | head -n 1)" + lastbackup="${lastbackup%-*.gz}" + if [ -f "$file" ]; then + log "Removing old backups for: $lastbackup" + for file in "$OUTDIR"/"$lastbackup"*; do + log "Removing old backup part: $file" + rm "$file" + done fi fi # WE MAKE BACKUP NOW SERGEI