24
24
"
25
25
26
26
# Set default program options.
27
+ opt_date_format=' %F-%H%M'
27
28
opt_backup_full=' '
28
29
opt_backup_incremental=' '
29
30
opt_default_exclude=' '
@@ -66,6 +67,7 @@ print_usage ()
66
67
{
67
68
echo " Usage: $0 [options] [-l label] <'//' | name [name...]>
68
69
--default-exclude Exclude datasets if com.sun:auto-snapshot is unset.
70
+ -D, --date=FORMAT Date format. Default '%F-%H%M'.
69
71
-d, --debug Print debugging messages.
70
72
-e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
71
73
--fast Use a faster zfs list invocation.
@@ -160,6 +162,45 @@ do_run () # [argv]
160
162
}
161
163
162
164
165
+ setup_snap_glob ()
166
+ {
167
+ local base=" $1 "
168
+ local format=" $2 "
169
+
170
+ # The dash to mimic the separator between prefix/label
171
+ # and DATE in SNAPNAME.
172
+ echo -n " $base " -
173
+ echo $format | \
174
+ awk -v ORS=" " ' { gsub(/./,"&\n") ; print }' | \
175
+ while read char; do
176
+ [ " $char " = " %" ] && continue
177
+
178
+ if [ " $char " = " ." ]; then
179
+ echo -n " ."
180
+ elif [ " $char " = " -" ]; then
181
+ echo -n " -"
182
+ else
183
+ # Given the format char, create
184
+ # a string with only that.
185
+ # So if we said '%Y', the percentage
186
+ # sign would have been filtered out
187
+ # at the top of the loop, leaving the
188
+ # 'Y' here. So str=2014.
189
+ str=$( date +" %$char " )
190
+
191
+ # Print the lenght of that with
192
+ # question marks (4 with the '%Y'
193
+ # example above).
194
+ i=0
195
+ while [ $i -lt ${# str} ]; do
196
+ echo -n " ?"
197
+ i=$(( i + 1 ))
198
+ done
199
+ fi
200
+ done
201
+ }
202
+
203
+
163
204
do_snapshots () # properties, flags, snapname, oldglob, [targets...]
164
205
{
165
206
local PROPS=" $1 "
@@ -335,12 +376,12 @@ $jj"
335
376
GETOPT=$( getopt \
336
377
--longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \
337
378
--longoptions=event:,keep:,label:,prefix:,sep: \
338
- --longoptions=debug,help,quiet,syslog,verbose \
379
+ --longoptions=date:, debug,help,quiet,syslog,verbose \
339
380
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
340
381
--longoptions=send-full:,send-incr:,send-opts:,recv-opts: \
341
382
--longoptions=send-ssh-opts:,send-mbuf-opts:,pre-send:,post-send: \
342
383
--longoptions=send-fallback \
343
- --options=dnshe:l:k:p:rs:qgv \
384
+ --options=D: dnshe:l:k:p:rs:qgv \
344
385
-- " $@ " ) \
345
386
|| exit 128
346
387
@@ -349,6 +390,10 @@ eval set -- "$GETOPT"
349
390
while [ " $# " -gt ' 0' ]
350
391
do
351
392
case " $1 " in
393
+ (-D|--date)
394
+ opt_date_format=" $2 "
395
+ shift 2
396
+ ;;
352
397
(-d|--debug)
353
398
opt_debug=' 1'
354
399
opt_quiet=' '
@@ -702,13 +747,13 @@ SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'"
702
747
703
748
# ISO style date; fifteen characters: YYYY-MM-DD-HHMM
704
749
# On Solaris %H%M expands to 12h34.
705
- DATE=$( date --utc +%F-%H%M )
750
+ DATE=$( date --utc +" $opt_date_format " )
706
751
707
752
# The snapshot name after the @ symbol.
708
753
SNAPNAME=" $opt_prefix ${opt_label: +$opt_sep$opt_label } -$DATE "
709
754
710
- # The expression for matching old snapshots. -YYYY-MM-DD-HHMM
711
- SNAPGLOB=" $opt_prefix ${opt_label: +?$opt_label } ???????????????? "
755
+ # The expression for matching old snapshots.
756
+ SNAPGLOB=" $( setup_snap_glob $ opt_prefix${opt_label: +?$opt_label } $opt_date_format ) "
712
757
713
758
if [ -n " $opt_do_snapshots " ]
714
759
then
0 commit comments