$linuxjunkies
>

zfs-auto-snapshot(8)

Automatically create and manage ZFS snapshots on a configurable schedule.

UbuntuDebianFedoraArch

Synopsis

zfs-auto-snapshot [OPTION]... [FILESYSTEM|VOLUME|SNAPSHOT]...

Description

zfs-auto-snapshot is a shell script that automatically creates periodic snapshots of ZFS filesystems and volumes. It is typically run by cron at regular intervals (hourly, daily, weekly, monthly) and maintains a rolling set of snapshots by removing old ones based on configurable retention policies.

The command labels snapshots with a timestamp and frequency prefix (e.g., hourly-2024-01-15-14h30) and can be configured per-dataset using ZFS user properties to control snapshot frequency, retention count, and whether snapshots are taken recursively.

It integrates seamlessly with cron and systemd timers, and respects ZFS pool status, skipping snapshots if a pool is degraded or unavailable.

Common options

FlagWhat it does
-a, --autoTake snapshots of all datasets that have zfs-auto-snapshot:frequent, :hourly, :daily, :weekly, or :monthly properties set to 'true'
-r, --recursiveRecursively take snapshots of filesystem and all its children
-k, --keep NUMKeep NUM recent snapshots of each dataset and delete older ones (default: 24 for hourly, 7 for daily, 4 for weekly, 12 for monthly)
-f, --frequentCreate snapshots labeled 'frequent' (typically every 15 minutes)
-h, --hourlyCreate snapshots labeled 'hourly'
-d, --dailyCreate snapshots labeled 'daily'
-w, --weeklyCreate snapshots labeled 'weekly'
-m, --monthlyCreate snapshots labeled 'monthly'
-n, --dry-runPrint commands that would be executed without actually creating or destroying snapshots
-s, --syslogWrite log messages to syslog instead of stderr
-e, --eventUse this for backup events (experimental, affects retention behavior)
-p, --prefix STRINGUse custom snapshot name prefix instead of 'frequent', 'hourly', 'daily', etc.

Examples

Take daily snapshots of all datasets marked with zfs-auto-snapshot:daily=true property

zfs-auto-snapshot -a -d

Recursively take hourly snapshots of tank/home and all child datasets

zfs-auto-snapshot -r -h tank/home

Dry run: show what daily snapshots would be taken without actually creating them

zfs-auto-snapshot -n -a -d

Take hourly snapshots and keep the 48 most recent ones per dataset before pruning

zfs-auto-snapshot -a -h -k 48

Enable automatic daily snapshots for tank/data dataset (then use with -a -d)

zfs set zfs-auto-snapshot:daily=true tank/data

Take monthly snapshots of all marked datasets and log events to syslog

zfs-auto-snapshot -a -m -s

Take frequent snapshots of pool/vms recursively, keeping last 12 snapshots

zfs-auto-snapshot -r -f pool/vms -k 12

Cron entry to run hourly snapshots every hour on all marked datasets

0 * * * * zfs-auto-snapshot -a -h >/dev/null 2>&1

Related commands