简体   繁体   中英

How to restore MySQL database to a point in time

A MySQL database is used for test purpose, so I want to run backend API tests on this (multiple transactions), simulating a real database in production.

When tests execution are finished, I want to restore the database in the point before that execution, to be able to run more tests with that database snapshot.

I don't have any MySQL version restriction, because it'll be a fresh database server.

What's the most performant way to restore this database?

You have a lot of options:

  • Create a snapshot with a tool like mysqldump and restore from this snapshot later to reset the database.
  • Create a volume-level snapshot on a filesystem that supports it like ZFS and restore it later.
  • Create a virtual machine and snapshot that, later restoring it to the snapshot. Most VM environments like VirtualBox support this feature.
  • Use a Docker container with an attached volume you can snapshot and restore.

I'd use Percona XtraBackup to create a physical backup. This can be restored a lot faster than a dump created by mysqldump .

If the database is large enough (over 100GB), even a physical backup won't be fast enough. I'd use LVM snapshots of the filesystem. See https://www.lullabot.com/articles/mysql-backups-using-lvm-snapshots for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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