Daily backup of MySQL database with crontab system

Source: Internet
Author: User

Use the system crontab to execute the backup file regularly, save the backup result by date, and achieve the purpose of backup.

1. Create a path to save the backup file/mysqldata

1 #mkdir /mysqldata

2. Create a/usr/sbin/bakmysql file

1 #VI /usr/sbin/bakmysql

Input

12 rq= Date +%Y%m%d Span class= "Crayon-sy" " tar zcvf /mysqldata/mysql$rq. Tar. GZ /var/Lib/mysql

/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.

3. Modify the file properties to make it executable

1 # chmod +x /usr/sbin/bakmysql

4, modify the/etc/crontab

1 #Vim /etc/crontab

Add the following

1 3 * * * root /usr/sbin/Bakmysql

Indicates that backups are performed 3 o'clock every day

5. Restart Crond

1 # service crond restart

Complete.

So every day you can see such a file in/mysqldata

1 mysql20040619. Tar. GZ

Daily backup of MySQL database with crontab system

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.