ZFS, Bash, and Piped Loops

Fellow Linux Nutjobs! Here is your evening lesson in how to reclaim space from a ZFS partition by destroying snapshots. In my setup, my remote backup has a subset of the snapshots I’m automatically creating from my backup scripts. To reclaim space, I’m deleting those snapshots that have been backed up off-site.


Assume alias Zfs="sudo zfs" in the following example:

Zfs list -rHt snap tank/pictures \
| while read L ; do 
   [[ $L == "tank/pictures@20131008-191254"* ]] && break; 
   echo $L;
done \
| cut -d' ' -f1 \
| while read M ; do 
    Zfs destroy $M; 
done

Pop quiz. What other command could I use besides cut?

And guess what? I typed that command in almost one go, not pasted in from an editor. I’ve formatted it all fancy-like for your precious sanity.

Example of how Jed works his mojo.

Example of how Jed works his mojo.

Advertisements

One thought on “ZFS, Bash, and Piped Loops

  1. be maintained. ZFS snapshots are created very quickly, since all the data composing the snapshot is already stored; they are also space efficient, since any unchanged data is shared among the file system and its snapshots.

Comments are closed.