2424"
2525
2626# Set default program options.
27+ opt_date_format=' %F-%H%M'
2728opt_backup_full=' '
2829opt_backup_incremental=' '
2930opt_default_exclude=' '
@@ -56,6 +57,7 @@ print_usage ()
5657{
5758 echo " Usage: $0 [options] [-l label] <'//' | name [name...]>
5859 --default-exclude Exclude datasets if com.sun:auto-snapshot is unset.
60+ -D, --date=FORMAT Date format. Default '%F-%H%M'.
5961 -d, --debug Print debugging messages.
6062 -e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
6163 --fast Use a faster zfs list invocation.
@@ -144,6 +146,24 @@ do_run () # [argv]
144146}
145147
146148
149+ setup_snap_glob ()
150+ {
151+ local base=" $1 "
152+ local format=" $2 "
153+
154+ echo -n " $base "
155+ echo $format | \
156+ awk -v ORS=" " ' { gsub(/./,"&\n") ; print }' | \
157+ while read char; do
158+ if [ " $char " = " ." ]; then
159+ echo -n " ."
160+ else
161+ echo -n " ?"
162+ fi
163+ done
164+ }
165+
166+
147167do_snapshots () # properties, flags, snapname, oldglob, [targets...]
148168{
149169 local PROPS=" $1 "
@@ -210,9 +230,9 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
210230GETOPT=$( getopt \
211231 --longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \
212232 --longoptions=event:,keep:,label:,prefix:,sep: \
213- --longoptions=debug,help,quiet,syslog,verbose \
233+ --longoptions=date:, debug,help,quiet,syslog,verbose \
214234 --longoptions=pre-snapshot:,post-snapshot:,destroy-only \
215- --options=dnshe:l:k:p:rs:qgv \
235+ --options=D: dnshe:l:k:p:rs:qgv \
216236 -- " $@ " ) \
217237 || exit 128
218238
@@ -221,6 +241,10 @@ eval set -- "$GETOPT"
221241while [ " $# " -gt ' 0' ]
222242do
223243 case " $1 " in
244+ (-D|--date)
245+ opt_date_format=" $2 "
246+ shift 2
247+ ;;
224248 (-d|--debug)
225249 opt_debug=' 1'
226250 opt_quiet=' '
@@ -530,13 +554,13 @@ SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'"
530554
531555# ISO style date; fifteen characters: YYYY-MM-DD-HHMM
532556# On Solaris %H%M expands to 12h34.
533- DATE=$( date --utc +%F-%H%M )
557+ DATE=$( date --utc +" $opt_date_format " )
534558
535559# The snapshot name after the @ symbol.
536560SNAPNAME=" $opt_prefix ${opt_label: +$opt_sep$opt_label } -$DATE "
537561
538562# The expression for matching old snapshots. -YYYY-MM-DD-HHMM
539- SNAPGLOB=" $opt_prefix ${opt_label: +?$opt_label } ???????????????? "
563+ SNAPGLOB=" $( setup_snap_glob $ opt_prefix${opt_label: +?$opt_label } $opt_date_format ) "
540564
541565if [ -n " $opt_do_snapshots " ]
542566then
0 commit comments