|
5 | 5 | # on the machine, except: |
6 | 6 | # - the last $1 snapshots (the first parameter in the CLI call), |
7 | 7 | # - 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 |
9 | 9 | # dependant; so with old 'main' snapshots, dependant ones will be deleted as well, |
10 | 10 | # thanks to '-R' option when calling 'zfs destroy'). |
11 | 11 | # |
|
19 | 19 | if [[-z"$n" ]];then |
20 | 20 | echo"Specify the number of snapshots to keep (Example: 'bash ./scripts/delete_old_zfs_snapshots.sh 5' to delete all but last 5 snapshots)." |
21 | 21 | else |
22 | | - sudo zfs list -t snapshot -o name \ |
| 22 | + sudo zfs list -t snapshot -o name-s creation -H\ |
23 | 23 | | grep -v clone \ |
24 | | -| grep -v NAME \ |
25 | 24 | | head -n -$n \ |
26 | 25 | | xargs -n1 --no-run-if-empty sudo zfs destroy -R |
27 | 26 | fi |
28 | 27 |
|
29 | 28 | ## 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" |