Recursive removal of ZFS snapshots

Recursive removal of ZFS snapshots for given volume:


if [ "$1" == "" ]; then
 echo "You need to specify volume name, all snapshots will be recursively removed"
 exit 1

snapshots=`zfs list -H -o name -t snapshot -r $1`
lines=`echo "$snapshots" | wc -l`

for snapshot in $snapshots; do
 echo $snapshot
read -p "Removing $lines snapshots, write yes to continue: "
if [ "$REPLY" != "yes" ]; then
 echo "Cancel snapshot removal."
 exit 1

for snapshot in $snapshots; do
 echo "$i / $lines: $snapshot"
 zfs destroy "$snapshot"

exit 0


One Comment

  1. because they no longer exist on the sending side, you might consider using the snapshots hold feature. Holding a snapshot prevents it from being destroyed. In addition, this feature allows a snapshot with clones to be deleted pending the removal of the last clone by using the

Leave a Reply

Your email address will not be published. Required fields are marked *