12 thoughts on “Remove all ZFS snapshots

  1. slawko

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

    🙂

  2. 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

  3. 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

  4. 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

  5. likewhoa

    @Mihai your command is using while the wrong way.

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

  6. Jin Chang

    A quick one liner to delete all snapshots but keep the latest 3 (for BSD without GNU head command that linux gets):

    zfs list -o name -t snapshot |tail +2 |sed ‘$d’|sed ‘$d’|sed ‘$d’|xargs -n1 zfs destroy

    If anyone knows a better way to do this with sed I would love to know.

  7. Pingback: Blow away ZFS snapshots and watch the progress | Technicus

  8. Andy Mason

    Stolen from elsewhere:

    To delete all snapshots:
    zfs destroy -rv [email protected]%

    You can test first with -rnv

    Jin: nice, but keeping 30 is still a pain 🙂 Wish we had head -n -30.

  9. Dasha

    Hi matt,
    Thanks before. But, can you help to find how to remove only the old snapshot script for Ubuntu?
    And the script will be running on cron every day.

Comments are closed.