From: http://hi.baidu.com/wenddiy/blog/item/135c2f861e7849b50df4d230.html
I. What is Incremental backup?
Incremental Backup backs up new data. If you have 10 Gb of data in a database, you can add 10 MB of data every day. The database must be backed up once every day. Do you need to back up so much data? We only need to back up the added data. Obviously, I only need to back up the added data. This reduces the burden on the server.
2. Enable BINLOG
VI my. CNF
Log-bin =/var/lib/MySQL/mysql-bin.log, if so log-bin = mysql-bin.log is under the datadir directory by default
[Root @ blackghost MySQL] # ls | grep mysql-bin
Mysql-bin.000001
Mysql-bin.000002
Mysql-bin.000003
Mysql-bin.000004
Mysql-bin.000005
Mysql-bin.000006
Mysql-bin.index
After mysql-bin is started, one or more files are generated.
Mysql-bin.000002 files store the data that is added to the database every day, where the incremental data of all databases is located.
3. check what is in a file like a mysql-bin.000002
[Root @ blackghost MySQL] # mysqlbinlog/var/lib/MySQL/mysql-bin.000002 & gt;/tmp/Add. SQL
An important index file is mysql-bin.index.
JavaCode
[Root@ BlackghostMySQL] # Cat mysql-bin.index./MySQL-bin.000001./MySQL-bin.000002./MySQL-bin.000003./MySQL-bin.000004./MySQL-bin.000005./MySQL-bin.000006
[Root @ blackghost MySQL] # Cat mysql-bin.index./mysql-bin.000001./mysql-bin.000002./mysql-bin.000003./mysql-bin.000004./mysql-bin.000005./mysql-bin.000006 ././
Iv. Incremental backup and incremental Restoration
1. Incremental Backup
Now that we know that the newly added data in MySQL is in a file like mysql-bin, we only need to back up the file like mysql-bin.
CP/var/lib/MySQL-Bin */data/mysql_newbak/
2. incremental Restoration: some common and useful
A) restore-start-date,-Stop-date by Time
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-start-date = "2010-09-29 18:00:00"-Stop-date = "2010-09-29 23:00:00"/var/lib/ mySQL/mysql-bin.000002 | mysql-u root-P
Check the data according to the conditions.
Java code
[Root@ BlackghostMySQL] #/usr/local/MySQL/bin/mysqlbinlog -- start-date ="18:00:00"-- Stop-date ="23:00:00"/Var/lib/MySQL-bin.000002// The following is part of the content, which is actually some SQL statements that operate on data.#
B), restore Based on the starting position,-start-position,-Stop-Position
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-start-position = 370-stop-position = 440/var/lib/MySQL/mysql-bin.000002 | mysql- U root-P
// View the inserted content, which is the same in root)
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-start-position = 370-stop-position = 440/var/lib/MySQL/mysql-bin.000002
-Start-position = 370-stop-position = 440 where does the number come from?
#370
#100929 21:35:25 server Id 1 end_log_pos440Query thread_id = 1 exec_time = 0 error_code = 0
Set timestamp = 1285767325 /*! */;
The above red bold is, one is start-position, the other is stop-Position
C) restore the database by name-d
Here is a lowercase D. Do not mix it with-D in mysqldump. Haha.
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-d test/var/lib/MySQL/mysql-bin.000002
For details, refer to)
D), which is divided into-H based on the IP address of the database.
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-H 1921381.102/var/lib/MySQL/mysql-bin.000002
For details, refer to)
E) According to the port occupied by the database,-P
Sometimes, we use port 3306 for MySQL. Note that it is an uppercase P
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-P 13306/var/lib/MySQL/mysql-bin.000002
For details, refer to)
F) restore-server-id based on the database serverid
In the database configuration file, there is a serverid and the serverid in the same cluster cannot be the same.
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-server-id = 1/var/lib/MySQL/mysql-bin.000002
For details, refer to)
Note: I have mentioned the above examples one by one. In fact, they can be arranged and combined. For example
[Root @ blackghost MySQL] #/usr/local/MySQL/bin/mysqlbinlog-start-position = "2010-09-29 18:00:00"-d test-H 127.0.0.1/var/lib/MySQL/mysql-bin.000002 | mysql-u root-P
5. Follow-up
One unpleasant thing about Incremental backup is that files such as MySQL-bin will be added every time MySQL is started. If you don't care about them, it will take a long time, it will fill up your disk.
./Mysqldump-flush-logs-u root myblog>/tmp/myblog. SQL
Back up the myblog database and clear the data about myblog In the Incremental backup.
./Mysqldump-flush-logs-u root-all-databases>/tmp/alldatabase. SQL
Back up all databases and clear Incremental Backup
Mysql-bin.index index, because the incremental data is not necessarily in a file such as a mysql-bin000, at this time, we will find an incremental file such as MySQL-bin according to the mysql-bin.index.
If BINLOG-do-DB = test1 is configured in MySQL, only data in the database test1 is available in the Incremental backup.