In Linux, MySQL regularly backs up data by date

Source: Internet
Author: User

1. Use the MySQL built-in command mysqldump

Usage:
Mysqldump [Options] database [Tables]
Mysqldump [Options] -- databases [Options] db1 [DB2 DB3. ..]
Mysqldump [Options] -- all-databases [Options]

You can see that you can back up all the databases, the specified database, and the tables in the specified database.

Mysqldump-uusername-ppassword database>/var/backup/MySQL/database. SQL

Ii. Backup by date

Mysqldump-uusername-ppassword database>/var/backup/MySQL/database-'date + % Y % m % D'. SQL

'Date + % Y % m % d' uses shell knowledge to execute the command first to obtain the formatted date.

Vim/var/backup/backup-mysql.sh

Store the above content in the file

Chmod + x backup-mysql.sh

Add executable permissions

Iii. Scheduled Backup

Use the crontab OF THE SYSTEM

Crontab-e

# M h Dom mon Dow command
0 3 ***/var/backup/backup-mysql.sh

The time format is

Minutes, days, months, and weeks

The preceding example specifies that the database is backed up three o'clock every day.

Improvement:

Of course, you can also add some better functions, such

Compress the backup file. This is very simple.

Only the backup files of the last XX days are retained. This is a little more complicated.

Using MySQL binary Incremental backup ......

Updated on February 15

The following is a shell script:

Jira_file_name = Jira-'date + % Y % m % d'; bbs_file_name = BBS-'date + % Y % m % d '; mantis_file_name = mantis-'date + % Y % m % d'; CD/var/backup/MySQL/mysqldump-ujira-pjira Jira >$ {jira_file_name }. sqltar-zcvf implements jira_file_name1_. SQL .tar.gz $ {jira_file_name }. sqlrm-RF $ {jira_file_name }. sqlmysqldump-ubbs-PBBs BBS >$ {bbs_file_name }. sqltar-zcvf restart bbs_file_name1_. SQL .tar.gz $ {bbs_file_name }. sqlrm-RF $ {bbs_file_name }. sqlmysqldump-umantis-pmantis mantis >$ {mantis_file_name }. sqltar-zcvf extends mantis_file_name). SQL .tar.gz $ {mantis_file_name }. sqlrm-RF $ {mantis_file_name }. SQL

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.