All ArticlesDevOps2026-11-20T07:18:27+08:00

Restored a VM Snapshot and MySQL Won't Start? Crash-Consistent vs App-Consistent

The reader restored a hypervisor or VPS snapshot and found MySQL failing to start or tables marked as corrupted, because the snapshot captured the disk in the middle of database writes. After reading, they will know how crash-consistent snapshots, application-consistent snapshots, and logical dumps differ, and which one to pick for each database workload.

You restored a VM or VPS snapshot to undo a bad update or recover a broken server. The machine boots fine, and then MySQL refuses to start. Sometimes it does start, but some tables throw 'marked as crashed' errors, or InnoDB loops through recovery and exits. The snapshot is usually not broken. The cause is what the database was doing at the moment the snapshot was taken.

This article walks through the problem the way a post-mortem would. It covers what users see, how the investigation usually goes, the point where the cause becomes clear, how to get the data out in the short term, and what to change so the next restore works.

Initial impact: the server is back but the database is not

The first report is rarely about MySQL. Visitors see 'Error establishing a database connection' on a WordPress site, an application returns 500 errors, or a monitoring check on port 3306 goes red. On the server, systemctl status shows the MySQL service as failed, or the start command hangs for a while before it gives up.

At the support desk, the usual first reaction is 'the restore broke my site'. That is understandable, and it is also slightly wrong. The restore did exactly what it promised. It put the disk back to the state it was in at one instant. The real question is whether that state was one MySQL can start from.

Investigation: rule out the ordinary causes first

When MySQL fails after restoring a snapshot or a copied data directory (datadir, usually /var/lib/mysql), community threads keep pointing at the same three causes. The causes are file permission mismatches, mismatched transaction logs, and AppArmor or SELinux blocking access. You can see the pattern in discussions on DigitalOcean Community and Server Fault. The first and last causes take a minute to check, so check them before anything else:

# Read the end of the MySQL error log (path depends on distro and config)
sudo tail -n 50 /var/log/mysql/error.log

# Same information from systemd (unit may be mysql, mysqld, or mariadb)
sudo journalctl -u mysql --no-pager -n 50

# Numeric owner and group of the data directory and its files
sudo ls -ln /var/lib/mysql | head -n 20

# Free space on the filesystem holding the datadir
df -h /var/lib/mysql

Permissions matter most when the datadir was copied onto a different machine, because the mysql user can have a different numeric UID there. That is why ls -ln is more useful than ls -l. On Ubuntu, AppArmor blocks MySQL if the datadir now lives at a path the profile does not allow. On RHEL-family systems, copied files can carry the wrong SELinux context, which restorecon fixes. A full disk also stops InnoDB from starting. If df and du disagree about how full the disk is, see df says the VPS disk is full, but du can't find the files.

If you restored a whole VM disk in place, ownership and security labels usually come back unchanged. In that case these checks tend to come back clean, and the log points somewhere else.

The discovery: the snapshot caught the database mid-write

The error log is where the cause becomes clear. Wording varies between MySQL and MariaDB versions, but the messages look roughly like this:

# Illustrative output format, not from a real server
[Note] InnoDB: Database was not shut down normally!
[Note] InnoDB: Starting crash recovery.
[ERROR] InnoDB: Page [page id: space=..., page number=...] log sequence number ... is in the future!
[ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption

'Not shut down normally' explains the whole situation. A standard hypervisor or VPS snapshot is crash-consistent. It records every block on the disk at one moment and does not ask the running software for permission. From MySQL's point of view, restoring that snapshot looks exactly like someone pulled the power cable at that moment.

InnoDB is designed to survive a power cut. Changes go to the redo log (a sequential journal of changes) before the data pages themselves are written, and those pages are flushed to disk later. On startup, InnoDB replays the redo log to bring the data files up to date. It uses the log sequence number (LSN), a running position in the redo log, to decide what still needs replaying. The doublewrite buffer protects against pages that were only half written. So most crash-consistent snapshots of a pure InnoDB server recover without any help.

Recovery fails when the 'power cut' was one InnoDB could not have survived in real life either. Common cases:

  • MyISAM or Aria tables. These engines have no redo log, so a mid-write snapshot can leave them inconsistent. That produces 'marked as crashed' errors.
  • Data split across several virtual disks. If the datadir is on one disk and the redo logs or binary logs are on another, and the two disks are not snapshotted atomically, the files come from different moments. LSN errors like the one above are the typical result.
  • Write caching that ignores flushes. If the hypervisor's disk cache mode or the storage layer acknowledges writes before they are durable, InnoDB believes data is safe when it never reached the disk the snapshot read from.
  • Mixed or hand-copied files. Copying a live datadir with cp or rsync is not even crash-consistent, because each file is copied at a different time. Restoring some tablespace files from one backup and the logs from another has the same effect.

There is also a quieter case. With innodb_flush_log_at_trx_commit set to 0 or 2, recovery succeeds, but the most recent commits before the snapshot can be missing. Nothing looks corrupted. A few recent orders or comments are simply gone.

Temporary mitigation: work on a copy and get a dump out

The short-term goal is to extract the data. Making the restored server healthy again comes later. Follow these steps in order:

  1. Keep the original snapshot untouched. Restore it again to a separate VM, or copy the datadir somewhere else, and do all the work on that copy.
  2. Start MySQL normally once and read the log. Recovery sometimes only needed more time, or it was blocked by one of the ordinary causes above.
  3. If InnoDB still aborts, set innodb_force_recovery in the [mysqld] section and try again. Start at 1 and raise the value one step at a time, only as far as you need.
  4. As soon as the server starts, dump everything and stop using that instance.
[mysqld]
# Temporary, for data extraction only. Remove after dumping.
# Start at 1. Values of 4 and above can permanently damage data files.
innodb_force_recovery = 1

Warning: at higher innodb_force_recovery levels, InnoDB skips parts of recovery, and recent versions switch it to read-only. Do not let the application write to this instance. Run something like mysqldump --single-transaction --routines --events --all-databases > recovered.sql, then load the dump into a fresh MySQL instance with a clean datadir.

Some forum answers suggest moving the redo log files aside so InnoDB recreates them. This throws away every change that was in the log but not yet applied to the data files, and it can leave tables silently inconsistent. Treat it as a last resort, use it only on a copy, and check where your version keeps those files first, because the location has changed between releases. For MyISAM tables, REPAIR TABLE or mysqlcheck --repair is the usual route.

Architectural fix: pick the consistency level per workload

The lasting fix is to stop relying only on crash-consistent snapshots for databases where a failed recovery would hurt. An application-consistent snapshot is taken after the database has been brought to a clean state on purpose. You can get there in a few ways. You can stop MySQL for the few seconds the snapshot takes. You can hold FLUSH TABLES WITH READ LOCK in an open session while the snapshot runs and then run UNLOCK TABLES. Or you can let the hypervisor call a guest agent hook that does one of those for you.

A plain filesystem freeze through a guest agent gives you a clean filesystem, but MySQL still sees a crash unless the hook script also involves MySQL. Whether your platform's snapshots call a guest agent at all depends on the hypervisor or panel, so check its documentation instead of assuming.

MethodWhat you getGood fitWatch out for
Crash-consistent snapshotDisk as of one instant, recovered like a power cutPure InnoDB on a single disk, as a fast rollback pointMyISAM, multi-disk VMs, caches that ignore flushes
App-consistent snapshotClean on-disk state, starts without crash recoveryBusy servers where a failed recovery is costlyBrief write pause or downtime during the snapshot
Logical dump (mysqldump, mariadb-dump)SQL file, portable across servers and versionsSmall to medium databases, migrations, a second backup layerRestore is slow for large data, and --single-transaction only covers InnoDB
Hot physical backup (Percona XtraBackup, mariabackup)Consistent copy of data files taken while the server runsLarge InnoDB databases that need fast restoresTool version must match the server version and fork

Some rules of thumb follow from this. A small WordPress or shop database can usually live with a crash-consistent snapshot plus a nightly logical dump, because the dump is the copy you can always load somewhere else. A large, write-heavy InnoDB server is better served by hot physical backups plus binary logs for point-in-time recovery. If you still have MyISAM tables, either convert them to InnoDB or make your snapshots app-consistent. On VMs with more than one disk, keep the datadir and its logs on the same disk, or confirm that your platform snapshots all disks atomically.

None of this counts until you have restored a backup and started MySQL from it. A green backup job only tells you a file was written. Why a successful backup job does not guarantee a working database restore covers how to test that properly.

If MySQL will not start after a snapshot restore, read the error log before changing anything. Rule out permissions, AppArmor or SELinux, and disk space. Then treat the restored disk as a server that lost power. Work on a copy, raise innodb_force_recovery only as far as you need, and get a dump out. For the long term, keep a database-aware backup next to the snapshots, whether that is a quiesced snapshot, a logical dump, or a hot physical backup, and run a test restore before you need it.