Exclude ZFS filesystems from zfs-auto-snapshot on Ubuntu and remove them 2


Just ran into this quick blurb…

zfs set com.sun:auto-snapshot=false butank/DATA/backups

So I have backups running to a secondary storage ZFS pool in my server and today I realized my disk space was consumed by ZFS snapshots.  I thought, there’s no way even my backups are using that much data, even with rotations and archives.  Checking “zfs list -o space” confirmed it, there’s were hundreds of gigs used by snapshots.

Found a post by @dajhorn, one of the ZFS On Linux developers and Ubuntu package maintainers. He suggested that zfs  set command above to exclude ZFS filesystems from the zfs-auto-snapshot package/script on Ubuntu.

https://github.com/dajhorn/zfs-auto-snapshot/issues/7

Next… I needed to remove all those auto snapshots. Again, with the help of dajhorn I ended up with this script:

Pastebin here destroy-zfs-auto-snaps-for-fs.sh:
http://pastebin.com/3pLJZa2E

Below syntax is terrible, so use the Pastebin above.

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

#!/usr/bin/env bash
if [ -n "${1}" ]
then
 echo "This will *RECURSIVELY* destroy all ZFS auto snapshots (not your manually created snaps). "
 echo "Parent and child filesystem snapshots to be destroyed: ${1}"
 echo "Continue? (y/n)"
 read ANS
if [ $ANS == "y" ]
 then
 echo "Listing snapshots to be destroyed..."
 for ii in $(zfs list -r -t snapshot -o name ${1} | grep @zfs-auto-snap); do echo $ii; done
 echo "The above snapshots will be destroyed, sound like a plan? (y/n)"
 read PLAN
 if [ $PLAN == "y" ]
 then
 for ii in $(zfs list -r -t snapshot -o name ${1} | grep @zfs-auto-snap); do echo $ii; zfs destroy $ii; done
 echo "ZFS Auto snaps for ${1} destroyed!"
 else
 echo "Not a plan then... exiting."
 fi

 else
 echo "Not destroying... exit."
 fi
echo "Done."
else 
 echo "Exiting. You did not provide a ZFS filesystem. (destroy-zfs-auto-snaps-for-fs.sh zpool/some/fs)"
fi

 

Quick notes.  I did find an awesome one-liner here:
http://serverfault.com/questions/340837/how-to-delete-all-but-last-n-zfs-snapshots

But I didn’t want to leave any snapshots, just my preference. I wanted them all cleaned out.  Besides, its easy enough to quickly create a new recursive snapshot for the filesystem desired with “-r” switch.  Then with a custom name, they are not removed as part of the script above.

Happy ZFS-ing!