Auto backup mysql database

How to Auto backup mysql database 

 

1. Create backup command and test the command

[root@Centos6 ~]# mkdir backup
[root@Centos6 ~]# cd backup
[root@Centos6 backup]# mysqldump -u root -pnewP@ssw0rd -h 127.0.0.1 –all-databases | gzip > database_`date ‘+%m-%d-%Y’`.sql.gz
[root@Centos6 backup]# ls -lah
total 144K
drwxr-xr-x 2 root root 4.0K Dec 7 00:02 .
dr-xr-x—. 5 root root 4.0K Dec 7 00:02 ..
-rw-r–r– 1 root root 136K Dec 7 00:02 database_12-07-2012.sql.gz
[root@Centos6 backup]#

2. Create auto backup by crontab at 00:00 everyday

[root@Centos6 backup]# crontab -e
no crontab for root – using an empty one
00 00 * * * /usr/bin/mysqldump -u root -pnewP@ssw0rd -h 127.0.0.1 –all-databases | gzip > /backup/database_`date ‘+%m-%d-%Y’`.sql.gz
[root@Centos6 backup]# ls -lah
total 144K
drwxr-xr-x 2 root root 4.0K Dec 7 00:08 .
dr-xr-xr-x. 23 root root 4.0K Dec 7 00:08 ..
-rw-r–r– 1 root root 136K Dec 7 00:08 database_12-07-2012.sql.gz
[root@Centos6 backup]#

That’s all. Thanks for IThelpblog.com.

 

 

Tags:  

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>