You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
Dave Eddy 1b51381cc4
add -V
4 years ago
man add manpage 4 years ago add changelog 4 years ago
LICENSE add LICENSE 4 years ago
Makefile add Makefile 4 years ago add -V 4 years ago
zfs-snapshot-all add -V 4 years ago

ZFS Snapshot All

Recursively snapshot all zpools


Snapshot all zpools with the prefix "foo"

# ./zfs-snapshot-all foo
zfs snapshot -r goliath@foo_1448256528
zfs snapshot -r zones@foo_1448256528

Snapshot all zpools with the prefix "bar" without actually executing any snapshot commands (dry-run)

# ./zfs-snapshot-all -n bar
zfs snapshot -r goliath@bar_1448256538 # dry-run: no action taken
zfs snapshot -r zones@bar_1448256538 # dry-run: no action taken

Snapshot the pools given as arguments, "goliath", "zones", and "fake" with the prefix "foo"

# ./zfs-snapshot-all foo goliath zones fake
zfs snapshot -r goliath@foo_1448256549
zfs snapshot -r zones@foo_1448256549
zfs snapshot -r fake@foo_1448256549
cannot open 'fake': dataset does not exist
# echo $?

This script can be best used with cron for automated snapshots

1 0 * * * /opt/custom/bin/zfs-snapshot-all automated_daily   >> /var/log/autosnap.log 2>&1
2 0 * * 0 /opt/custom/bin/zfs-snapshot-all automated_weekly  >> /var/log/autosnap.log 2>&1
3 0 1 * * /opt/custom/bin/zfs-snapshot-all automated_monthly >> /var/log/autosnap.log 2>&1
4 0 1 1 * /opt/custom/bin/zfs-snapshot-all automated_yearly  >> /var/log/autosnap.log 2>&1

And then zfs-prune-snapshots can be used to cleanup snapshots as they get too old... for example

11 0 * * * /opt/custom/bin/zfs-prune-snapshots -p automated_daily_   7d   >> /var/log/autosnap.log 2>&1
12 0 * * 0 /opt/custom/bin/zfs-prune-snapshots -p automated_weekly_  4w   >> /var/log/autosnap.log 2>&1
13 0 1 * * /opt/custom/bin/zfs-prune-snapshots -p automated_monthly_ 12M  >> /var/log/autosnap.log 2>&1
14 0 1 1 * /opt/custom/bin/zfs-prune-snapshots -p automated_yearly_  10y  >> /var/log/autosnap.log 2>&1


usage: zfs-snapshot-all [-hnx] <name> [[pool1] pool2 ...]

recursively snapshot all zpools

    # zfs-snapshot-all foo
    snapshot all zpools with the prefix foo

    # zfs-snapshot-all bar pool1 pool2
    snapshot zpools pool1 and pool2 with the prefix bar

    # zfs-snapshot-all -x baz pool3
    snapshot zpool pool3 with the *exact* snapshot name 'baz'

    -h             print this message and exit
    -n             dry-run, don't actually create snapshots
    -x             don't automatically append the date in epoch to
                   the snapshot name
    -V             print the version number and exit

Development Notes


shellcheck is used to check bash style. Use make check to run the style checker:

$ make check
awk 'length($0) > 80 { exit(1); }' zfs-snapshot-all
shellcheck zfs-snapshot-all

Bash style guide:


Use make man to regenerate the manpage:

$ make man
md2man-roff man/ > man/zfs-snapshot-all.1
$ ./man/zfs-snapshot-all.1
<man page opens>

Manpages are generated with md2man which requires ruby-devel to be installed. Once ruby is installed, md2man can be installed locally with:

$ gem install --user-install md2man


MIT License