简体   繁体   English

mysqldump或mysqlhotcopy备份大型MySQL数据库?

[英]mysqldump or mysqlhotcopy to backup large MySQL database?

I have some NAS storage to do backups to with my dedicated hosting provider. 我有一些NAS存储要与我的专用托管服务提供商进行备份。 I setup automatic daily backups with WHM to backup the databases and accounts. 我使用WHM设置自动每日备份以备份数据库和帐户。 The server is hosting one site. 服务器托管一个站点。 When it does the backup, it does a mysql dump, and essentially takes the site down for the whole time it is doing the backup because nobody can connect to the database while the dump is happening. 当它进行备份时,它执行一个mysql转储,并且实际上在整个备份过程中将站点关闭,因为在转储发生时没有人可以连接到数据库。 The site is usually down for about 30 seconds to a minute (this may not seem like much, but for this kind of site it is a real problem). 该网站通常会停机约30秒到一分钟(这可能看起来不多,但对于这种网站来说这是一个真正的问题)。

Is there a better way to do the backup so that this won't happen (would mysqlhotcopy or Maatkit be better?), whether it be a different method of backing up to NAS, or just not using NAS at all and using some other method. 是否有更好的方法来进行备份以便不会发生这种情况(mysqlhotcopy或Maatkit会更好吗?),无论是备份到NAS的不同方法,还是根本不使用NAS并使用其他方法。

mysqlhotcopy is faster than mysqldump but doesn't do InnoDB. mysqlhotcopy比mysqldump快,但不做InnoDB。

To do backups, I use replication and do dumps on the slave. 要进行备份,我使用复制并对从属进行转储。 You get 0 downtime and no load spike during the backup process. 在备份过程中,您可以获得0停机时间和无负载峰值。

For InnoDB, the optimal solution without replication seems to be: 对于InnoDB,没有复制的最佳解决方案似乎是:

mysqldump mydbname --result-file=mydbname.sql --verbose --single-transaction

That uses InnoDB's transaction snapshot feature and allows normal (write!) databases operations without interruptions at all. 它使用InnoDB的事务快照功能,并允许正常(写!)数据库操作而不会中断。 With --master-data=1 you should even be able to automatically record the binary log position of the snapshot. 使用--master-data=1您甚至可以自动记录快照的二进制日志位置。 However, the binary log position seems to be pretty worthless when doing this separately on multiple databases on the same server. 但是,在同一服务器上的多个数据库上单独执行此操作时,二进制日志位置似乎毫无价值。

A disadvantage is that this does not work properly when you have some MyISAM tables. 缺点是当您有一些MyISAM表时,这不能正常工作。 I myself make use of MySQL's fulltext indexing which requires unpartitioned MyISAM tables. 我自己使用MySQL的全文索引,这需要未分区的MyISAM表。 However, one could arrange things in such a way that MyISAM tables are only secondary data sets into which one dumps texts already existing in InnoDB tables such that the MyISAM tables could be rebuilt from scratch when needed. 但是,人们可以安排事情,使MyISAM表只是辅助数据集,其中一个转储已存在于InnoDB表中的文本,以便MyISAM表可以在需要时从头开始重建。 I have a script which checks the databases' table types and uses --single-transaction instead of --lock-tables whenever there are only InnoDB tables inside one DB. 我有一个脚本,它检查数据库的表类型,并且只要一个数据库中只有InnoDB表,就使用--single-transaction而不是--lock-tables

Another solution would be to use some disk or filesystem snapshot feature, for example LVM. 另一种解决方案是使用某些磁盘或文件系统快照功能,例如LVM。 But that would be quite a significant performance hit when writing while snapshots exist because of LVM's extremely dumb backup-on-write mechanism (which is falsely claimed to be COW, which it is not in the common sense). 但是,当存在快照时,由于LVM极其笨拙的写入时备份机制(这被错误地声称是COW,而不是常识),因此这将是一个非常重要的性能损失。 A pretty good solution therefore seems to be MySQL on Solaris ZFS or on FreeBSD UFS. 因此,一个非常好的解决方案似乎是Solaris ZFS或FreeBSD UFS上的MySQL。 Both supporting efficient snapshots and being relatively stable due to their age. 两者都支持有效的快照,并且由于其年龄而相对稳定。 Btrfs has efficient snapshots, too, but is still BETA. Btrfs也有高效的快照,但仍然是BETA。

ok, there is yet another rather efficient snapshot technology: mdraid1 -- Linux softraid level 1. If you run MySQL on mdraid1, just plug in another disk, let it sync, stop mysql, do a sync, remove the third and synced raid component, restart mysql. 好吧,还有另一种相当有效的快照技术:mdraid1 - Linux softraid level 1.如果你在mdraid1上运行MySQL,只需插入另一个磁盘,让它同步,停止mysql,进行同步,删除第三个和同步的raid组件,重启mysql。 If you use bitmaps with your raid1, a re-sync to take another snapshot is usually quite fast.... 如果您对raid1使用位图,重新同步以拍摄另一张快照通常会非常快......

You wouldn't need another server, just put another install of MySQL in a sandbox on the same machine. 您不需要另一台服务器,只需将另一台MySQL安装在同一台机器上的沙盒中。 Load may spike a little but you won't get any of the locking issues. 负载可能会有点飙升,但您不会遇到任何锁定问题。

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

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