diff --git a/src/zfs-auto-snapshot.8 b/src/zfs-auto-snapshot.8 index 51fdc7f..cf16379 100644 --- a/src/zfs-auto-snapshot.8 +++ b/src/zfs-auto-snapshot.8 @@ -31,6 +31,9 @@ Print actions without actually doing anything. \fB\-s\fR, \fB\-\-skip\-scrub\fR Do not snapshot filesystems in scrubbing pools. .TP +\fB\-w\fR, \fB\-\-skip\-readonly\fR +Do not snapshot filesystems which are readonly. +.TP \fB\-h\fR, \fB\-\-help\fR Print the usage message. .TP diff --git a/src/zfs-auto-snapshot.sh b/src/zfs-auto-snapshot.sh index 5ef5bae..11b8b32 100755 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -38,6 +38,7 @@ opt_sep='_' opt_setauto='' opt_syslog='' opt_skip_scrub='' +opt_skip_readonly='' opt_verbose='' opt_pre_snapshot='' opt_post_snapshot='' @@ -61,6 +62,7 @@ print_usage () --fast Use a faster zfs list invocation. -n, --dry-run Print actions without actually doing anything. -s, --skip-scrub Do not snapshot filesystems in scrubbing pools. + -w, --skip-readonly Do not snapshot filesystems which are readonly. -h, --help Print this usage message. -k, --keep=NUM Keep NUM recent snapshots and destroy older snapshots. -l, --label=LAB LAB is usually 'hourly', 'daily', or 'monthly'. @@ -208,11 +210,11 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...] # { GETOPT=$(getopt \ - --longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \ + --longoptions=default-exclude,dry-run,fast,skip-scrub,skip-readonly,recursive \ --longoptions=event:,keep:,label:,prefix:,sep: \ --longoptions=debug,help,quiet,syslog,verbose \ --longoptions=pre-snapshot:,post-snapshot:,destroy-only \ - --options=dnshe:l:k:p:rs:qgv \ + --options=dnswhe:l:k:p:rs:qgv \ -- "$@" ) \ || exit 128 @@ -254,6 +256,10 @@ do opt_skip_scrub='1' shift 1 ;; + (-w|--skip-readonly) + opt_skip_readonly='1' + shift 1 + ;; (-h|--help) print_usage exit 0 @@ -482,6 +488,13 @@ do fi done + # Exclude datasets with readonly=on if the --skip-readonly flag is set. + if [ -n "$opt_skip_readonly" ] && [ "$(zfs get -H -o value readonly $ii)" = "on" ] + then + print_log debug "Excluding $ii because it is readonly." + continue + fi + for jj in $NOAUTO do # Ibid regarding iii.