From e9ddac48490859a577bef4b32f08d12a09e55710 Mon Sep 17 00:00:00 2001 From: Cory Albrecht Date: Sat, 23 Nov 2024 12:56:50 -0500 Subject: [PATCH 1/3] added local-time snapshot naming --- .gitignore | 1 + src/zfs-auto-snapshot.sh | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c2d30b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +zfs-auto-snapshot.code-workspace diff --git a/src/zfs-auto-snapshot.sh b/src/zfs-auto-snapshot.sh index cd88f0f..dbe18b0 100644 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -43,6 +43,7 @@ opt_pre_snapshot='' opt_post_snapshot='' opt_do_snapshots=1 opt_min_size=0 +opt_local=0 # Global summary statistics. DESTRUCTION_COUNT='0' @@ -65,6 +66,7 @@ print_usage () -h, --help Print this usage message. -k, --keep=NUM Keep NUM recent snapshots and destroy older snapshots. -l, --label=LAB LAB is usually 'hourly', 'daily', or 'monthly'. + -L, --local-time Use local time for snapshot names instead of UTC. -p, --prefix=PRE PRE is 'zfs-auto-snap' by default. -q, --quiet Suppress warnings and notices at the console. --send-full=F Send zfs full backup. Unimplemented. @@ -295,6 +297,10 @@ do opt_label="$2" shift 2 ;; + (-L|--local-time) + opt_local=1 + shift 1 + ;; (-m|--min-size) opt_min_size="$2" shift 2 @@ -585,7 +591,12 @@ 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. # We use the shortfirm -u here because --utc is not supported on macos. -DATE=$(date -u +%F-%H%M) +if [ $opt_local -eq 1] +then + DATE=$(date +%F-%H%M) +else + DATE=$(date -u +%F-%H%M) +fi # The snapshot name after the @ symbol. SNAPNAME="${opt_prefix:+$opt_prefix$opt_sep}${opt_label:+$opt_label}-$DATE" From 43b316d1eac526c55910ff77cad323d3a269eb82 Mon Sep 17 00:00:00 2001 From: Cory Albrecht Date: Sat, 23 Nov 2024 13:02:16 -0500 Subject: [PATCH 2/3] updated man page with new options --- src/zfs-auto-snapshot.8 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/zfs-auto-snapshot.8 b/src/zfs-auto-snapshot.8 index 87fc8b3..873e2e6 100644 --- a/src/zfs-auto-snapshot.8 +++ b/src/zfs-auto-snapshot.8 @@ -40,6 +40,9 @@ Keep NUM recent snapshots and destroy older snapshots. \fB\-l\fR, \fB\-\-label\fR=\fILAB\fR LAB is usually 'hourly', 'daily', or 'monthly'. .TP +\fB\-L\fR, \fB\-\-local\-time\fR +Use local time instead of UTC for snapshots. +.TP \fB\-p\fR, \fB\-\-prefix\fR=\fIPRE\fR PRE is 'zfs\-auto\-snap' by default. .TP From ff94a033d42b3567e08b8c1f0cb1174728f33b7b Mon Sep 17 00:00:00 2001 From: Cory Albrecht Date: Sat, 23 Nov 2024 13:29:24 -0500 Subject: [PATCH 3/3] more updates --- src/zfs-auto-snapshot.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zfs-auto-snapshot.sh b/src/zfs-auto-snapshot.sh index dbe18b0..cc3063e 100644 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -233,12 +233,12 @@ else fi GETOPT=$($GETOPT_BIN \ - --longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \ + --longoptions=default-exclude,dry-run,fast,local-time,skip-scrub,recursive \ --longoptions=event:,keep:,label:,prefix:,sep: \ --longoptions=debug,help,quiet,syslog,verbose \ --longoptions=pre-snapshot:,post-snapshot:,destroy-only \ --longoptions=min-size: \ - --options=dnshe:l:k:p:rs:qgvm: \ + --options=dnshe:l:Lk:p:rs:qgvm: \ -- "$@" ) \ || exit 128 @@ -591,7 +591,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. # We use the shortfirm -u here because --utc is not supported on macos. -if [ $opt_local -eq 1] +if [ $opt_local -eq 1 ] then DATE=$(date +%F-%H%M) else