Skip to content

Commit bf4e97b

Browse files
committed
Add a switch for the fast zfs list invocation.
Implement a `--fast` switch that uses the optimized `zfs list` invocation instead of the slower regular form. If the optimized form is generally better, then use it as the default and reverse the switch to `--slow` sometime later. Issue: #16
1 parent 53ad1dc commit bf4e97b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/zfs-auto-snapshot.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ opt_backup_incremental=''
2929
opt_default_exclude=''
3030
opt_dry_run=''
3131
opt_event='-'
32+
opt_fast_zfs_list=''
3233
opt_keep=''
3334
opt_label=''
3435
opt_prefix='zfs-auto-snap'
@@ -54,6 +55,7 @@ print_usage ()
5455
--default-exclude Exclude datasets if com.sun:auto-snapshot is unset.
5556
-d, --debug Print debugging messages.
5657
-e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
58+
--fast Use a faster zfs list invocation.
5759
-n, --dry-run Print actions without actually doing anything.
5860
-s, --skip-scrub Do not snapshot filesystems in scrubbing pools.
5961
-h, --help Print this usage message.
@@ -193,7 +195,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
193195
# {
194196

195197
GETOPT=$(getopt \
196-
--longoptions=default-exclude,dry-run,skip-scrub,recursive \
198+
--longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \
197199
--longoptions=event:,keep:,label:,prefix:,sep: \
198200
--longoptions=debug,help,quiet,syslog,verbose \
199201
--options=dnshe:l:k:p:rs:qgv \
@@ -226,6 +228,10 @@ do
226228
fi
227229
shift 2
228230
;;
231+
(--fast)
232+
opt_fast_zfs_list='1'
233+
shift 1
234+
;;
229235
(-n|--dry-run)
230236
opt_dry_run='1'
231237
shift 1
@@ -339,9 +345,14 @@ ZFS_LIST=$(env LC_ALL=C zfs list -H -t filesystem,volume -s name \
339345
-o name,com.sun:auto-snapshot,com.sun:auto-snapshot:"$opt_label") \
340346
|| { print_log error "zfs list $?: $ZFS_LIST"; exit 136; }
341347

342-
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -o name -s name|grep $opt_prefix |awk '{ print substr( $0, length($0) - 14, length($0) ) " " $0}' |sort -r -k1,1 -k2,2|awk '{ print substr( $0, 17, length($0) )}') \
343-
|| { print_log error "zfs list $?: $SNAPSHOTS_OLD"; exit 137; }
344-
348+
if [ -n "$opt_fast_zfs_list" ]
349+
then
350+
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -o name -s name|grep $opt_prefix |awk '{ print substr( $0, length($0) - 14, length($0) ) " " $0}' |sort -r -k1,1 -k2,2|awk '{ print substr( $0, 17, length($0) )}') \
351+
|| { print_log error "zfs list $?: $SNAPSHOTS_OLD"; exit 137; }
352+
else
353+
SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -S creation -o name) \
354+
|| { print_log error "zfs list $?: $SNAPSHOTS_OLD"; exit 137; }
355+
fi
345356

346357
# Verify that each argument is a filesystem or volume.
347358
for ii in "$@"

0 commit comments

Comments
 (0)