Remove all ZFS snapshots

Here’s a small bash script to destroy all existing zfs snapshots.

Run at your own risk!  :-)

#!/bin/bash
for snapshot in `zfs list -H -t snapshot | cut -f 1`
do
zfs destroy $snapshot
done

Last updated by .




Related posts:
  1. 10 steps to a Xen domU
  2. ZFS: The future of filesystems?



SysAdminMan provides virtual PBX hosting based on Asterisk and Freeswitch.
Avaialble systems include FreePBX, PBX-in-a-Flash, Elastix, A2Billing and FusionPBX.
More details and prices can be found at sysadminman.net


6 Comments

  1. slawko:

    Hi,
    It’s better to get rid of cut command:
    for snapshot in `zfs list -H -o name -t snapshot`
    (…)

    :)

  2. Anders:

    Well,

    zfs list -H -o name -t snapshot | xargs -n1 zfs destroy

    is even better :-)

  3. Luke Sheldrick:

    Nice. Ta

  4. hseldon:

    I found that when deleting snapshots from multiple shares this works okay:

    zfs list -H -o name -t snapshot|grep nameofzfsshare|pfexec xargs -n1 zfs destroy

  5. Mihai:

    while trying the same thing we came up with this line
    It helps to see what is going to be deleted

    zfs list -H -o name -t snapshot | grep | while read SNAPSHOT;do echo $SNAPSHOT; zfs destroy $SNAPSHOT;done

  6. Mihai:

    This is an edit because first post was truncated

    while trying the same thing we came up with this line
    It helps to see what is going to be deleted

    zfs list -H -o name -t snapshot | grep nameofsnapshot| while read SNAPSHOT;do echo $SNAPSHOT; zfs destroy $SNAPSHOT;done

Leave a comment