File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change 55# on the machine, except:
66# - the last $1 snapshots (the first parameter in the CLI call),
77# - those snapthots that are used now,
8- # - snapshots having "clone" or "NAME" in the name (however, they are supposed to be
8+ # - snapshots having "clone" in the name (however, they are supposed to be
99# dependant; so with old 'main' snapshots, dependant ones will be deleted as well,
1010# thanks to '-R' option when calling 'zfs destroy').
1111#
1919if [[ -z " $n " ]]; then
2020 echo " Specify the number of snapshots to keep (Example: 'bash ./scripts/delete_old_zfs_snapshots.sh 5' to delete all but last 5 snapshots)."
2121else
22- sudo zfs list -t snapshot -o name \
22+ sudo zfs list -t snapshot -o name -s creation -H \
2323 | grep -v clone \
24- | grep -v NAME \
2524 | head -n -$n \
2625 | xargs -n1 --no-run-if-empty sudo zfs destroy -R
2726fi
2827
2928# # An example of crontab entry, setting up auto-deletion of all unused ZFS snapshots except the last 3 ones.
30- # # 0 6 * * * sudo zfs list -t snapshot -o name | grep -v clone | grep -v NAME | head -n -3 | xargs -n1 --no-run-if-empty sudo zfs destroy -R 2>&1 | logger --stderr --tag "cleanup_zfs_snapshot"
29+ # # 0 6 * * * sudo zfs list -t snapshot -o name -s creation -H | grep -v clone | grep -v NAME | head -n -3 | xargs -n1 --no-run-if-empty sudo zfs destroy -R 2>&1 | logger --stderr --tag "cleanup_zfs_snapshot"
You can’t perform that action at this time.
0 commit comments