Synopsis #
A ZFS clone is a writable dataset created from a snapshot. It initially shares the snapshot’s blocks and consumes more space as files change. Use it to test data changes without modifying the source dataset.
This example uses tank/data, an existing dataset, and creates tank/data-test. Replace tank with the pool name. For changes to the operating system itself, use a boot environment
.
Create the clone #
Check the source dataset and available pool space. Choose an unused snapshot name, clone name, and mount point:
# zfs list tank/data
# zpool list tank
# zfs snapshot tank/data@before-test
# zfs clone -o mountpoint=/mnt/data-test tank/data@before-test tank/data-test
# zfs get origin,mountpoint tank/data-test
The clone contains the source data as it existed at the snapshot. Its origin should be tank/data@before-test and its mount point /mnt/data-test.
A snapshot of a running database does not replace a database backup. Stop writes or follow the application’s backup procedure before taking the snapshot.
Make changes in the clone #
Work under /mnt/data-test, leaving the original mount point alone. Confirm the path before running tools that modify or delete files:
$ df /mnt/data-test
$ ls /mnt/data-test
If an application will use the clone, change its data path and keep its ports, sockets, and services separate from the original instance. Creating the clone does not redirect applications automatically.
Compare the changed files with the original dataset. Changes in the clone should leave the original unchanged. Monitor space while testing:
# zfs list -o name,used,refer,mountpoint tank/data tank/data-test
Remove the test copy #
Save any results needed elsewhere and stop processes using the clone. The following commands permanently discard the test copy and then its source snapshot:
# zfs destroy tank/data-test
# zfs destroy tank/data@before-test
The snapshot cannot be removed while the clone depends on it.