使用从属设备转储的 MySQL 增量备份(InnoDB 和 MyISAM)
假设我已经有一个正在运行的主数据库服务器和一个从数据库服务器。
我想将增量备份/时间点恢复引入其中。由于我已经获得了用于复制的二进制日志,因此它应该像进行完整备份并存储日志位置一样简单。
但是,我的服务器上有 MyISAM 和 InnoDB 表,并且关于如何在每种情况下进行完整备份的建议似乎存在冲突。如果它是严格的 InnoDB,我可以使用 --single-transaction 执行 mysqldump,但该选项警告我 MyISAM 仍可能被更改。
我的问题如下:
(1)MySQL手册建议备份以下内容是否合理:
mysqldump --single-transaction --flush-logs --master-data=2 --all -数据库> whatever.sql
...将是不合适的,因为MyISAM表可能会改变(表没有用--single-transaction锁定),所以新的日志文件启动,但它可能包含对实际上已经在服务器上运行的MyISAM表的查询在这些表进入转储之前(增量恢复会在不需要时尝试重新执行这些查询)?
(2) 是使用 --lock-all 表获得 MyISAM 和 InnoDB 表的“正确”完整备份的唯一方法吗? (或者在那时关闭服务器/复制文件,因为一切都被锁定)
我假设这些问题的答案是肯定的,但如果我错了,请纠正我,因为我已经基于下一个想法离开它。
我希望将主服务器上的中断降至最低,因此我正在考虑根据此处的说明对从服务器进行完整转储:
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html#option_mysqldump_master-data
那些说明实际上是用于在奴隶上设置奴隶,但我想知道以下内容是否合理?
每天一次:
- 停止从属设备
- 显示从属设备状态并获取主日志文件和位置
- 在不对其进行任何更改的情况下对从属设备进行完整转储(MyISAM 或 InnoDB)
- 再次启动从属设备
- 将我的完整转储移至主服务器位于某些备份目录中
如果恢复:
- 从上面的 (5) 恢复到完整转储
- 使用此处的位置运行时间点恢复 http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery-positions.html 从上面 (2) 中的位置转到我想要恢复到的任何位置
这合法吗?我不明白为什么从属设备的完整转储与主设备的完整转储有任何不同,所以看起来应该没问题。
感谢您的帮助!
Assume I already have a master and a slave DB server that are up and running.
I'd like to introduce incremental backups/point in time recovery into the mix. Since I've already got binary logs going for the replication, it should be as simple as making a full backup and storing the log position.
However, I have both MyISAM and InnoDB tables on my server, and there seems to be conflicting suggestions on how to do full backups in each case. If it were strictly InnoDB, I could do mysqldump with --single-transaction, but that option warns me that MyISAM may still be changed.
My questions are as follows:
(1) Is it a valid concern that the MySQL manual suggested backup of:
mysqldump --single-transaction --flush-logs --master-data=2 --all-databases > whatever.sql
...would be unsuitable because MyISAM tables may change (tables are not locked with --single-transaction), so the new log file is started but it may contain queries for MyISAM tables which were actually already run on the server before those tables made it into the dump (and an incremental restore would try to re-do those queries when they aren't needed)?
(2) Is the only way to get a "proper" full backup with both MyISAM and InnoDB tables to use --lock-all tables? (Or at that point just shut down the server/copy files since everything is locked anyway)
I'm assuming that the answer to those questions is yes, but please correct me if I'm wrong, because I've based the next idea off of it.
I'd like to keep interruptions to a minimum on the master server, so I am considering doing the full dumps off of the slave based on the directions here:
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html#option_mysqldump_master-data
Those directions are actually for setting up a slave off of a slave, but I am wondering, is the following plausible?
Once a day:
- Stop the slave
- Show slave status and get the master log file and position
- Do a full dump of the slave while no changes are being made to it (MyISAM or InnoDB)
- Start up the slave again
- Move my full dump over to the master server in some backup dir
In case of recovery:
- Restore to the full dump from (5) above
- Run point in time recovery using positions from here http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery-positions.html to go from the position in (2) above to whatever position I want to restore to
Is that legit? I don't see why the full dump from the slave would be any different from the master one, so it seems like it would be fine.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你每天一次的计划非常合理,原因很简单:你首先阻止了奴隶。不会有新的交易进来。我想提出一些额外的建议。
在从机上,请在 /etc/my.cnf 中设置以下内容
,原因如下:
当从机处理 mysqldump 时,如果任何表在 innodb 缓冲池中注册了脏页,则必须将这些页刷新到磁盘。我注意到在你的 mysqldump 中你已经发出了这个选项。默认情况下,innodb_max_dirty_pages_pct 为 90。无论存在什么脏页,都必须写入磁盘。如果 innodb_max_dirty_pages_pct 始终为零,则刷新 innodb 缓冲池会更快。
您可以动态设置它,而无需重新启动 mysql。只需运行这个:
这将使 innodb 缓冲池保持精简和平均。
我还看到您的 mysqldump 命令中有 --master-data=2 。仅当从属设备上启用了二进制日志时,这才有效。如果没有,则需要从master检索master日志和位置,因为mysqldump无法做到这一点。以下是从从站获取主站日志文件和位置的方法:
步骤 1) 运行“SHOW SLAVE STATUS\G”并重定向到 ShowSlaveStatus.txt
步骤 2) 从 ShowSlaveStatus.txt 获取以下信息
Relay_Master_Log_File
Exec_Master_Log_Pos
步骤3) 将这两个值写入转储文件的后面。
还有一件事:
请将 --routines --triggers 添加到 mysqldump 命令中。您永远不知道什么时候会决定编写存储过程和触发器。另外,如果从站已停止,则无需 --lock-tables 。
Your once a day plan is very plausible for one simple reason: You stopped the slave first. No new transactions would be coming in. I would like to suggest something additional.
On the slave please set the following in /etc/my.cnf
Here is why:
While the slave is processing the mysqldump, if any tables have dirty pages registered in the innodb buffer pool, the pages must be flushed to disk. I noticed in your mysqldump you issue this option already. By default, innodb_max_dirty_pages_pct is 90. Whatever dirty pages exist must be written to disk. If innodb_max_dirty_pages_pct is zero all the time, flushing the innodb bufferpool is quicker.
You can set this dynamically without restarting mysql. Just run this:
This will keep the innodb buffer pool lean and mean.
I also see that --master-data=2 is in your mysqldump command. This will only work if the binary logs are enabled on the slave. If not, you need to retrieve the master log and position from the master, because mysqldump cannot do that. Here is how you can get the master's log file and position from the slave:
Step 1) Run "SHOW SLAVE STATUS\G" and rediredct to ShowSlaveStatus.txt
Step 2) Get the following info from ShowSlaveStatus.txt
Relay_Master_Log_File
Exec_Master_Log_Pos
Step 3) Write these two values at the back of the dump file.
One more thing:
Please add --routines --triggers to the mysqldump command. You never know when you may decide to write stored procedures and triggers. Also, no need to --lock-tables is the slave is stopped.