I’m using zfs snapshots to save all non global zones filesystems via cron. This can be achieved using the zfs snapshot option “-r”. During snapshot creation this means
create snapshots on the target filesystem and all descendants filesystems
If made a mistake and you want to rollback the last action you will be disappointed that the corresponding “-r” option of the zfs rollback command has a different meaning:
destroy snapshots newer than the specified snapshot
All posts in the internet that I found show that there is no way to make a recursiv rollback with just using zfs. A small shell script can help to make recursiv rollbacks:
# Dr. Martin Menzel
# Dr. Menzel IT - www.dr-menzel-it.de
# Use at your own risk. No warranty. No fee.
# parameter list:
# (1) the filesystem to be used to start decendant recursion
# example: apool/zones/webzone
# (2) the snapshot to which the filesystems should be rolled back
# example: @2013-07-21-083500
for snap in `zfs list -H -t snapshot -r $1 | grep "$2" | cut -f 1`; do
# -r : also destroys the snapshots newer than the specified one
# -R : also destroys the snapshots newer than the one specified and their clones
# -f : forces an unmount of any clone file systems that are to be destroyed
echo -n "rolling back to [$snap] : ";zfs rollback -r -R -f $snap; echo " Done."
Of course you have to make the file executable after copying it to your system with a command like
chmod 755 zfs-recursive-rollback.sh
You should also adapt the command line options in the script to your needs if the options in the script do not fit.