Last active
April 21, 2024 17:01
-
-
Save meliber/b50b73c91a65475a12eb726caa9db176 to your computer and use it in GitHub Desktop.
zfsd -- zfs snapshot deletion
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 | |
# sample name of zfs snapshot | |
# pool/data/home@20240220 | |
# pool/sys/root@20240220 | |
zfsd() { | |
start=$1 | |
end=$2 | |
connector=$3 | |
for dataset in $(zfs list -H -o name); | |
do | |
if [ -z $end ] && [ -z $connector ];then | |
# delete snapshots of today if no args are given | |
if [ -z $start ];then | |
sudo zfs destroy "${dataset}@$(date +%Y%m%d)" 2>/dev/null | |
else | |
sudo zfs destroy "${dataset}@${start}" 2>/dev/null | |
fi | |
else | |
for ((i=$start; i<=$end; i++)); | |
do | |
sudo zfs destroy "${dataset}@${connector}${i}" 2>/dev/null | |
done | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment