Use rsync for MySQL Incremental Backup

Source: Internet
Author: User
Description of related parameters in the mysql_back.sh script. The-c in the CT-c is the meaning of the command, that is, the-c is followed by the relevant commands, but these commands must

Description of related parameters in the mysql_back.sh script. The-c in the CT-c is the meaning of the command, that is, the-c is followed by the relevant commands, but these commands must

I. Environment Description (using rsync for mysql Incremental Backup)

192.168.0.2 is the backup server.

192.168.0.3 is the mysql database that needs to be backed up frequently.

Ii. Main Configuration

1. Backup Server Configuration
Useradd mysql_db-d/data/bak
Passwd rsync_server
# The password I configured is "123"

2. mysql Server Configuration
Vi mysql_back.sh
Export PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Binlog_dir =/data/mysql/3306/logs
# Delete old binlog FileList
If [-f $ binlog_dir/mysql-bin.index]; then
Rm-f $ binlog_dir/mysql-bin.index
Fi
Passwd = "123"
Ls-l $ binlog_dir | grep mysql-bin | awk '{print $8}'>/data/mysql/3306/logs/binlog/mysql-bin.index
Rsync_exec (){
CT-c"
Set timeout 600;
Spawn rsync-rpogtv -- progress -- files-from = $ binlog_dir/binlog/mysql-bin.index $ binlog_dir mysql_db@192.168.0.2:/data/bak
CT {
\ "* Yes/no * \" {send \ "yes \ r \"; exp_continue}
\ "* Password * \" {send \ "$ passwd \ r \";}
}
CT eof ;"
}
Rsync_exec

3. Grant mysql_back.sh the right to execute and add a scheduled task.

// Explain the parameters in the mysql_back.sh script. The-c in CT-c is the meaning of the command, that is, the-c is followed by the relevant commands, but these commands must be caused. Set timeout sets the script timeout to 600 seconds, and spawn sets the start mode for running system commands. In rsync-rpogtv, r indicates recursively entering the directory, p indicates retaining the original permissions of the file, o indicates retaining the original owner of the file, and g indicates retaining the original group of the file ,, t indicates the time when the file was originally created or modified, v indicates that the lengthy information is added, and -- progress indicates that the rsync process is displayed. -- files-from indicates where to obtain the file for rsync. Objective CT is used here to avoid interaction. The Escape Character of \ "* yes/no * \" is followed by \ at both ends, and * is an arbitrary match, eof indicates the end of the program.

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.