Friday, January 22, 2010

MySQL: Automated MySQL Database Backup

SkyHi @ Friday, January 22, 2010

Want to backup your MySQL databases to another machine on a nightly basis?

Then create a /etc/cron.daily/ job like this:

mysqldump --compress -u root -p$pw -h $currenthost --add-drop-table --extended-insert --quote-names --databases db1 db2| mysql -u root -p$pw -h $remotehost


chmod +x /etc/cron.daily/

And change the $ parameters to the appropriate ‘real’ values.

Or if you are not backing up to a separate host, run:

mysqldump -u root -p$pw -h $currenthost --add-drop-table --extended-insert --quote-names --databases db1 db2 > /var/log/mysql.backup.$(date +"%Y%m%d").sql