Created
September 18, 2017 19:19
-
-
Save paulhandy/45571e2077df83829fcc6dac1cfedd1a to your computer and use it in GitHub Desktop.
Clean up old zfs snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://serverfault.com/questions/340837/how-to-delete-all-but-last-n-zfs-snapshots#340846 | |
You may find something like this a little simpler | |
zfs list -t snapshot -o name | grep ^tank@Auto | tac | tail -n +16 | xargs -n 1 zfs destroy -r | |
output the list of snapshot (names only) with zfs list -t snaphot -o name | |
filter to keep only the ones that match tank@Auto with grep ^tank@Auto | |
reverse the list (previously sorted from oldest to newest) with tac | |
limit output to the 16th oldest result and following with tail -n +16 | |
then destroy with xargs -n 1 zfs destroy -vr | |
deleting snapshots in reverse order is supposedly more efficient. | |
or sort in reverse order of creation | |
zfs list -t snapshot -o name -S creation | grep ^tank@Auto | tail -n +16 | xargs -n 1 zfs destroy -vr | |
Test it with ...|xargs -n 1 echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment