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 "help house http://www.bkjia.com]
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}. SQL
- Tar-zcvf restart jira_file_name1_. SQL .tar.gz $ {JIRA_FILE_NAME}. SQL
- Rm-rf $ {JIRA_FILE_NAME}. SQL
- Mysqldump-ubbs-pbbs bbs >$ {BBS_FILE_NAME}. SQL
- Tar-zcvf restart bbs_file_name1_. SQL .tar.gz $ {BBS_FILE_NAME}. SQL
- Rm-rf $ {BBS_FILE_NAME}. SQL
- Mysqldump-umantis-pmantis mantis >$ {MANTIS_FILE_NAME}. SQL
- Tar-zcvf restart extends mantis_file_name). SQL .tar.gz $ {MANTIS_FILE_NAME}. SQL
- Rm-rf $ {MANTIS_FILE_NAME}. SQL