crontab command automatically backs up the remote server MySQL database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.