Skip to content

Commit dcea665

Browse files
committed
Add option --date=FORMAT to specify the date part in the snapshot name.
1 parent d5cb31a commit dcea665

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/zfs-auto-snapshot.8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ for those in which the user-property \fBcom.sun:auto-snapshot\fR is
1616
set to \fBfalse\fR. This option reverses the behavior and requires
1717
\fBcom.sun:auto-snapshot\fR to be set to \fBtrue\fR.
1818
.TP
19+
\fB\-D\fR, \fB\-\-date=\fIFORMAT\fR
20+
Use \fIformat\fR for snapshot name. See \fBdate\fR(1) for more information.
21+
.TP
1922
\fB\-d\fR, \fB\-\-debug\fR
2023
Print debugging messages.
2124
.TP

src/zfs-auto-snapshot.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ IFS="
2424
"
2525

2626
# Set default program options.
27+
opt_date_format='%F-%H%M'
2728
opt_backup_full=''
2829
opt_backup_incremental=''
2930
opt_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.
@@ -210,9 +212,9 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
210212
GETOPT=$(getopt \
211213
--longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \
212214
--longoptions=event:,keep:,label:,prefix:,sep: \
213-
--longoptions=debug,help,quiet,syslog,verbose \
215+
--longoptions=date:,debug,help,quiet,syslog,verbose \
214216
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
215-
--options=dnshe:l:k:p:rs:qgv \
217+
--options=D:dnshe:l:k:p:rs:qgv \
216218
-- "$@" ) \
217219
|| exit 128
218220

@@ -221,6 +223,10 @@ eval set -- "$GETOPT"
221223
while [ "$#" -gt '0' ]
222224
do
223225
case "$1" in
226+
(-D|--date)
227+
opt_date_format="$2"
228+
shift 2
229+
;;
224230
(-d|--debug)
225231
opt_debug='1'
226232
opt_quiet=''
@@ -530,7 +536,7 @@ SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'"
530536

531537
# ISO style date; fifteen characters: YYYY-MM-DD-HHMM
532538
# On Solaris %H%M expands to 12h34.
533-
DATE=$(date --utc +%F-%H%M)
539+
DATE=$(date --utc +"$opt_date_format")
534540

535541
# The snapshot name after the @ symbol.
536542
SNAPNAME="$opt_prefix${opt_label:+$opt_sep$opt_label}-$DATE"

0 commit comments

Comments
 (0)