From 228e583dc77f026d2475d34de56a0fab90c60be9 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Tue, 27 Jun 2023 14:45:38 +0100 Subject: [PATCH] update script on unraid backup --- guides/unraid/pages/docker-app-backup.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/guides/unraid/pages/docker-app-backup.md b/guides/unraid/pages/docker-app-backup.md index aa89d05..3ffc017 100644 --- a/guides/unraid/pages/docker-app-backup.md +++ b/guides/unraid/pages/docker-app-backup.md @@ -40,8 +40,8 @@ applicationData="/mnt/user/appdata/application_name/" # Example: /mnt/user/Storage/Backups/$applicationName/ backupDirectory="" -# Set Number of Days to Keep Backups -days=30 +# Set Number backups to keep +backupsToKeep=30 # The user of your account # Example: lee @@ -50,6 +50,7 @@ user="" # --- Backup Application --- # Start notification +echo "Backup of $applicationName starting." /usr/local/emhttp/plugins/dynamix/scripts/notify -s "$applicationName Backup" -d "Backup of $applicationName starting." # Create backup directory @@ -61,12 +62,19 @@ cd "$backupDirectory" tar -cf "$applicationName-$now".tar "$applicationData" # Set Permissions -chown "$user:$user" $applicationName-"$now".tar +chown "$user:$user" "$applicationName-$now".tar # Cleanup old backups -find "$backupDirectory"* -type d -mtime +"$days" | xargs rm -rf +for file in $(ls -t); do + if [[ $count -ge $backupsToKeep ]]; then + rm -- "$file" + echo "Deleted old backup: $file" + fi + ((count++)) +done # Stop notification +echo "Backup of $applicationName completed!" /usr/local/emhttp/plugins/dynamix/scripts/notify -s "$applicationName Backup" -d "Backup of $applicationName completed!" ```