add retention period
This commit is contained in:
@@ -5,16 +5,19 @@ source config.sh
|
|||||||
|
|
||||||
# Cycle through all the databases and back up each one
|
# Cycle through all the databases and back up each one
|
||||||
for db_name in "${databases[@]}"; do
|
for db_name in "${databases[@]}"; do
|
||||||
# Compongo il nome del file di backup
|
# Compose the backup file name
|
||||||
backup_file="$backup_dir/$db_name-$(date +%Y%m%d%H%M%S).sql"
|
backup_file="$backup_dir/$db_name-$(date +%Y%m%d%H%M%S).sql"
|
||||||
|
|
||||||
# I run the mysqldump command to export the database
|
# 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"
|
mysqldump --user="$db_user" --password="$db_pass" --host="$db_host" --port="$db_port" --databases "$db_name" > "$backup_file"
|
||||||
|
|
||||||
# If the backup was successful, I see a confirmation message
|
# Check if the backup was successful
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Backup di $db_name completato con successo in $backup_file"
|
echo "Backup of $db_name completed successfully in $backup_file"
|
||||||
else
|
else
|
||||||
echo "Si è verificato un errore durante il backup di $db_name"
|
echo "An error occurred during the backup of $db_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Delete backups older than specified retention period
|
||||||
|
find "$backup_dir" -type f -name "$db_name-*.sql" -mtime +$backup_retention_days -exec rm {} \;
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user