Skip to content

LVM and ZFS snapshot backups for consistent state-ful workloads

Take consistent storage-layer snapshots with LVM and ZFS, mount them for rsync or restic, and replicate ZFS sends to an offsite pool.

A database server, a Docker host with persistent volumes, or any large state-ful workload cannot be safely backed up with a plain file-level rsync — the files are mutating mid-copy and the result is a Frankenstein of inconsistent state. Storage-layer snapshots are the answer: a near-instantaneous, atomic, point-in-time copy at the block level that you can mount, back up, and discard. This article walks the two tools that matter on Linux — LVM thin-provisioned snapshots and ZFS snapshots — and the patterns each enables.

How to verify

For an existing host, find out which volume manager is in play and look at the snapshot history:

sudo lvs -o +lv_attr,origin,data_percent
sudo vgs -o +vg_free
sudo zpool list
sudo zfs list -t snapshot -o name,used,refer,creation
sudo zfs get com.sun:auto-snapshot

lvs shows LV attributes; the O flag means origin (a snapshot was taken). zfs list -t snapshot is the per-dataset snapshot history. If there is no snapshotting in evidence, the existing backups are likely inconsistent at the application layer.

What’s happening

LVM thin snapshots: a thin-provisioned LV in a thin pool exposes a copy-on-write snapshot in O(1) time. The snapshot starts empty (logically); as the origin diverges, the differing blocks accumulate in the thin pool. Read from the snapshot returns the origin’s state at snapshot time. Snapshots cost space proportional to the change rate, not the volume size, and exhausting the thin pool freezes IO for everything in it — capacity discipline matters.

ZFS snapshots: a filesystem-level snapshot at copy-on-write semantics, native to the filesystem rather than the block device. Creation is constant-time, snapshots can be sent incrementally between pools (zfs send/zfs receive), they cannot be modified once taken, and they consume only delta blocks. Send/receive over SSH replicates an entire dataset to an offsite pool with optional encryption preserved across the wire.

The procedure

LVM thin snapshot for a database backup

  1. Confirm thin provisioning. Snapshots on a non-thin LV grow until the snapshot LV’s preallocated space is exhausted, then break silently. Use a thin pool.

    sudo lvs -o name,attr,size,data_percent,pool_lv
  2. Quiesce the application briefly. For Postgres, pg_start_backup() and pg_stop_backup() in non-exclusive mode; for MySQL, FLUSH TABLES WITH READ LOCK and UNLOCK TABLES. Take the snapshot in between.

    # In another shell
    sudo lvcreate --thin --snapshot --name pg-snap-2026-06-02 vg0/pg-data
  3. Mount and back up. The snapshot is a normal block device.

    sudo mkdir -p /mnt/pg-snap
    sudo mount -o ro /dev/vg0/pg-snap-2026-06-02 /mnt/pg-snap
    restic backup --tag pg-snap /mnt/pg-snap
    sudo umount /mnt/pg-snap
    sudo lvremove -f vg0/pg-snap-2026-06-02

ZFS snapshot + offsite replication

  1. Create a snapshot. Recursive on the dataset and its children.

    sudo zfs snapshot -r tank/data@2026-06-02T02:00
    sudo zfs list -t snapshot -r tank/data
  2. Send the first snapshot to the offsite pool. Full send the first time; subsequent sends are incremental.

    sudo zfs send -R tank/data@2026-06-02T02:00 \
      | mbuffer -s 128k -m 1G \
      | ssh backup.example.com 'mbuffer -s 128k -m 1G | sudo zfs receive -F offsite/tank-mirror'
  3. Incremental sends on subsequent runs. -i references the previous snapshot known on the destination.

    PREV=2026-06-01T02:00
    CURR=2026-06-02T02:00
    sudo zfs send -R -i "tank/data@${PREV}" "tank/data@${CURR}" \
      | ssh backup.example.com "sudo zfs receive -F offsite/tank-mirror"
  4. Use zfs-auto-snapshot or sanoid for retention. Sanoid declaratively manages frequency and retention; syncoid handles the replication side. The pair is the de-facto Linux ZFS replication tool.

    # /etc/sanoid/sanoid.conf
    [tank/data]
        use_template = production
        recursive = yes
    
    [template_production]
        frequently = 0
        hourly = 24
        daily = 14
        monthly = 6
        yearly = 0
        autosnap = yes
        autoprune = yes
    sudo apt install -y sanoid
    sudo systemctl enable --now sanoid.timer
  5. Verify on the destination. zfs list -t snapshot on the offsite host should show the same snapshot history minus the latency.

    ssh backup.example.com "sudo zfs list -t snapshot -r offsite/tank-mirror | tail"

Common pitfalls

  • An LVM thin pool that fills up freezes all IO on every LV in it; alert on data_percent and meta_percent thresholds well below 100.
  • A snapshot of a database with no quiesce is “crash-consistent” — it usually replays cleanly on restore but is not the same as a logical backup.
  • ZFS encryption at the dataset level survives zfs send only with -w (raw send); without it, the destination dataset must decrypt and re-encrypt.
  • A long-held LVM snapshot accumulates COW writes and slows down the origin LV — keep snapshots short-lived and remove them after the backup completes.
  • zfs receive on a fresh destination must use -F to allow overwriting; on an existing one, -F rolls back the dest to match the source, which is destructive — know which mode you are in.

In the engagements we run, ZFS replication is the storage-tier backup for any host where the data exceeds what restic can scan in a backup window, and LVM thin snapshots are the bridge for application-consistent file-level backups on hosts that don’t run ZFS. The destination pool is on a separate physical site or cloud region and is checked alongside the regular /en/knowledge-base/disaster-recovery-drill/. See /en/services/managed-operations/.