Recursive removal of ZFS snapshots for given volume:
#!/bin/bash if [ "$1" == "" ]; then echo "You need to specify volume name, all snapshots will be recursively removed" exit 1 fi snapshots=`zfs list -H -o name -t snapshot -r $1` lines=`echo "$snapshots" | wc -l` for snapshot in $snapshots; do echo $snapshot done read -p "Removing $lines snapshots, write yes to continue: " if [ "$REPLY" != "yes" ]; then echo "Cancel snapshot removal." exit 1 fi i=1 for snapshot in $snapshots; do echo "$i / $lines: $snapshot" zfs destroy "$snapshot" i=$((i+1)) done exit 0
