TrueNAS CORETrueNAS CORE Nightly Development Documentation
This content follows experimental early release software. Use the Product and Version selectors above to view content specific to a stable software release.

Creating Snapshots

Snapshots are one of the most powerful features of ZFS. A snapshot provides a read only point-in-time copy of a file system or volume. This copy does not consume extra space in the ZFS pool. The snapshot only records the differences between storage block references whenever the data is modified.

Why do I want to keep snapshots? Snapshots keep a history of files and provide a way to recover an older or even deleted files. For this reason, many administrators take regular snapshots, store them for some time, and copy them to a different system. This strategy allows an administrator to roll the system data back to a specific point in time. In the event of catastrophic system or disk failure, off-site snapshots can restore data up to the most recent snapshot.

Taking snapshots requires the system have all pools, datasets, and zvols already configured.

Creating a Single Snapshot

Consider making a Periodic Snapshot Task to save time and create regular, fresh snapshots.

To perform a quick snapshot of existing storage, go to Storage > Snapshots and click ADD.

StorageSnapshotsAdd

Use the Dataset dropdown list to select an existing ZFS pool, dataset, or zvol to snapshot.

The TrueNAS software displays a suggested name that you can override with any custom string.

To include the snapshot in local or remote replication tasks choose a proper naming schema. The Naming Schema drop-down list populates with schemas already created from periodic snapshot tasks.

To include child datasets with the snapshot, select Recursive.

Managing Snapshots

Go to Storage > Snapshots to manage created snapshots.

StorageSnapshots

Each entry in the list includes the dataset and snapshot names. Click to view options for a snapshot.

DATE CREATED shows the exact time and date of the snapshot creation.

USED shows the amount of space consumed by this dataset and all of its descendants. This value, checked against the dataset quota and reservation, shows the space used but does not include the dataset reservation. It takes into account the reservations of any descendant datasets. The amount of space that a dataset consumes from its parent, and the amount of space freed if this dataset is recursively deleted, is the greater of its space used and its reservation.

At creation, a snapshot shares space between the snapshot, file system, and even with previous snapshots. File system changes reduce the shared space and count toward space used by a snapshot. Deleting a snapshot often increases the space that is unique and used in other snapshots.

REFERENCED shows the amount of data accessible by this dataset. This could be shared with other datasets in the pool. New snapshots or clones reference the same amount of space as the file system it was created from, as the contents are identical.

Viewing Used Space with Shell

Another method to view the space used by an individual snapshot is to go to the shell and enter command zfs list -t snapshot.

The space used, available, or referenced does not account for pending changes. In general, pending changes update within a few seconds, but larger disk changes slow usage updates.

Deleting a Snapshot

The Delete option destroys the snapshot. You must delete child clones before you can delete their parent snapshot. While creating a snapshot is instantaneous, deleting one is I/O intensive and can take a long time, especially when deduplication is enabled.

Why? ZFS has to review all allocated blocks before deletion to see if another process is using that block. If not used, the ZFS can free that block.

Cloning a Snapshot

Use CLONE TO NEW DATASET to create a new snapshot clone (dataset) from the snapshot contents.

What is a clone? A clone is a writable copy of the snapshot. Because a clone is actually a mountable dataset, it appears in the Pools screen rather than the Snapshots screen. Creating a new snapshot adds -clone to the name by default.
A dialog prompts for the new dataset name. The suggested name derives from the snapshot name.

Rolling Back

Reverts the dataset back to the point in time saved by the snapshot.

Rollback is a dangerous operation that causes any configured replication tasks to fail. Replications use the existing snapshot when doing an incremental backup, and rolling back can put the snapshots out of order. To restore the data within a snapshot, the recommended steps are:

  1. Clone the desired snapshot.

  2. Share the clone with the share type or service running on the TrueNAS system.

  3. Allow users to recover their needed data.

  4. Delete the clone from Storage > Pools.

This approach does not destroy any on-disk data and has no impact on replication.

TrueNAS asks for confirmation before rolling back to the chosen snapshot state. Clicking Yes reverts all dataset files to the state they were in at the time of snapshot creation.

Bulk Operations

To delete multiple snapshots, select the left column box for each snapshot to include. Click the Delete button that displays.

To search through the snapshots list by name, type a matching criteria into the Filter Snapshots text field. The list now displays only the snapshot names that match the filter text.

Browsing a Snapshot Collection

All dataset snapshots are accessible as an ordinary hierarchical file system, accessed from a hidden .zfs located at the root of every dataset.

A snapshot and any files it contains are not accessible or searchable if the snapshot mount path is longer than 88 characters. The data within the snapshot is safe but to make the snapshot accessible again shorten the mount path.

A user with permission to access the dataset contents can view the list of snapshots by going to the dataset .zfs directory from a share, like SMB, NFS, and iSCSI, or in the TrueNAS SCALE CLI. Users can browse and search any files they have permission to access throughout the entire dataset snapshot collection.

When creating a snapshot, permissions or ACLs set on files within that snapshot might limit access to the files. Snapshots are read-only, so users do not have permission to modify a snapshot or its files, even if they had write permissions when creating the snapshot.

From the Datasets screen, select the dataset and click Edit on the Dataset Details widget. Click Advanced Options and set Snapshot Directory to Visible.

To access snapshots:

  • Using a share, configure the client system to view hidden files. For example, in a Windows SMB share, enable Show hidden files, folders, and drives in Folder Options. From to the dataset root folder, open the .zfs directory and navigate to the snapshot.

  • Using the TrueNAS SCALE CLI, enter storage filesystem listdir path="/PATH/TO/DATASET/.zfs/PATH/TO/SNAPSHOT" to view snapshot contents. See also storage filesystem.

    Command Example
    storage filesystem listdir path="/mnt/tank/test/.zfs/snapshot/SNAPSHOT1"
    +--------------+-----------------------------------------------------+-----------------------------------------------------+-----------+--------+-------+-------+------+------+---------------+-----------+
    | name         | path                                                | realpath                                            | type      | size   | mode  | acl   | uid  | gid  | is_mountpoint | is_ctldir |
    +--------------+-----------------------------------------------------+-----------------------------------------------------+-----------+--------+-------+-------+------+------+---------------+-----------+
    | tuser        | /mnt/tank/test/.zfs/snapshot/SNAPSHOT1/tuser        | /mnt/tank/test/.zfs/snapshot/SNAPSHOT1/tuser        | DIRECTORY | 6      | 16832 | false | 3000 | 3000 | false         | true      |
    | FILENAME.tar | /mnt/tank/test/.zfs/snapshot/SNAPSHOT1/FILENAME.tar | /mnt/tank/test/.zfs/snapshot/SNAPSHOT1/FILENAME.tar | FILE      | 0      | 33200 | true  | 950  | 950  | false         | true      |
    | FILE.tar     | /mnt/tank/test/.zfs/snapshot/SNAPSHOT1/FILE.tar     | /mnt/tank/test/.zfs/snapshot/SNAPSHOT1/FILE.tar     | FILE      | 778240 | 33200 | true  | 950  | 950  | false         | true      |
    +--------------+-----------------------------------------------------+-----------------------------------------------------+-----------+--------+-------+-------+------+------+---------------+-----------+
    

A user with permission to access the hidden file can view and explore all snapshots for a dataset from the shell or the Sharing screen using services like SMB, NFS, and SFTP.