mysqldump or mysqlhotcopy to backup large MySQL database?

11,569

For InnoDB, the optimal solution without replication seems to be:

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. With --master-data=1 you should even be able to automatically record the binary log position of the snapshot. 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. I myself make use of MySQL's fulltext indexing which requires unpartitioned MyISAM tables. 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. 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.

Another solution would be to use some disk or filesystem snapshot feature, for example 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). A pretty good solution therefore seems to be MySQL on Solaris ZFS or on FreeBSD UFS. Both supporting efficient snapshots and being relatively stable due to their age. Btrfs has efficient snapshots, too, but is still BETA.

Share:
11,569
James Simpson
Author by

James Simpson

CEO & Founder of GoldFire Studios. Business is my game, and games are my business.

Updated on June 04, 2022

Comments

  • James Simpson
    James Simpson almost 2 years

    I have some NAS storage to do backups to with my dedicated hosting provider. I setup automatic daily backups with WHM to backup the databases and accounts. 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. 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).

    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.