Initial impact: the server is back but the database is not
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
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:
BASH
# 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/mysqlmysql 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
TEXT
# 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- 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
cporrsyncis 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.
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
- 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.
- 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.
- If InnoDB still aborts, set
innodb_force_recoveryin the[mysqld]section and try again. Start at 1 and raise the value one step at a time, only as far as you need. - As soon as the server starts, dump everything and stop using that instance.
INI
[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 = 1innodb_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
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.
| Method | What you get | Good fit | Watch out for |
|---|---|---|---|
| Crash-consistent snapshot | Disk as of one instant, recovered like a power cut | Pure InnoDB on a single disk, as a fast rollback point | MyISAM, multi-disk VMs, caches that ignore flushes |
| App-consistent snapshot | Clean on-disk state, starts without crash recovery | Busy servers where a failed recovery is costly | Brief write pause or downtime during the snapshot |
Logical dump (mysqldump, mariadb-dump) | SQL file, portable across servers and versions | Small to medium databases, migrations, a second backup layer | Restore 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 runs | Large InnoDB databases that need fast restores | Tool version must match the server version and fork |
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.