I have been thinking about restoring a MySQL database, and ensuring data integrity. So basically during restoring a database to a snapshot, using a sql dump, it does the locking etc, so you can be sure the database is in the state you expect. But then if you want to restore the database further using the Binary Log, there may be a time gap between finishing the sql dump and starting the Binary Log commands, that a user or process might be able to change data in the database, and destroy data integrity.
So there has to be a way to stop anything from making changes to the database until the full restore process is complete. I can think of a few ways:
- Write the dump file so that it does its statements in a transaction, and before the transaction is committed, create a sql file from the appropriate Binary Logs, which is executed too. Commit the changes after the whole thing is finished.
- You would normally shut down any applications that might be using the database anyway. But in addition, to be absolutely sure that nothing is accessing the database during the process of restoring it, you could copy the mysql.user table to a backup table, change all the users passwords to a temporary master password, start the process of restoring the database and when finished, restore the users original passwords, and start the applications.
I like option 2 because it ensures without doubt that no process will be able to change anything until you are finished restoring. It is simple, easy, and powerful.
My question is:
Is there a better way?