Fix Nextcloud multipart backups being only slightly rotated

This commit is contained in:
Salt 2020-05-06 09:46:45 -05:00
parent c3fa85aacb
commit 3a33549174

View File

@ -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