Add scheduled database backup script

Add db-scheduled-backup.sh that calls db-backup-standalone.sh and removes backup files older than 7 days using find -mtime +7.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-25 22:30:33 +01:00
parent 86e3084d3a
commit 66cfdf779e

35
db-scheduled-backup.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
# Script to run scheduled database backups and clean up old files
# This script calls db-backup-standalone.sh and then removes backups older than 7 days
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_SCRIPT="$SCRIPT_DIR/db-backup-standalone.sh"
# Ensure the backup script exists and is executable
if [ ! -f "$BACKUP_SCRIPT" ]; then
echo "Error: Backup script not found at $BACKUP_SCRIPT"
exit 1
fi
if [ ! -x "$BACKUP_SCRIPT" ]; then
echo "Making backup script executable..."
chmod +x "$BACKUP_SCRIPT"
fi
# Run the backup
echo "Starting database backup..."
"$BACKUP_SCRIPT"
# Delete backups older than 7 days
BACKUP_DIR="${BACKUP_DIR:-backups}"
if [ -d "$BACKUP_DIR" ]; then
echo "Cleaning up backups older than 7 days in $BACKUP_DIR..."
find "$BACKUP_DIR" -name "mongo-volume-backup-*.tar.gz" -type f -mtime +7 -delete
echo "Cleanup completed."
else
echo "Warning: Backup directory $BACKUP_DIR not found, skipping cleanup."
fi
echo "Scheduled backup completed successfully."