Search This Blog

Tuesday, March 27, 2012

Making a mysql back up every day midnight using cron

This is a simple way to back up your database everyday Go to ubuntu command line and log in as root user, type following command to open crontab file

 >crontab -e

 type the following command in the file

 0 0 * * * mysqldump -uYOURUSER -pYOURPASSWORD YOURDBNAME > /home/tommy/my_back_up/mydb_`date +\%y-\%m-\%d`.sql

 you can restart cron by typing

 >restart cron

 OR

 >/etc/init.d/cron restart

This will create a sql dump file everyday midnight
file name would be mydb_2012-04-21.sql

No comments: