Today the boss let backup database can not do their own toss it, the following summary of the results of the toss.
Database backup ideas:
1. Scripting
2. Execute the script haha, is not very simple, open the refrigerator, put the elephant, close. Below I am the concrete operation.
First, write the script
1. Set up a directory for backup
Mkdir/usr/local/mysqlbackup
Cd/usr/local/mysqlbackup
2. Write the backup script code:
Backup with mysqldump Backup, the benefits of decompression is the SQL script can be imported directly.
Copy the following code to change the user and password database to their own
#!/bin/shmysqldump-uroot-p123456 dbname | gzip >/var/lib/mysqlbackup/dbname ' Date +%y-%m-%d_%h%m%s '. sql.gzcd /usr/local/mysqlbackuprm-rf ' Find-name ' *.sql.gz '-mtime ' #删除10天前的备份文件
3. Change Backup Script permissions
Second, execute the backup script code with CRONTAB timing:
If you are backing up at 1 o'clock 00 every night, add the following code, which generally separates the backup time from the other performed business so that MySQL crashes.
XX 1 * * */usr/local/mysqlbackup/dbbackup.sh
crontab command
* * * * * * /usr/local/mysqlbackup/dbbackup.sh per minute 3,15 * * * */usr/local/mysqlbackup/dbbackup.sh 3 and 15 points per day 3,15 * * * */usr/local/mysqlbackup/dbbackup.sh 3 and 15 points per day 3,15 8-11 * */usr/local/mysqlbackup/dbbackup . SH in the 3rd and 15 minutes of 8 o'clock in the morning to 11 o ' */1 * * * * * * * * * * * /usr/local/mysqlbackup/dbbackup.sh every hour to restart SMB0 * * 6 /usr/local/ Mysqlbackup/dbbackup.sh every Saturday night 23:00 * 23-7/1 * * */usr/local/mysqlbackup/dbbackup.sh 11 o'clock to 7 a.m., every hour restart SMB 0 4 1 Jan * /usr/local/mysqlbackup/dbbackup.sh January 1 4-point restart SMB
Restart Service Crond Restart
You can view the configuration of crontab by command crontab-l.
Crontab-r Delete the current user timer task
Backup MySQL database under Linux