Backup MySQL Databases Automatically With AutoMySQLBackup

AutoMySQLBackup has all the features I needed: it can backup a single database, multiple databases, or all the databases on the server; each database is saved in a separate file that can be compressed (with gzip or bzip2); it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.). It has also some other features (check the project homepage for full details), that I am not using myself (like email logs for example), but other peoples might find interesting. The installation is very simple: just download the one file bash script and save it somewhere, customize it to fit your setup (only some basic changes are needed: like the MySQL user and password, backup location), make it executable and activate it in cron as needed (daily for example).

Here are the variables that I usually setup:

# Username to access the MySQL server e.g. dbuser
# Username to access the MySQL server e.g. password
# Host name (or IP address) of MySQL server e.g localhost
# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
# Backup directory location e.g /backups
# Mail setup

You can also run the script manually:


But probably you will want to enable it in cron and run daily. You can just dump it in the /etc/cron.daily/ folder and you should be done.

Place it in /opt and create a symlink to the file (to help with future updates of the script):

ln -s

And run it from cron by placing in /etc/crontab something like:

#MySQL Daily backup
45 5 * * * root /opt/ >/dev/null 2>&1

If needed, after the script is finished, you can save the backup folder where you placed the databases to a remote location (ftp, nfs, smb, or whatever) or another local medium (like tape for ex.). Saving to remote locations is not supported in the script itself so you will have to either mount the remote space locally (if it is possible… for nfs, smb, for ex.) and save directly onto it, or you will have to use another method to upload the files remotely (maybe you just have to include the backup folder used above in your regular backup script).