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