gregthegeek

destroy-zfs-auto-snaps-for-fs.sh

Nov 24th, 2012
607
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  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.  
  10.     if [ $ANS == "y" ]
  11.     then
  12.         echo "Listing snapshots to be destroyed..."
  13.         for ii in $(zfs list -r -t snapshot -o name ${1} | grep @zfs-auto-snap); do echo $ii; done
  14.         echo "The above snapshots will be destroyed, sound like a plan? (y/n)"
  15.         read PLAN
  16.         if [ $PLAN == "y" ]
  17.         then
  18.             for ii in $(zfs list -r -t snapshot -o name ${1} | grep @zfs-auto-snap); do echo $ii; zfs destroy $ii; done
  19.             echo "ZFS Auto snaps for ${1} destroyed!"
  20.         else
  21.             echo "Not a plan then... exiting."
  22.         fi
  23.        
  24.     else
  25.         echo "Not destroying... exit."
  26.     fi
  27.    
  28.     echo "Done."
  29. else
  30.     echo "Exiting. You did not provide a ZFS filesystem.  (destroy-zfs-auto-snaps-for-fs.sh zpool/some/fs)"
  31. fi
RAW Paste Data