Use the crontab system to regularly back up MySQL database _ MySQL every day

Source: Internet
Author: User
The crontab system regularly backs up MySQL databases every day and uses the crontab system to regularly execute backup files and save the backup results by date.

1. create the path to save the backup file/mysqldata

# Mkdir/mysqldata

2. create the/usr/sbin/bakmysql file.

# Vi/usr/sbin/bakmysql

Input

Rq = 'date + % Y % m % d'

Tar zcvf/mysqldata/mysql1_rq.tar.gz/var/lib/mysql

Or write it

Rq = 'date + % Y % m % d'

Mysqldump -- all-databases-u root-p980405>/mysqldata/mysql1_rq.tar.gz

/Var/lib/mysql is the directory of your database files. some users are/usr/local/mysql/data.

/Mysqldata/indicates the directory where the backup file is saved. this can be done according to your requirements.

3. Modify file attributes to make them executable.

# Chmod + x/usr/sbin/bakmysql

4. modify/etc/crontab

# Vi/etc/crontab

Add

01 3 *** root/usr/sbin/bakmysql

Indicates that a backup is performed at three o'clock every day.

5. restart crond.

#/Etc/rc. d/init. d/crond restart

Complete.

In this way, you can see such files in/mysqldata every day.

Mysql20040619.tar.gz

You can download it directly.

Stop the database service process or lock the database before running the tar command,

Otherwise, the database may be damaged when the data is recovered. if you are lucky, you can fix the problem.

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.