zfs-destroy-auto-snaps 1.1 KB

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