From 004ab36c07344df66404a58c7b7949fb0594725c Mon Sep 17 00:00:00 2001 From: Daniel Legt Date: Thu, 18 Jan 2024 21:50:15 +0200 Subject: [PATCH] * Auto Remover --- gitea/gitea_backup.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gitea/gitea_backup.sh b/gitea/gitea_backup.sh index 5eedcae..aa9cd7e 100755 --- a/gitea/gitea_backup.sh +++ b/gitea/gitea_backup.sh @@ -38,6 +38,18 @@ backup_from_docker() { exit 1 fi + # Keep only the last $KEEP_BACKUP_COUNT backups + if [ -n "$KEEP_BACKUP_COUNT" ]; then + # Get the number of backup files + BACKUP_COUNT=$(ls -1 $BACKUP_SOURCE_PATH/gitea-dump-*.zip | wc -l) + + # Check if the current number of backups exceeds the limit + if [ "$BACKUP_COUNT" -gt "$KEEP_BACKUP_COUNT" ]; then + # Remove the oldest files + ls -1tr $BACKUP_SOURCE_PATH/gitea-dump-*.zip | head -n -$KEEP_BACKUP_COUNT | xargs -d '\n' rm -f + fi + fi + log "Backup file $BACKUP_FILE created." }