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 # Purge oldest backup if we need to
currentbackupcount="$(ls -1 "$OUTDIR" | wc -l)" currentbackupcount="$(ls -1 "$OUTDIR" | wc -l)"
if (( currentbackupcount >= retention )); then # Multiplying by three here because our backups are three-parters
lastbackup="$(find "$OUTDIR" -name \*.zip 2>/dev/null | sort | head -n 1)" if (( currentbackupcount >= retention * 3 )); then
if [ -f "$lastbackup" ]; then lastbackup="$(find "$OUTDIR" -name \*.tar.gz 2>/dev/null | sort | head -n 1)"
log "Removing old backup: $lastbackup" lastbackup="${lastbackup%-*.gz}"
rm "$lastbackup" 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
fi fi
# WE MAKE BACKUP NOW SERGEI # WE MAKE BACKUP NOW SERGEI