Table of Contents
Why Snapshot Systems Matter
Snapshot systems let you capture the state of data at a point in time and revert to it later. Unlike traditional backups (which usually copy data elsewhere), snapshots are typically:
- Space-efficient: only changes since the last snapshot are stored.
- Fast: created almost instantly.
- Integrated with the filesystem or storage layer.
They are especially useful for:
- Quickly undoing mistakes (accidental deletes/overwrites).
- Safe upgrades or configuration changes (“try it, and roll back if broken”).
- Consistent backups (e.g., freeze a snapshot, then back that up).
This chapter focuses on practical use of snapshot-capable systems you’re likely to encounter: LVM, Btrfs, ZFS, and filesystem-integrated snapshot tools.
Core Concepts Specific to Snapshots
To use snapshot systems effectively, you should recognize a few snapshot-specific ideas:
- Copy-on-write (COW)
Many snapshot systems are COW-based: when data changes after a snapshot, the new data is written elsewhere, while the snapshot still references the old blocks. This allows: - fast snapshot creation
- efficient storage, especially with many snapshots
- Read-only vs read-write snapshots
- Read-only: ideal for backups; guarantees no changes.
- Read-write: can be used for testing or cloning environments, but may consume more space as you diverge from the original.
- Snapshot hierarchy / parents
- Some systems (e.g., Btrfs, ZFS) treat snapshots as children/clones of a subvolume/dataset. Deleting a parent may be restricted if snapshots exist.
- Retention policies
- Snapshots accumulate and will eventually consume space.
- You need a strategy (e.g., hourly for 24 hours, daily for a week, weekly for a month) and a process for pruning old snapshots.
Using LVM Snapshots
Logical Volume Manager (LVM) can create snapshots of logical volumes. This works at the block layer, below filesystems.
Common Use Case
- You have
/dev/vg0/rootmounted at/. - You want to take a snapshot before a risky system update so you can revert if needed.
Creating an LVM Snapshot
- Check free space in the volume group:
sudo vgs
sudo lvsYou need enough free space in the volume group to hold changes made after the snapshot is taken.
- Create a snapshot logical volume:
Example: 10G snapshot of vg0/root named root_snap:
sudo lvcreate -L 10G -s -n root_snap /dev/vg0/rootKey options:
-s: create snapshot-L 10G: allocate 10 GiB for snapshot’s COW data (not the full size of the origin)-n root_snap: name of the snapshot LV
- Use the snapshot
Mount it read-only to inspect or export data:
sudo mkdir -p /mnt/root_snap
sudo mount -o ro /dev/vg0/root_snap /mnt/root_snapYou can now copy files out, compare configs, etc.
Reverting to an LVM Snapshot
LVM snapshots are typically designed to be short-lived. If you want to revert the original LV to the snapshot’s state:
- Ensure the origin is not mounted (or mounted read-only in special cases):
- Boot into rescue mode or a live environment.
- Unmount the original filesystem, e.g.:
sudo umount /dev/vg0/root- Merge the snapshot back:
sudo lvconvert --merge /dev/vg0/root_snapAfter merging, the snapshot LV disappears, and the origin LV returns to the snapshot state on next activation (e.g., reboot).
Removing LVM Snapshots
Snapshots consume space as changes occur. To remove them:
sudo umount /mnt/root_snap
sudo lvremove /dev/vg0/root_snapMonitoring usage:
sudo lvs
Watch the Data% or Cpy%Sync fields for snapshot space usage. If the snapshot runs out of allocated space, it can become invalid.
Btrfs Snapshots
Btrfs is a COW filesystem with built-in snapshotting. You work with subvolumes and their snapshots.
Basic Workflow
Assume:
- Btrfs filesystem is mounted at
/. - Root subvolume is
@, home is@home, etc. - You have
btrfs-progsinstalled.
Listing Subvolumes and Snapshots
sudo btrfs subvolume list /
Snapshots are just subvolumes, but typically stored in a dedicated directory (e.g., /.snapshots or /@.snapshots).
Creating a Snapshot
Read-only snapshot of / subvolume @ into /.snapshots/@-preupdate:
sudo mkdir -p /.snapshots
sudo btrfs subvolume snapshot -r /@ /.snapshots/@-preupdateKey options:
snapshot -r: create read-only snapshot.- Without
-r, you get a read-write snapshot.
Using a Snapshot
Mount a snapshot to inspect or recover files:
sudo mkdir -p /mnt/btrfs_snap
sudo mount -o subvol=@-preupdate /.snapshots /mnt/btrfs_snap
(Exact mount command depends on how your root btrfs volume is laid out; sometimes you mount the main device, e.g. /dev/sdaX, with -o subvol=....)
Then:
sudo cp /mnt/btrfs_snap/etc/important.conf /etc/Deleting a Snapshot
sudo btrfs subvolume delete /.snapshots/@-preupdateYou should periodically prune snapshots to reclaim space and keep performance reasonable.
Rolling Back with Btrfs
For root filesystem snapshots, a typical rollback strategy is:
- Boot into:
- a snapshot-aware boot entry (some distros create GRUB entries per snapshot), or
- a live/rescue system.
- Change which subvolume is used as the default:
List subvolumes with their IDs:
sudo btrfs subvolume list /Set default subvolume to a known-good snapshot:
sudo btrfs subvolume set-default <subvol_id_of_snapshot> /- Reboot. The system will boot into that snapshot state.
Different distributions provide tooling around this (e.g., snapper, timeshift), covered further below.
ZFS Snapshots
ZFS integrates filesystem and volume management, and has a robust snapshot system.
Assume:
- A dataset
tank/rootis mounted at/. - ZFS utilities are installed.
Listing ZFS Snapshots
sudo zfs list -t snapshot
Snapshots are named as dataset@snapname, e.g., tank/root@preupdate.
Creating a Snapshot
sudo zfs snapshot tank/root@preupdateFor multiple related datasets:
sudo zfs snapshot -r tank@preupdate
-r creates snapshots recursively for children.
Accessing Snapshot Data
Many systems auto-mount .zfs/snapshot under the mountpoint. For example:
ls /@.zfs/snapshot
ls /@.zfs/snapshot/preupdate
If root is on tank/root, you might see:
/tank/.zfs/snapshot/preupdate/...
You can copy files from there:
sudo cp /tank/.zfs/snapshot/preupdate/etc/important.conf /etc/Rolling Back with ZFS
Rollback discards all changes made since the snapshot:
sudo zfs rollback tank/root@preupdateYou can also roll back recursively if using recursive snapshots:
sudo zfs rollback -r tank@preupdate
Note that rollback is destructive: newer snapshots may be affected depending on flags used. Read the zfs-rollback man page carefully on production systems.
Deleting ZFS Snapshots
To free space:
sudo zfs destroy tank/root@preupdate
You can use zfs list -t snapshot to see which snapshots consume the most space (REFER and USED columns).
Snapshot Management Tools (Snapper, Timeshift)
Several tools provide friendlier, policy-based management on top of Btrfs or rsync-like snapshots. These don’t replace understanding the underlying mechanisms, but they simplify daily use.
Snapper (Primarily Btrfs)
Snapper manages Btrfs snapshots, including:
- automatic pre/post snapshots for
zypper/dnf/aptoperations (on some distros), - scheduled snapshots (hourly, daily, etc.),
- snapshot cleanup according to configured limits.
Basic Operations
Create a snapshot:
sudo snapper create --description "before upgrade"List snapshots:
sudo snapper listCompare snapshots (diff):
sudo snapper diff <id1> <id2>Undo changes between snapshots:
sudo snapper undochange <id1>..<id2> /path
Exact integration and configuration differ by distribution (often in /etc/snapper/configs/), but the pattern is:
- Snapper auto-creates snapshots, tags them (e.g.
pre,post), - You can roll back individual files or entire directories.
Timeshift (Desktop-Focused)
Timeshift primarily targets desktop systems, offering snapshot-based system restore using:
- Btrfs snapshots, or
- rsync-based copies.
Typical workflow:
- Configure Timeshift:
- select snapshot type (Btrfs/rsync),
- set location and schedule,
- choose inclusion rules (usually system files, not user data).
- Timeshift automatically makes:
- hourly/daily/weekly snapshots,
- “before package upgrade” snapshots (on some systems).
- To restore:
- run Timeshift,
- pick a snapshot,
- choose “Restore” to revert system files to that state.
Timeshift focuses on system-level state, not user home data (you use separate backup tools for /home).
Snapshot Strategies and Best Practices
When to Use Snapshots vs Traditional Backups
Snapshots are:
- Not a substitute for offsite or offline backups.
- Stored on the same physical storage as the original data in most cases.
Good pattern:
- Use snapshots as short/medium-term safety nets.
- Use traditional backups (
rsync,tar, remote backups, etc.) for long-term, off-system protection.
Typical Snapshot Policies
Examples (adjust for your needs and space):
- For a workstation or small server:
- Btrfs/ZFS:
- hourly snapshots, keep last 24;
- daily snapshots, keep last 7;
- weekly snapshots, keep last 4.
- LVM:
- pre-upgrade snapshot; delete after verifying success.
- For critical systems:
- Combine:
- very frequent snapshots (e.g., every 15 minutes for a database dataset),
- plus regular offsite backups of selected snapshots.
Space Management
Keep an eye on:
- For LVM: free space in the volume group and snapshot LV usage.
- For Btrfs/ZFS: overall free space and per-snapshot usage.
Tools:
- LVM:
vgs,lvs,lvdisplay - Btrfs:
btrfs filesystem df,btrfs qgroup show(if quotas used) - ZFS:
zfs list -t snapshot,zfs get used,refer
Automated cleanup using tools like Snapper or custom scripts is often necessary.
Consistency Considerations
Snapshots capture an instantaneous view of the filesystem or block device. For application-consistent snapshots:
- Quiesce applications if possible (e.g., flush database writes, put DB into backup mode).
- Use application-specific tools or hooks before triggering a snapshot.
On small personal systems, this level of rigor is often skipped, but on important servers, it matters.
Integrating Snapshots with Backup Workflows
A common pattern:
- Create a snapshot of the dataset/filesystem.
- Back up from the snapshot, not the live filesystem:
- ensures a consistent view;
- avoids locking files for long.
- Delete the snapshot when the backup completes.
Example with Btrfs:
SNAP_NAME="backup-$(date +%F-%H%M)"
sudo btrfs subvolume snapshot -r /@ /.snapshots/@-$SNAP_NAME
# Backup the snapshot (to remote host, for example)
sudo rsync -aHAX /.snapshots/@-$SNAP_NAME/ user@backup:/backups/host/root/$SNAP_NAME/
# Remove snapshot
sudo btrfs subvolume delete /.snapshots/@-$SNAP_NAME
This pattern works similarly with ZFS (zfs snapshot then zfs send | zfs receive or rsync) and LVM (snapshot LV, then mount and back it up).
Summary
- Snapshot systems provide fast, space-efficient point-in-time copies of data.
- LVM offers block-level snapshots suitable for any filesystem.
- Btrfs and ZFS integrate snapshots directly at the filesystem level, making them easy to manage and powerful for rollback and cloning.
- Tools like Snapper and Timeshift sit on top of snapshot-capable filesystems to automate creation and cleanup.
- Snapshots complement, but do not replace, traditional backups—combine both for a robust backup and restore strategy.