Last active
January 24, 2024 04:30
-
-
Save SkyWriter/58e36bfaa9eea1d36460 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
fsWithSnapshots=$(zfs list -Hr -t snapshot tank/share |grep '@' |cut -d '@' -f 1 |uniq) | |
for fs in $fsWithSnapshots ; do | |
# Changed to now sort newest to oldest. This will mean that newer snapshots without deltas will get removed. | |
emptySnapshot=$(zfs list -Hr -d1 -t snapshot -o name,used -S creation $fs |sed '$d' |awk ' $2 == "0B" { print $1 }' ) | |
for snapshot in $emptySnapshot ; do | |
# Added safety check. Verify the size of the snapshot prior to destroying it | |
used=$(zfs list -Hr -d1 -t snapshot -o used $snapshot) | |
if [[ $used != "0B" ]]; then | |
continue | |
fi | |
echo "Destroying empty snapshot $snapshot" | |
zfs destroy $snapshot | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/SkyWriter/58e36bfaa9eea1d36460?permalink_comment_id=3552336#gistcomment-3552336
jimsalterjrs/sanoid#616 (comment)
https://www.reddit.com/r/zfs/comments/ja1k7n/sanoid_dont_create_empty_0b_snapshots/