Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude datasets with readonly=on if the --skip-readonly flag is set #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/zfs-auto-snapshot.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/zfs-auto-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ opt_sep='_'
opt_setauto=''
opt_syslog=''
opt_skip_scrub=''
opt_skip_readonly=''
opt_verbose=''
opt_pre_snapshot=''
opt_post_snapshot=''
Expand All @@ -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'.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down