I saw two different approaches for backing up database with LVM snapshot. This article suggests spawning another MySQL instance to do an SQL dump. MYSQL Performance Blog suggests that it is safe to copy directly the database files:
6) Copy data to backup. Normally you can skip slow query logs and
error log while taking backup. You also can skip most of binary logs –
however if some of your slaves are far behind you might want to keep
some of last binary logs just in case, or you can assume in case of
recovery from the backup you will need to restore slaves as well and
skip binary logs in your backup process.
For database in InnoDB
format, is it ok that I just backup the /var/lib/mysql/
folder?
Best Answer
For InnoDB and other transactional data stores it should be OK purely from a referential integrity point of view as the normal crash recovery procedure will roll out any incomplete transactions that were in progress when the backup was taken, but there are potential problems that mean it is not recommended that you backup databases this way:
If you can cope with a small amount of down-time then you can keep it to a minimum by:
This way you are only down for the length of time needed to stop and restart the DB service (starting the LVM snapshot should be near instantaneous).
If you can't afford a time any time for this short service outage, you could perhaps setup replication and you could then backup from that instead:
In fact, you don't need the LVM snapshots for this if the backup doesn't take so long that resuming replication becomes problematical.