Skip to main content

Filesystem Snapshots: Time Travel for Your Data

How modern filesystems create instant snapshots. Explore Btrfs/ZFS snapshot mechanics, rollback operations, and backup strategies interactively.

10 min|linuxfilesystemsstoragebackup
Best viewed on desktop for optimal interactive experience

Why Snapshots Matter

Imagine being able to take a photograph of your entire filesystem -- every file, every directory, every byte -- in less time than it takes to blink. Now imagine doing this every hour, keeping weeks of these photographs, and having it cost almost nothing in disk space. That is what filesystem snapshots provide.

Traditional backups are slow and expensive. Copying 100GB of data to a backup location takes hours and consumes another 100GB of storage. Snapshots take milliseconds and initially consume zero additional space. This is not magic -- it is the result of a fundamental architectural principle called Copy-on-Write (CoW), which makes "copying" data a matter of creating a new pointer rather than duplicating blocks.

Snapshots have become essential infrastructure for system administration: creating a safety net before software upgrades, providing hourly recovery points for accidental deletions, spinning up instant test environments from production data, and enabling incremental replication to offsite backup servers.

How Snapshots Work: Interactive Exploration

Watch snapshot creation, modification tracking, and rollback in action below. The visualization shows how CoW allows the original and the snapshot to share unchanged blocks while diverging only where modifications occur:

Interactive Snapshot Mechanism

Snapshot Creation: Instant & Space-Efficient

Step 1: Initial Filesystem State

Filesystem Blocks:
Block 100
File A
refs: 1 | current
Block 101
File B
refs: 1 | current
Block 102
File C
refs: 1 | current
Space Usage:
Current: 30GB
Snapshots: 0GB
Total: 30GB
What's happening:
  • Filesystem has 3 files (30GB total)
  • No snapshots exist yet
  • All blocks owned by current filesystem
  • Space usage: 30GB
Step 1 of 5

The Copy-on-Write Foundation

A snapshot does not copy data. It copies metadata -- the tree of pointers that describes where each file's blocks live on disk. At the moment of creation, the snapshot and the live filesystem point to exactly the same physical blocks. Total additional space consumed: effectively zero.

When the live filesystem modifies a block after a snapshot exists, the kernel does not overwrite the original block. Instead, it writes the new version to a fresh location and updates only the live filesystem's pointer. The snapshot's pointer still references the original block, preserving the old state. This is the copy-on-write principle: data is only "copied" (really, preserved) at the moment it would otherwise be overwritten.

This mechanism has a profound implication for space accounting. A snapshot of a 100GB filesystem does not cost 100GB. It costs only as much space as the data that changes after the snapshot is taken. If you modify 5GB of files, the snapshot holds onto the original 5GB while the live filesystem uses the new 5GB, for a total of 105GB -- not 200GB.

Space Efficiency with Multiple Snapshots

The space savings compound beautifully with multiple snapshots. Consider a 100GB filesystem with hourly snapshots where 1GB changes per hour:

StateTotal Disk UsedNaive Copy Would Use
Original data100 GB100 GB
After 1 snapshot + 1 GB changed101 GB200 GB
After 24 snapshots + 24 GB changed124 GB2,500 GB
After 168 snapshots (1 week) + 100 GB changed200 GB16,900 GB

The gap between CoW snapshot storage and naive copy storage grows wider with every snapshot. This is why modern systems can maintain hundreds of snapshots without running out of space.

Read-Only vs Writable Snapshots

Snapshots come in two flavors, each serving a distinct purpose:

Read-only snapshots are the default on most filesystems. They provide an immutable historical reference -- a perfect record of the filesystem at a specific moment. You can browse them, read files from them, and use them as a source for restoring data, but you cannot modify them. This immutability is a feature: it guarantees that your recovery point cannot be accidentally or maliciously altered.

Writable snapshots (clones) create an independent, modifiable copy of the filesystem that starts as an exact duplicate. They are ideal for testing: clone your production database, run a destructive migration test against the clone, and discard it if things go wrong -- all without touching production data and without waiting for a full copy. Clones share all unchanged blocks with their parent, so creating one is just as fast and space-efficient as a read-only snapshot.

Snapshot vs Traditional Backup

PropertyCoW SnapshotTraditional Backup (rsync/tar)
Creation timeMillisecondsMinutes to hours
Initial space costNear zeroFull copy of data
Incremental costOnly changed blocksVaries by tool
Recovery timeInstant (rollback)Minutes to hours (restore)
Protects against disk failureNo (same disk)Yes (if offsite)
Protects against accidental deletionYesYes
Protects against ransomwarePartially (read-only snapshots)Yes (if offsite and immutable)

The critical distinction is that snapshots live on the same physical storage as the original data. If the disk itself fails, both the live data and all snapshots are lost. This is why snapshots complement backups but never replace them.

Rolling Back

The most powerful use of snapshots is rollback -- reverting the entire filesystem to a previous state. This is invaluable before risky operations like OS upgrades, kernel updates, or major configuration changes. If the upgrade breaks the system, rolling back to the pre-upgrade snapshot restores everything to exactly the way it was, often in seconds.

On Btrfs, rollback involves replacing the current subvolume with a snapshot. On ZFS, a dedicated rollback operation atomically reverts a dataset to a snapshot's state. Some Linux distributions, most notably openSUSE, integrate snapshot rollback directly into the boot loader -- if an upgrade goes wrong, you can select a previous snapshot from the GRUB menu and boot into it.

The key caution with rollback is that it is all-or-nothing for the affected volume. You cannot selectively roll back individual files from a snapshot rollback operation (though you can manually copy individual files out of a snapshot before rolling back).

Send/Receive: Turning Snapshots into Backups

The send/receive mechanism bridges the gap between snapshots and true backups. Both Btrfs and ZFS can serialize a snapshot into a data stream and transmit it to another filesystem -- on a different disk, a different machine, or across a network to an offsite server.

The real power is incremental send. After the initial full transfer, subsequent sends contain only the blocks that changed between two snapshots. A filesystem with 100GB of data but only 500MB of daily changes transmits just 500MB per day to the backup server, regardless of total size. This makes efficient offsite replication practical even over modest network connections.

This combination -- local snapshots for instant rollback, incremental send/receive for offsite protection -- provides a comprehensive data protection strategy that covers both the "oops, I deleted a file" scenario and the "the building burned down" scenario.

Automated Snapshot Policies

Manual snapshots are useful for one-off safety nets, but the real value comes from automated policies that maintain a rolling window of recovery points. A typical retention policy looks like this:

FrequencyRetentionPurpose
Every 15 minutesKeep 4Recover from very recent mistakes
HourlyKeep 24Fine-grained recovery within the last day
DailyKeep 7Recover anything from the past week
WeeklyKeep 4Monthly recovery points
MonthlyKeep 12Annual archive

Automation tools like Snapper (for Btrfs) and zfs-auto-snapshot (for ZFS) manage this lifecycle automatically -- creating snapshots on schedule, pruning old ones according to the retention policy, and integrating with package managers to snapshot before and after system updates.

Several Linux distributions have embraced snapshot automation at the system level. openSUSE creates automatic Btrfs snapshots before and after every package operation, with rollback available from the boot menu. Ubuntu offers similar functionality through apt-btrfs-snapshot. The general-purpose tool Timeshift provides a graphical interface for managing Btrfs or rsync-based system snapshots on any distribution.

Limitations and Caveats

Snapshots are not backups

This point bears repeating because it is the most common source of data loss among snapshot users. Snapshots reside on the same physical storage pool as the live data. A disk failure, controller failure, or filesystem corruption event destroys both the live data and every snapshot simultaneously.

Space is not free forever

While individual snapshots are cheap, they accumulate. Every block that has been modified since a snapshot was taken must be preserved as long as that snapshot exists. A filesystem with many old snapshots and high write churn can consume space surprisingly fast. Monitoring space usage and enforcing retention policies is essential.

Performance considerations

Large numbers of snapshots can impact performance in specific ways. Deleting files becomes slower because the kernel must check reference counts to determine whether a block is still needed by any snapshot. Btrfs balance operations slow down proportionally to the number of snapshots. ZFS scrubs must read through all snapshot data, increasing scrub times.

Clone dependency chains

Writable clones (snapshots promoted to independent volumes) create dependency relationships. A snapshot cannot be deleted if a clone depends on it -- the clone must be "promoted" first, which reverses the parent-child relationship. Deep chains of clones and snapshots can become difficult to manage.

  • Copy-on-Write: The mechanism that makes snapshots instant and space-efficient
  • Btrfs: Subvolume-based snapshots with Snapper integration
  • ZFS: Dataset snapshots, clones, and RAID-Z integration
  • Journaling: An alternative consistency mechanism that protects metadata rather than providing point-in-time recovery

Key Takeaways

  1. Snapshots are instant and nearly free because they leverage copy-on-write to share unchanged blocks between the snapshot and the live filesystem.

  2. Space cost is proportional to change, not to size. A snapshot of a 1TB filesystem costs nothing at creation and grows only as data is modified.

  3. Rollback is the killer feature. The ability to revert an entire filesystem to a known-good state in seconds makes risky operations safe.

  4. Send/receive turns snapshots into backups. Incremental replication to offsite storage provides true disaster recovery with minimal bandwidth.

  5. Snapshots are not backups on their own. They protect against accidental changes, not against hardware failure. Always combine snapshots with offsite replication or traditional backups.

  6. Automate with retention policies. Manual snapshots are useful; automated snapshot schedules with principled retention are essential for production systems.

If you found this explanation helpful, consider sharing it with others.

Mastodon