2022-09-07 14:16:20 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# config section
|
|
|
|
date=`date +%Y-%m-%d`
|
|
|
|
backup_dir='/mnt/mysql_backup'
|
|
|
|
retention=3
|
|
|
|
|
2022-09-07 14:40:17 +02:00
|
|
|
# create backup directory
|
2022-09-07 14:16:20 +02:00
|
|
|
mkdir -p $backup_dir
|
|
|
|
|
|
|
|
# database backup
|
2022-09-07 14:58:10 +02:00
|
|
|
for DB in $(mysql -e 'show databases' -sN|grep -v 'information_schema\|performance_schema'); do
|
2022-09-07 14:16:20 +02:00
|
|
|
mysqldump $DB > "$backup_dir/$date.$DB.sql";
|
|
|
|
done
|
|
|
|
|
|
|
|
# delete old backups
|
2022-09-07 14:58:10 +02:00
|
|
|
find $backup_dir -type f -mtime +$retention -name '*.sql' -execdir rm -- '{}' \;
|