Skip to content

Commit 5ce7a23

Browse files
committed
Implement the --event option for :auto-snap-desc.
Set the com.sun:auto-snap-desc property on each snapshot to an arbitrary value. On Solaris, this property is set to the dash character by default -- which is convention for NULL -- but it can contain an FMRI status comment or other user data.
1 parent 2e26499 commit 5ce7a23

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/zfs-auto-snapshot.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ opt_backup_full=''
2828
opt_backup_incremental=''
2929
opt_default_exclude=''
3030
opt_dry_run=''
31+
opt_event='-'
3132
opt_keep=''
3233
opt_label=''
3334
opt_prefix='zfs-auto-snap'
@@ -52,6 +53,7 @@ print_usage ()
5253
echo "Usage: $0 [options] [-l label] <'//' | name [name...]>
5354
--default-exclude Exclude objects if com.sun:auto-snapshot is unset.
5455
-d, --debug Print debugging messages.
56+
-e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
5557
-n, --dry-run Print actions without actually doing anything.
5658
-s, --skip-scrub Do not snapshot filesystems in scrubbing pools.
5759
-h, --help Print this usage message.
@@ -152,7 +154,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
152154

153155
for ii in $TARGETS
154156
do
155-
if do_run "zfs snapshot $PROPERTIES $FLAGS '$ii@$NAME'"
157+
if do_run "zfs snapshot $PROPS $FLAGS '$ii@$NAME'"
156158
then
157159
SNAPSHOT_COUNT=$(( $SNAPSHOT_COUNT + 1 ))
158160
else
@@ -192,9 +194,9 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
192194

193195
GETOPT=$(getopt \
194196
--longoptions=default-exclude,dry-run,skip-scrub,recursive \
195-
--longoptions=keep:,label:,prefix:,sep: \
197+
--longoptions=event:,keep:,label:,prefix:,sep: \
196198
--longoptions=debug,help,quiet,syslog,verbose \
197-
--options=dnshl:k:p:rs:qgv \
199+
--options=dnshe:l:k:p:rs:qgv \
198200
-- "$@" ) \
199201
|| exit 128
200202

@@ -213,6 +215,17 @@ do
213215
opt_default_exclude='1'
214216
shift 1
215217
;;
218+
(-e|--event)
219+
if [ "${#2}" -gt '1024' ]
220+
then
221+
print_log error "The $1 parameter must be less than 1025 characters."
222+
exit 139
223+
elif [ "${#2}" -gt '0' ]
224+
then
225+
opt_event="$2"
226+
fi
227+
shift 2
228+
;;
216229
(-n|--dry-run)
217230
opt_dry_run='1'
218231
shift 1
@@ -474,12 +487,9 @@ do
474487
TARGETS_RECURSIVE="${TARGETS_RECURSIVE:+$TARGETS_RECURSIVE }$ii" # nb: \t
475488
done
476489

477-
478-
# Linux lacks SMF and the notion of an FMRI event.
479-
FMRI_EVENT='-'
480-
481-
# Set this property because the SUNW program does.
482-
SNAPPROP="-o com.sun:auto-snapshot-desc='$FMRI_EVENT'"
490+
# Linux lacks SMF and the notion of an FMRI event, but always set this property
491+
# because the SUNW program does. The dash character is the default.
492+
SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'"
483493

484494
# ISO style date; fifteen characters: YYYY-MM-DD-HHMM
485495
# On Solaris %H%M expands to 12h34.

0 commit comments

Comments
 (0)