Today with the information collected through the online and their own practice, with the crontab command to do a remote server database backup, hope to be useful to everyone.
The operation steps are as follows:
1. Open Putty, enter the password here, and then go to:
2. Create a path to save the backup file/mysqldata: After creating the file, you can see the Mysqldata folder in the root directory (and Var, usr in the same directory) after you enter the following information in the Green place of the second image above.
#mkdir/mysqldata
3. Create a/usr/sbin/bakmysql file
#vi/usr/sbin/bakmysql
Input
rq= ' Date +%y%m%d '
Tar Zcvf/mysqldata/mysql$rq.tar.gz/var/lib/mysql
or write
rq= ' Date +%y%m%d '
Mysqldump--all-databases-u root-p password >/mysqldata/mysql$rq.sql
/var/lib/mysql is the directory of your database files, some users are/usr/local/mysql/data, each person may be different
/mysqldata/represents the directory where the backup files are saved, and this can be done by each person according to their own requirements.
Note: You can see the Bakmysql file in the/usr/sbin/directory, you can also copy the above input to Bakmysql after creating the Bakmysql.
4. Modify the file properties to make them executable:
# chmod +x/usr/sbin/bakmysql
5. Modify/etc/crontab
Input #vi/etc/crontab
After entering the above command, you can see the following interface:
Add in red box up (how to add please see my blog crontab timed execution php)
1 * * * root/usr/sbin/bakmysql
Indicates that backups are performed 1:10 every day
6. Restart Crond
#/etc/rc.d/init.d/crond Restart
crontab command automatically backs up the remote server MySQL database