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:
snap1 for the tank/data dataset.
Listing snapshots:
Destroying a snapshot:
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
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:
tank/data_clone based on snap1.
Cloning a snapshot:
Modifying a clone:
Snapshot and Clone Management¶
- Retention policies: Use
zfs set snapdir=hiddento hide snapshots fromzfs list. - Space management: Snapshots consume space only when data changes. Use
zfs listto monitor usage. - Backup with snapshots: Use
zfs sendandzfs receiveto transfer snapshots between pools.
Example: Backing up a snapshot
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 snapshotandzfs cloneto manage data protection and workflow flexibility. - Regularly prune old snapshots and monitor space usage to avoid storage exhaustion.
- Combine snapshots with
zfs send/receivefor offsite backups or dataset replication.