Skip to content

Snapshots & Clones


Snapshots: Point-in-Time Protection

ZFS snapshots are read-only, space-efficient copies of datasets. They use copy-on-write (CoW) to share data with the original dataset until modifications occur.

Creating a snapshot:

zfs snapshot tank/data@snap1
This creates a snapshot named snap1 for the tank/data dataset.

Listing snapshots:

zfs list -t snapshot
Output includes snapshot names, creation time, and space used.

Destroying a snapshot:

zfs destroy tank/data@snap1
Use zfs destroy -r to recursively delete nested snapshots.

Pruning old snapshots:
To prune old snapshots, use zfs destroy with retention policies or scripts. For example:

zfs destroy -r tank/data@snap2
zfs destroy -r tank/data@snap3
zfs destroy -r tank/data@snap4
zfs destroy -r tank/data@snap5
zfs destroy -r tank/data@snap6
zfs destroy -r tank/data@snap6a
Automate pruning with retention policies:
zfs set retention=7d tank/data
This keeps snapshots for 7 days before pruning.


Clones: Writable Branches of Snapshots

Clones are writable datasets that fork from a snapshot. They share data with the original snapshot but allow independent modifications.

Creating a clone:

zfs clone tank/data@snap1 tank/data_clone
This creates a new dataset tank/data_clone based on snap1.

Cloning a snapshot:

zfs clone -o snapdir=hidden tank/data@snap1 tank/data_clone2
Cloning a snapshot creates a writable clone, which can itself be cloned to enable branching workflows.

Modifying a clone:

echo "Test data" > /tank/data_clone/testfile
Changes to the clone do not affect the original snapshot.


Snapshot and Clone Management

  • Retention policies: Use zfs set snapdir=hidden to hide snapshots from zfs list.
  • Space management: Snapshots consume space only when data changes. Use zfs list to monitor usage.
  • Backup with snapshots: Use zfs send and zfs receive to transfer snapshots between pools.

Example: Backing up a snapshot

zfs send tank/data@snap1 | zfs receive tank/data_backup


Troubleshooting Tips

  • Snapshot size issues: If a snapshot grows unexpectedly, investigate CoW behavior or data changes.
  • Clone conflicts: Ensure the target dataset name does not already exist when cloning.
  • Snapshot dependencies: Destroy child snapshots before deleting parent snapshots.

Key takeaways

  • Snapshots provide efficient, read-only backups with minimal storage overhead.
  • Clones enable safe, writable branching from snapshots for testing or development.
  • Use zfs snapshot and zfs clone to manage data protection and workflow flexibility.
  • Regularly prune old snapshots and monitor space usage to avoid storage exhaustion.
  • Combine snapshots with zfs send/receive for offsite backups or dataset replication.