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/mysqlbackup.sh 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

Run

chmod +x /etc/cron.daily/mysqlbackup.sh

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


REFERENCE
http://www.jinkang-cheng.co.cc/posts/2009/09/18/mysql-automated-mysql-database-backup/