lvm thin send/recv

A few days ago i found this mail on the LKML that introduces support for userspace access to LVM thin provisioned metadata snapshots. I didn’t know this is possible.

Using the thin provisioning tools you can then export the metadata information for your LVM snapshots to track changed regions between them.

The workflow is pretty straight forward, yet not really documented:

  • Create a base snapshot for a volume on a thin provisioned LVM pool, this snapshot is used as reference for further incremental snapshots:
# lvcreate -ay -Ky --snapshot -n full_backup thingroup/vol1
  • Now copy some data to the volume and create another snapshot, additionally tell the kernel to create a metadata snapshot using dmsetup.
  # dmsetup message /dev/mapper/thingroup-thinpool-tpool 0 reserve_metadata_snap
  # lvcreate -ay -Ky --snapshot -n inc_backup thingroup/vol1
  • Export an XML description of the differences between the snapshots using the thin_delta executable and release the snapshot:
  # thin_delta  -m --snap1 $(lvs --noheadings -o thin_id thingroup/full_backup) --snap2 $(lvs --noheadings -o thin_id thingroup/inc_backup) > delta_dump
  # dmsetup message /dev/mapper/thingroup-thinpool-tpool 0 release_metadata_snap
  • Parse the resulting XML file and read the blocks reported as “different” and “right only” from the created data snapshot.

This all has already been implemented by a nice utility called thin-send-recv, which based on this functionality allows to (incrementally) send LVM snapshots to remote systems just like zfs send or zfs recv.

Written on May 21, 2024