From 45fb90f651e74e86d9eb68faaf871abc9006a1a9 Mon Sep 17 00:00:00 2001 From: Jason Nance Date: Fri, 22 Dec 2017 09:48:47 -0600 Subject: [PATCH 01/11] Allow specifying UTC vs local timezone as program argument --- src/zfs-auto-snapshot.8 | 3 +++ src/zfs-auto-snapshot.sh | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/zfs-auto-snapshot.8 b/src/zfs-auto-snapshot.8 index 51fdc7f..cca428c 100644 --- a/src/zfs-auto-snapshot.8 +++ b/src/zfs-auto-snapshot.8 @@ -43,6 +43,9 @@ LAB is usually 'hourly', 'daily', or 'monthly'. \fB\-p\fR, \fB\-\-prefix\fR=\fIPRE\fR PRE is 'zfs\-auto\-snap' by default. .TP +\fB\-\-local\-tz\fR +Use system's local timezone instead of UTC in snapshot names. +.TP \fB\-q\fR, \fB\-\-quiet\fR Suppress warnings and notices at the console. .TP diff --git a/src/zfs-auto-snapshot.sh b/src/zfs-auto-snapshot.sh index 5ef5bae..dc5fef3 100755 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -65,6 +65,8 @@ print_usage () -k, --keep=NUM Keep NUM recent snapshots and destroy older snapshots. -l, --label=LAB LAB is usually 'hourly', 'daily', or 'monthly'. -p, --prefix=PRE PRE is 'zfs-auto-snap' by default. + --local-tz Use system's local timezone instead of UTC in snapshot + names. -q, --quiet Suppress warnings and notices at the console. --send-full=F Send zfs full backup. Unimplemented. --send-incr=F Send zfs incremental backup. Unimplemented. @@ -209,7 +211,7 @@ 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=event:,keep:,label:,prefix:,local-tz:,sep: \ --longoptions=debug,help,quiet,syslog,verbose \ --longoptions=pre-snapshot:,post-snapshot:,destroy-only \ --options=dnshe:l:k:p:rs:qgv \ @@ -286,6 +288,10 @@ do opt_prefix="$2" shift 2 ;; + (--local-tz) + opt_local_tz='1' + shift 1 + ;; (-q|--quiet) opt_debug='' opt_quiet='1' @@ -534,7 +540,14 @@ 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) +# If the --local-tz flag is set use the system's timezone. +# Otherwise, the default is to use UTC. +if [ -n $"opt_local_tz" ] +then + DATE=$(date +%F-%H%M) +else + DATE=$(date --utc +%F-%H%M) +fi # The snapshot name after the @ symbol. SNAPNAME="$opt_prefix${opt_label:+$opt_sep$opt_label}-$DATE" From 8fc645473e9e44a3c418ee277eefeb2d343118c3 Mon Sep 17 00:00:00 2001 From: Jason Nance Date: Wed, 27 Dec 2017 15:46:44 -0600 Subject: [PATCH 02/11] Fix longoption copypasta and move option to next line Fix $" typo --- 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 dc5fef3..cea8ad0 100755 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -211,8 +211,8 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...] GETOPT=$(getopt \ --longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \ - --longoptions=event:,keep:,label:,prefix:,local-tz:,sep: \ - --longoptions=debug,help,quiet,syslog,verbose \ + --longoptions=event:,keep:,label:,prefix:,sep: \ + --longoptions=local-tz,debug,help,quiet,syslog,verbose \ --longoptions=pre-snapshot:,post-snapshot:,destroy-only \ --options=dnshe:l:k:p:rs:qgv \ -- "$@" ) \ @@ -542,7 +542,7 @@ SNAPPROP="-o com.sun:auto-snapshot-desc='$opt_event'" # On Solaris %H%M expands to 12h34. # If the --local-tz flag is set use the system's timezone. # Otherwise, the default is to use UTC. -if [ -n $"opt_local_tz" ] +if [ -n "$opt_local_tz" ] then DATE=$(date +%F-%H%M) else From 3ded4dab067b44a22dd7d0c881a97f5e4ffd1292 Mon Sep 17 00:00:00 2001 From: Jason Nance Date: Tue, 13 Feb 2018 16:03:28 -0600 Subject: [PATCH 03/11] Set default for opt_local_tz --- src/zfs-auto-snapshot.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zfs-auto-snapshot.sh b/src/zfs-auto-snapshot.sh index cea8ad0..aef1d80 100755 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -42,6 +42,7 @@ opt_verbose='' opt_pre_snapshot='' opt_post_snapshot='' opt_do_snapshots=1 +opt_local_tz='' # Global summary statistics. DESTRUCTION_COUNT='0' From 65a0e5da9cdd6177f910255141d665e62e8c16df Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 09:59:41 -0700 Subject: [PATCH 04/11] Add shebang --- etc/zfs-auto-snapshot.cron.frequent | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/zfs-auto-snapshot.cron.frequent b/etc/zfs-auto-snapshot.cron.frequent index 613afc9..210d7dc 100644 --- a/etc/zfs-auto-snapshot.cron.frequent +++ b/etc/zfs-auto-snapshot.cron.frequent @@ -1,3 +1,5 @@ +#!/bin/sh + PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" */15 * * * * root which zfs-auto-snapshot > /dev/null || exit 0 ; zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 // From f522d3654b10000db0548e8081581e5e2fe7524a Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 10:00:08 -0700 Subject: [PATCH 05/11] Add PATH --- etc/zfs-auto-snapshot.cron.daily | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/zfs-auto-snapshot.cron.daily b/etc/zfs-auto-snapshot.cron.daily index 14fe006..3f9a5e7 100644 --- a/etc/zfs-auto-snapshot.cron.daily +++ b/etc/zfs-auto-snapshot.cron.daily @@ -1,5 +1,7 @@ #!/bin/sh +PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" + # Only call zfs-auto-snapshot if it's available which zfs-auto-snapshot > /dev/null || exit 0 From f1a6acf38b1d0f7d9abec63d1499f8bb22eecf5c Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 10:01:36 -0700 Subject: [PATCH 06/11] Added PATH, appropriate error code --- etc/zfs-auto-snapshot.cron.hourly | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etc/zfs-auto-snapshot.cron.hourly b/etc/zfs-auto-snapshot.cron.hourly index 5da52b1..b388b86 100644 --- a/etc/zfs-auto-snapshot.cron.hourly +++ b/etc/zfs-auto-snapshot.cron.hourly @@ -1,6 +1,8 @@ #!/bin/sh +PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" + # Only call zfs-auto-snapshot if it's available -which zfs-auto-snapshot > /dev/null || exit 0 +which zfs-auto-snapshot > /dev/null || exit 1 exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 // From bec89252fc9099e6b70268d61681a21cad884ea7 Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 10:01:55 -0700 Subject: [PATCH 07/11] Added appropriate error code --- etc/zfs-auto-snapshot.cron.daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/zfs-auto-snapshot.cron.daily b/etc/zfs-auto-snapshot.cron.daily index 3f9a5e7..d6e9361 100644 --- a/etc/zfs-auto-snapshot.cron.daily +++ b/etc/zfs-auto-snapshot.cron.daily @@ -3,6 +3,6 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" # Only call zfs-auto-snapshot if it's available -which zfs-auto-snapshot > /dev/null || exit 0 +which zfs-auto-snapshot > /dev/null || exit 1 exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 // From 6f1841dd0f2c67caf9160a52dc0da3b9a64efccb Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 10:04:17 -0700 Subject: [PATCH 08/11] Added exec --- etc/zfs-auto-snapshot.cron.frequent | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etc/zfs-auto-snapshot.cron.frequent b/etc/zfs-auto-snapshot.cron.frequent index 210d7dc..8a5c2de 100644 --- a/etc/zfs-auto-snapshot.cron.frequent +++ b/etc/zfs-auto-snapshot.cron.frequent @@ -2,4 +2,6 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" -*/15 * * * * root which zfs-auto-snapshot > /dev/null || exit 0 ; zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 // +*/15 * * * * root which zfs-auto-snapshot > /dev/null || exit 1 + +exec zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 // From 6bfc3332a75b8983fbbe5f9201fc9ac0fd7f6c73 Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 10:05:22 -0700 Subject: [PATCH 09/11] Added PATH, appropriate error code --- etc/zfs-auto-snapshot.cron.monthly | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etc/zfs-auto-snapshot.cron.monthly b/etc/zfs-auto-snapshot.cron.monthly index 2ab823f..1269916 100644 --- a/etc/zfs-auto-snapshot.cron.monthly +++ b/etc/zfs-auto-snapshot.cron.monthly @@ -1,6 +1,8 @@ #!/bin/sh +PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" + # Only call zfs-auto-snapshot if it's available -which zfs-auto-snapshot > /dev/null || exit 0 +which zfs-auto-snapshot > /dev/null || exit 1 exec zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 // From a0089f98ea8163c8118278e5c95c4e6c6f52efd6 Mon Sep 17 00:00:00 2001 From: grlcboi Date: Thu, 12 Jul 2018 10:06:00 -0700 Subject: [PATCH 10/11] Added PATH, appropriate error code --- etc/zfs-auto-snapshot.cron.weekly | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etc/zfs-auto-snapshot.cron.weekly b/etc/zfs-auto-snapshot.cron.weekly index 3aa977a..b087ce8 100644 --- a/etc/zfs-auto-snapshot.cron.weekly +++ b/etc/zfs-auto-snapshot.cron.weekly @@ -1,6 +1,8 @@ #!/bin/sh +PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" + # Only call zfs-auto-snapshot if it's available -which zfs-auto-snapshot > /dev/null || exit 0 +which zfs-auto-snapshot > /dev/null || exit 1 exec zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 // From ce72dbefa1e8ce1aaa771d85f90088581b1961ea Mon Sep 17 00:00:00 2001 From: root Date: Wed, 18 Jul 2018 23:31:13 -0700 Subject: [PATCH 11/11] use local tz --- etc/zfs-auto-snapshot.cron.daily | 2 +- etc/zfs-auto-snapshot.cron.frequent | 2 +- etc/zfs-auto-snapshot.cron.hourly | 2 +- etc/zfs-auto-snapshot.cron.monthly | 2 +- etc/zfs-auto-snapshot.cron.weekly | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/etc/zfs-auto-snapshot.cron.daily b/etc/zfs-auto-snapshot.cron.daily index d6e9361..d46e2b2 100644 --- a/etc/zfs-auto-snapshot.cron.daily +++ b/etc/zfs-auto-snapshot.cron.daily @@ -5,4 +5,4 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" # Only call zfs-auto-snapshot if it's available which zfs-auto-snapshot > /dev/null || exit 1 -exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 // +exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=32 --local-tz // diff --git a/etc/zfs-auto-snapshot.cron.frequent b/etc/zfs-auto-snapshot.cron.frequent index 8a5c2de..e1867c3 100644 --- a/etc/zfs-auto-snapshot.cron.frequent +++ b/etc/zfs-auto-snapshot.cron.frequent @@ -4,4 +4,4 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" */15 * * * * root which zfs-auto-snapshot > /dev/null || exit 1 -exec zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 // +exec zfs-auto-snapshot --quiet --syslog --label=frequent --keep=5 --local-tz // diff --git a/etc/zfs-auto-snapshot.cron.hourly b/etc/zfs-auto-snapshot.cron.hourly index b388b86..a5f96c0 100644 --- a/etc/zfs-auto-snapshot.cron.hourly +++ b/etc/zfs-auto-snapshot.cron.hourly @@ -5,4 +5,4 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" # Only call zfs-auto-snapshot if it's available which zfs-auto-snapshot > /dev/null || exit 1 -exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 // +exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=25 --local-tz // diff --git a/etc/zfs-auto-snapshot.cron.monthly b/etc/zfs-auto-snapshot.cron.monthly index 1269916..71ed091 100644 --- a/etc/zfs-auto-snapshot.cron.monthly +++ b/etc/zfs-auto-snapshot.cron.monthly @@ -5,4 +5,4 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" # Only call zfs-auto-snapshot if it's available which zfs-auto-snapshot > /dev/null || exit 1 -exec zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 // +exec zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 --local-tz // diff --git a/etc/zfs-auto-snapshot.cron.weekly b/etc/zfs-auto-snapshot.cron.weekly index b087ce8..c7a27de 100644 --- a/etc/zfs-auto-snapshot.cron.weekly +++ b/etc/zfs-auto-snapshot.cron.weekly @@ -5,4 +5,4 @@ PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" # Only call zfs-auto-snapshot if it's available which zfs-auto-snapshot > /dev/null || exit 1 -exec zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 // +exec zfs-auto-snapshot --quiet --syslog --label=weekly --keep=9 --local-tz //