简体   繁体   English

MySQL DB差异备份

[英]MySql DB differential backup

I have restored my live database backup (which has done at 01:00AM) on my replication server at 14:00PM. 我已在14:00 PM在复制服务器上还原了实时数据库备份(已在01:00 AM完成)。

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. 备份已成功还原,复制服务器已正确更新,但是如何还原实时服务器在01:00 AM至14:00 PM之间已更新的数据。

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. 最简单的方法是让复制服务器(通常称为“从属服务器”)在进行备份时从主服务器的binlog开始复制。 If you took the backup using "mysqldump", the "--master-data" option would have done that for you. 如果使用“ mysqldump”进行备份,则“ --master-data”选项将为您完成备份。

Now that you missed that chance, I see two possible ways: 现在您错过了这个机会,我看到了两种可能的方法:
1) Repeat it all, using "mysqldump --master-data". 1)使用“ mysqldump --master-data”重复全部操作。
2) Use "mysqlbinlog" to feed the changes of exactly that period from the master to the slave, piping it into "mysql": 2)使用“ mysqlbinlog”将从主站到从站的那段时间的变化反馈到“ mysql”中:
mysqlbinlog ... | mysqlbinlog ... | mysql -h slave ... MySQL的-H奴隶...

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. 方法2要求您仍然具有这些binlog,并且即使在14:00 之后的01:00-14:00期间提供了那些值,它也假定主服务器的更改适用于从属服务器。不举行。
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. 不要尝试使用“ --start-datetime”和“ --stop-datetime”进行传输,我发现长时间运行的事务会产生一些意外的影响。 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. 仅将它们用于查看01:00和14:00左右的动作,确定您需要执行的第一个动作(接近01:00)和已经执行的第一个动作(接近14:00)的确切位置,然后使用“-开始位置”和“-停止位置”进行传输。

Approach 1 is definitely easier to go, and I strongly recommend it. 方法1绝对更容易进行,我强烈建议您使用。 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. MySQL手册在http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html页面上说明了如何设置从站,其中涵盖了所有内容。

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 ..."). 如果您使用物理文件副本或LVM快照进行初始传输(而不是“ mysqldump”),则也要重复该操作,但要记录主服务器的binlog位置(“显示主服务器状态”),然后让从服务器从此处启动( “将母版更改为...”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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