zfs-destroy-auto-snaps 976 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. # From http://pastebin.com/3pLJZa2E
  3. if [ -n "${1}" ]
  4. then
  5. echo "This will *RECURSIVELY* destroy all ZFS auto snapshots (not your manually created snaps). "
  6. echo "Parent and child filesystem snapshots to be destroyed: ${1}"
  7. echo "Continue? (y/n)"
  8. read ANS
  9. if [ $ANS == "y" ]
  10. then
  11. echo "Listing snapshots to be destroyed..."
  12. for ii in $(zfs list -r -t snapshot -o name ${1} | grep @zfs-auto-snap); do echo $ii; done
  13. echo "The above snapshots will be destroyed, sound like a plan? (y/n)"
  14. read PLAN
  15. if [ $PLAN == "y" ]
  16. then
  17. for ii in $(zfs list -r -t snapshot -o name ${1} | grep @zfs-auto-snap); do echo $ii; zfs destroy $ii; done
  18. echo "ZFS Auto snaps for ${1} destroyed!"
  19. else
  20. echo "Not a plan then... exiting."
  21. fi
  22. else
  23. echo "Not destroying... exit."
  24. fi
  25. echo "Done."
  26. else
  27. echo "Exiting. You did not provide a ZFS filesystem. (destroy-zfs-auto-snaps-for-fs.sh zpool/some/fs)"
  28. fi