Backing up large database with large amount of data in a small time limit then restoring it within a small time of limit?
Any useful ideas?
Backing up large database with large amount of data in a small time limit then restoring it within a small time of limit?
Any useful ideas?
Use its replication facilities
mylvmbackup is a tool for quickly creating backups of a MySQL server's data files. To perform a backup, mylvmbackup obtains a read lock on all tables and flushes all server caches to disk, creates a snapshot of the volume containing the MySQL data directory, and unlocks the tables again. The snapshot process takes only a small amount of time. When it is done, the server can continue normal operations, while the actual file backup proceeds.
It would be nice to know what OS we're dealing with, but assuming it's a recent Linux distro, your best bet will be using LVM snapshots. The net is full of relevant recipes and tools, here's one link that lists the most popular ones:
Put the database on a hardware RAID system which allows mirroring.
For the backup, simply disable the mirroring. That will give you two exact copies of the database. Keep one "live". Run the rebuild on the other one (to clean up the possibly inconsistent state by "switching it off") and then back it up. You can take your time since the live DB still answers requests.
Enable the mirror to pull in any updates that have happened while you did a backup.
For a restore, also disable the mirror and restore into the "dead" part. After the restore has finished, enable the mirror again in such a way that the "live" database gets overwritten with the restore. You will have a few seconds of downtime for the DB server at this point since you must turn the "live" DB off and point the server to the restored DB. There is one issue to be aware of: Any changes made to the live database will be lost. Usually, this is not a bit problem, though: You must do the restore because the database is corrupt.
So you either have no live database at all or you have to run it in a "read only" state or something. If the database is not completely corrupt, you can restore the data into a third one and simply copy the few tables you need (or use the "dead" part of the mirror as a scrap space).
This approach gives you the least possible amount of downtime.
if you want a complete copy of an entire mysql server instance with the smallest downtime using only features present in mysql server, then do the following:
if you're using a filesystem that supports volume snapshots, then you can replace #2 with a snapshot instead.
Use a filesystem snapshot of your Innodb database*. You will get a consistent copy of the files on restore, after InnoDB has finished rolling back any transactions which were in progress etc.
To backup, you'll need to :
To restore it, shut down mysql, wipe out your old data files, then restore the files into the mysql data directory. When you restart the mysql instance, it will recover from any transactions which were in progress at the time of the backup (by rolling them back) then come up normally. This may take a while of course.
* of course you'll have some MyISAM tables in the "mysql" system database. Make sure they aren't changing during the snapshot.