Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4742f2a

Browse files
committed
Improve how we get list of old snapshots
1. Add ordering by `creation` time (desc)2. Do not filter out `NAME`, use `-H` instead.
1 parent3537b7e commit4742f2a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

‎scripts/delete_old_zfs_snapshots.sh‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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
#
@@ -19,12 +19,11 @@ n=$1
1919
if [[-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)."
2121
else
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
2726
fi
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"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp