Original address: http://www.linuxbrigade.com/back-up-all-of-your-mysql-databases-nightly/
Put the following into something like/usr/local/bin/mysql_backup.sh and since it have MySQL ' s root password in it, make Su Re that you chmod for it so no one else can read it.
#!/bin/Bashdb_backup="/backups/mysql_backup/' Date +%y-%m-%d '"Db_user="Root"db_passwd="SECRETTTT"HN=`hostname|awk-F.'{print $}'' # Create the backup directorymkdir-p $DB _backup# Remove backups older thanTen DaysFind/backups/mysql_backup/-maxdepth1-type D-mtime +Ten-execRM-RF {} \;# Backup each database on the system forDbinch$ (MySQL--user= $DB _user--password= $DB _passwd-e'Show Databases'-S--skip-column-names|grep-vie'(Staging|performance_schema|information_schema)'); DoMysqldump--user= $DB _user--password= $DB _passwd--events--opt--single-transaction $db |gzip>"$DB _backup/mysqldump-$HN-$db-$ (date +%y-%m-%d). GZ"; Done
By the, we ' re skipping tables ' performance_schema ' and ' information_schema ' ...
Then just call it from Cron by creating a root cron entry:
- 3 * * */usr/local/bin/mysql_backup. SH
Finish
Reproduced Back up all of your MySQL databases nightly