简体   繁体   中英

MySql DB differential backup

I have restored my live database backup (which has done at 01:00AM) on my replication server at 14:00PM.

Backup successfully restored & Replication server updated properly, but how to I restore data which has updated on live server between 01:00AM to 14:00PM.

is there any tool available or it is doable from any script or command line, please help.

Regards, Saurabh

You cannot "restore" such data (as they have never been in that receiving instance), but you can "apply" all changes that were done to the live database after you took the backup.

The easiest way to do this would have been to let the replication server (typically called a "slave") start replicating from the master's binlog at the position when the backup was taken. If you took the backup using "mysqldump", the "--master-data" option would have done that for you.

Now that you missed that chance, I see two possible ways:
1) Repeat it all, using "mysqldump --master-data".
2) Use "mysqlbinlog" to feed the changes of exactly that period from the master to the slave, piping it into "mysql":
mysqlbinlog ... | mysql -h slave ...

Approach 2 requires that you still have those binlogs available, and it assumes that the master's changes are applicable to the slave even though you feed those of the 01:00 - 14:00 period after those of 14:00 onwards - this may or may not hold.
Also, it requires that you can determine the exact positions in the binlog of the first and the last change you want to transfer. Do not try to use "--start-datetime" and "--stop-datetime" for the transfer, I have found some unexpected effects with longer-running transactions. Use them only to look at the actions around 01:00 and 14:00, respectively, determine the exact positions of the first action you need (close to 01:00) and the first you already have (close to 14:00), and then use "--start-position" and "--stop-position" for the transfer.

Approach 1 is definitely easier to go, and I strongly recommend it. The MySQL manual has instructions how to set up a slave on the page http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html which cover it all.

If you used physical file copies or LVM snapshots for the initial transfer (rather than "mysqldump"), also repeat it, but record the master's binlog position ("show master status") at that moment and then let the slave start from there ("change master to ...").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM