Crash-Consistent vs Application-Consistent Backups: Why a Live Copy Fails to Open, Snapshots, fsfreeze and WAL
Copying the files of a running service is not a backup. The difference between inconsistent, crash-consistent and application-consistent copies, when a disk snapshot is enough, applications spread over several volumes, and the pitfalls that surface on restore.
Copying the disk of a running service looks like the easiest way to take a backup. You rsync the files somewhere else, or you take a snapshot at the storage layer, and you are done. The problem shows up on restore day: the database refuses to start, an index is corrupt, or it starts but the last few minutes of data do not add up. This post covers which level of consistency a backup actually needs in order to be restorable, and how to get there.
Three levels of consistency
Inconsistent copy. Copying the files of a running application one by one falls into this class. The copy takes minutes; the first file is captured as it was at 10:00, the last as it was at 10:07. The result is a disk image that never existed at any single moment. For database files that means some pages are old and some are new, and no recovery mechanism can fix that. Taking a running database's data directory with rsync or tar is not a backup.
Crash-consistent copy. A frozen image of the disk at one instant. It is in the same state as the disk of a machine that lost power: in-memory buffers were never written, but every block on disk belongs to the same moment. LVM, ZFS and Btrfs snapshots, as well as cloud provider disk snapshots, give you this level. Software that keeps a write-ahead log (WAL, redo log, journal) is designed to survive exactly this: on startup it replays the log and returns to a consistent state.
Application-consistent copy. A copy taken at a moment when the application itself says "what is on disk right now is complete and closed". Either the application pauses writes briefly, or it produces a consistent dump through its own backup interface. Restoring it needs no recovery step, or the point up to which recovery is replayed is well defined.
When crash consistency is enough
There is a common over-caution here: some teams insist on application-consistent backups for every database and stop the service to get them. Most of the time this is unnecessary. The PostgreSQL documentation accepts a single atomic snapshot of the entire data directory (including the WAL directory) as a valid backup method; on restore the server simply performs normal crash recovery. The same reasoning holds for MySQL and MariaDB with InnoDB.
Two conditions must hold for this to work:
- The application's data and its log must be in the same snapshot. If data lives on one volume and WAL on another, and the two snapshots were taken a few seconds apart, you are back in the inconsistent class.
- The application must be relying on write ordering and
fsync. Settings that turn this off (fsync = offorfull_page_writes = offin PostgreSQL, "fast but unsafe" modes elsewhere) take crash consistency away as well.
For software without a journal, applications that update several files forming one logical structure independently, and services that "write state to disk on shutdown", a crash-consistent copy is not enough.
Ways to reach application consistency
Use the application's own backup tool
This is the most reliable path, because responsibility for consistency stays with the software that understands the file format.
For SQLite, instead of copying the file of a live database, use the built-in online backup command:
sqlite3 /var/lib/app/app.db ".backup '/backup/app-$(date +%F).db'"
Copying only the .db file of a SQLite database in WAL mode is particularly dangerous; recent transactions live in the -wal file and are missing from the copy.
In PostgreSQL, pg_dump gives a logical, consistent dump, but restoring a large database from it is slow. For physical backups, pg_basebackup or a backup tool that archives WAL is the better choice. In Redis, BGSAVE writes an RDB file that belongs to one instant; copy it only after the save has finished, by checking that LASTSAVE has changed.
Tell the application a backup is starting
If you want to keep the speed of storage snapshots, you can notify the application before the snapshot. PostgreSQL 15 and later provide pg_backup_start() and pg_backup_stop() for this. The critical detail: both calls must happen in the same database session, and that session must stay open until the snapshot completes. If a script runs psql -c "SELECT pg_backup_start(...)" and exits, the session closes and backup mode is cancelled. The backup label returned by pg_backup_stop() must also be stored alongside the backup.
In MySQL the classic approach is to lock tables with FLUSH TABLES WITH READ LOCK, take the snapshot, and release the lock with UNLOCK TABLES. The same trap applies: the lock only lives as long as the connection that took it.
Freeze the filesystem
fsfreeze holds new writes to a filesystem and flushes everything pending to disk. That gives filesystem-level consistency, not application-level consistency: data still sitting in the application's memory is outside the snapshot. On its own it is not enough, but combined with the application's own flush command it is useful.
#!/usr/bin/env bash
set -euo pipefail
MNT=/srv/data
fsfreeze --freeze "$MNT"
trap 'fsfreeze --unfreeze "$MNT"' EXIT
lvcreate --snapshot --size 10G --name data-snap /dev/vg0/data
The trap is not decoration. If a frozen filesystem stays frozen, every process trying to write to it blocks; the service times out, health checks fail, and from the outside it looks like an outage.
Pitfalls
Applications spread over several volumes. If data, logs and attachments live on separate disks, snapshotting each disk separately breaks consistency. Either use a group snapshot that freezes all of them at once (multi-volume snapshot features of cloud providers, VolumeGroupSnapshot in Kubernetes), or hold the application's writes for the duration of the snapshots.
Consistency between the database and object storage. If the application writes the file itself to object storage and its record to the database, the two are backed up at different times. On restore you get records without files, or orphaned files. No disk snapshot solves this. The practical answer is to keep versioning enabled on the object store and back up the database before the objects; that way every file the database knows about is in the backup set, and extra files are removed later by a cleanup job.
Classic LVM snapshots filling up. A thick LVM snapshot can only hold as many changes as the space you allocated. Leave it open for hours on a write-heavy volume and the space runs out, the snapshot becomes invalid, and the backup tool often carries that forward silently as an empty or broken copy. Keep the snapshot only for the duration of the copy and watch its usage.
Treating the snapshot as the backup. A snapshot in the same pool, the same disk array or the same cloud account disappears together with it. A snapshot only produces a consistent source; the backup is created when that source is copied somewhere else.
The consistency level of Kubernetes volume snapshots. VolumeSnapshot objects taken through CSI drivers are crash-consistent. Tools like Velero offer hooks that run commands inside the pod before and after the snapshot; if you need application consistency, that is where the flush or freeze command goes. If hook failures are configured not to stop the backup, remember that a hook can fail silently while the backup still shows as successful.
Which one to choose
If I have to take a side: for a journaling database on a single volume, an atomic disk snapshot plus WAL archiving gives most teams the best trade-off. It is fast, it does not stop the service, and it allows point-in-time recovery. For applications whose data is spread across several places and for software without a journal, use the application's own backup tool; in those cases a disk snapshot gives false confidence rather than real safety.
Treat freezing and locking as a last resort. Each one means a short write outage during the backup, and a single bug in the script can turn that short outage into a long one.
Whichever path you pick, verify consistency by restoring, not by reading documentation: open the snapshot on a separate machine, start the application, and check that recovery completed and the most recently written records are there. How fast you took a copy that will not open does not matter.