This commit is contained in:
dedhersel
2026-02-04 11:53:27 +01:00
commit 562afc3e7b
17 changed files with 1016 additions and 0 deletions

25
db_bash_backup-main/db.sh Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Import the configuration file
source "$SCRIPT_DIR/config.sh"
# Cycle through all the databases and back up each one
for db_name in "${databases[@]}"; do
# Compose the backup file name
backup_file="$backup_dir/$db_name-$(date +%Y%m%d%H%M%S).sql"
# Execute the mysqldump command to export the database
mysqldump --user="$db_user" --password="$db_pass" --host="$db_host" --port="$db_port" --databases "$db_name" > "$backup_file"
# Check if the backup was successful
if [ $? -eq 0 ]; then
echo "Backup of $db_name completed successfully in $backup_file"
else
echo "An error occurred during the backup of $db_name"
fi
# Delete backups older than specified retention period
find "$backup_dir" -type f -name "$db_name-*.sql" -mtime +$backup_retention_days -exec rm {} \;
done