Backup MySQL database under Linux

Source: Internet
Author: User

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

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.