LinuxCommandLibrary

mkzftree

Create a compressed ZFS filesystem archive

SYNOPSIS

mkzftree [ -a ] [ -l ] [ -s ] [ -v ] [ -t ] [ -h | --help ]
<target_directory>

PARAMETERS

<target_directory>
    The path to the root directory where the ZFS dataset tree will be created. This directory must be writable by the user running the command.

-a
    Include all ZFS datasets, not just those with the 'zfs-auto-snapshot:enabled' property set to 'true'.

-l
    List the ZFS datasets and snapshots that would be processed, but do not actually create any files or directories (dry-run for listing).

-s
    Create symbolic links to the ZFS snapshots instead of hard links or copies. This saves disk space on the target filesystem if it's not ZFS, but might not work on all filesystems or may not be suitable for all backup scenarios.

-v
    Enable verbose output, showing more details about the datasets and snapshots being processed.

-t
    Perform a test run without making any actual changes to the filesystem. This is a general dry-run option.

-h, --help
    Display a help message and exit.

DESCRIPTION

mkzftree is a utility script designed to make ZFS datasets and their snapshots accessible to traditional Unix tools like rsync, tar, or cp. It does this by creating a conventional directory hierarchy in a specified target location that mirrors the structure of ZFS pools, datasets, and their snapshots.

Ordinarily, ZFS snapshots are internal to the ZFS filesystem and not directly navigable as standard directories. mkzftree bridges this gap by creating special "tree" directories (typically in a non-ZFS filesystem, or another ZFS dataset if desired) where each dataset appears as a directory, and its snapshots appear as subdirectories within an "@snapshots" folder.

This allows for seamless traversal and backup of ZFS snapshots using tools that do not natively understand ZFS. It's commonly used in conjunction with zfs-auto-snapshot to facilitate automated, incremental backups of ZFS data to remote locations or other storage mediums.

CAVEATS

mkzftree is a helper script and not a core ZFS utility; it relies on the presence and proper functioning of the underlying zfs command.

The user executing mkzftree must have sufficient permissions to read ZFS dataset information and write to the specified <target_directory>.

If the -s (symlink) option is not used, and the target filesystem is not ZFS (which natively handles snapshots efficiently), creating hard links or copies for large numbers of snapshots can consume significant disk space. Performance can also be impacted on very large ZFS pools with extensive snapshot histories due to the overhead of listing and processing each snapshot.

TYPICAL USAGE

After running mkzftree /path/to/snapshot_tree, you can use standard tools to back up the contents. For instance, to rsync snapshots to a remote server:
rsync -a -H --delete /path/to/snapshot_tree/ /mnt/backup_target/
This command would copy the latest data and relevant snapshots to the backup destination, handling changes incrementally.

TREE STRUCTURE

The structure created by mkzftree typically looks like this:
<target_directory>/
├── pool/dataset_A/
│ └── @snapshots/
│ ├── hourly-2023-10-27_10.00/
│ └── daily-2023-10-26_00.00/
└── pool/dataset_B/
└── @snapshots/
└── weekly-2023-10-23_00.00/
Each directory within the @snapshots folder represents a specific ZFS snapshot, allowing its contents to be accessed as if it were a regular directory.

HISTORY

mkzftree originated as a component of the zfs-auto-snapshot project, a popular tool for automating ZFS snapshot creation and retention. Its development was driven by the need to bridge the gap between ZFS's powerful snapshot capabilities and the traditional Unix toolchain (like rsync and tar) that lacks native ZFS understanding. By providing a filesystem-like representation of snapshots, mkzftree enabled easier, more robust backup and replication strategies for ZFS users.

SEE ALSO

zfs(8), rsync(1), tar(1), cp(1), zfs-auto-snapshot(8)

Copied to clipboard