Skip to content

Commit

Permalink
Add option --date=FORMAT to specify the date part in the snapshot name.
Browse files Browse the repository at this point in the history
  • Loading branch information
FransUrbo committed Apr 2, 2015
1 parent d5cb31a commit dcea665
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/zfs-auto-snapshot.8
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ for those in which the user-property \fBcom.sun:auto-snapshot\fR is
set to \fBfalse\fR. This option reverses the behavior and requires
\fBcom.sun:auto-snapshot\fR to be set to \fBtrue\fR.
.TP
\fB\-D\fR, \fB\-\-date=\fIFORMAT\fR
Use \fIformat\fR for snapshot name. See \fBdate\fR(1) for more information.
.TP
\fB\-d\fR, \fB\-\-debug\fR
Print debugging messages.
.TP
Expand Down
12 changes: 9 additions & 3 deletions src/zfs-auto-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ IFS="
"

# Set default program options.
opt_date_format='%F-%H%M'
opt_backup_full=''
opt_backup_incremental=''
opt_default_exclude=''
Expand Down Expand Up @@ -56,6 +57,7 @@ print_usage ()
{
echo "Usage: $0 [options] [-l label] <'//' | name [name...]>
--default-exclude Exclude datasets if com.sun:auto-snapshot is unset.
-D, --date=FORMAT Date format. Default '%F-%H%M'.
-d, --debug Print debugging messages.
-e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
--fast Use a faster zfs list invocation.
Expand Down Expand Up @@ -210,9 +212,9 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
GETOPT=$(getopt \
--longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \
--longoptions=event:,keep:,label:,prefix:,sep: \
--longoptions=debug,help,quiet,syslog,verbose \
--longoptions=date:,debug,help,quiet,syslog,verbose \
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
--options=dnshe:l:k:p:rs:qgv \
--options=D:dnshe:l:k:p:rs:qgv \
-- "$@" ) \
|| exit 128

Expand All @@ -221,6 +223,10 @@ eval set -- "$GETOPT"
while [ "$#" -gt '0' ]
do
case "$1" in
(-D|--date)
opt_date_format="$2"
shift 2
;;
(-d|--debug)
opt_debug='1'
opt_quiet=''
Expand Down Expand Up @@ -530,7 +536,7 @@ SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'"

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

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

0 comments on commit dcea665

Please sign in to comment.