2024-09-26 09:39:21 -05:00
|
|
|
# Set the backup directory
|
2025-01-06 00:01:58 -06:00
|
|
|
BACKUP_DIR="/mnt/storagebox/forgejo/backup"
|
2024-09-26 09:39:21 -05:00
|
|
|
|
2025-01-03 17:38:24 -06:00
|
|
|
KEEP_NUM=7
|
2024-09-26 09:39:21 -05:00
|
|
|
|
|
|
|
echo "Starting backup cleanup process..."
|
|
|
|
echo "Keeping the $KEEP_NUM most recent backups in $BACKUP_DIR"
|
|
|
|
|
|
|
|
# Find all backup files, sort by modification time (newest first),
|
2025-01-03 19:49:01 -06:00
|
|
|
# skip the first KEEP_NUM, and delete the rest
|
2024-09-26 09:39:21 -05:00
|
|
|
find "$BACKUP_DIR" -type f -name "forgejo-dump-*" -print0 |
|
|
|
|
sort -z -t_ -k2 -r |
|
|
|
|
tail -z -n +$((KEEP_NUM + 1)) |
|
|
|
|
while IFS= read -r -d '' file; do
|
|
|
|
echo "Deleting: $file"
|
|
|
|
rm -f "$file"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Cleanup complete. Deleted all but the $KEEP_NUM most recent backups."
|