From 6727b6832b940743e28750fc7b89e0e7ffc20520 Mon Sep 17 00:00:00 2001 From: Alexandru Ghitza Date: Tue, 29 Nov 2016 11:03:05 +1100 Subject: [PATCH] Add option to use local time instead of UTC Closes #17, closes #18. --- README.md | 1 - acts | 11 ++++++++++- acts.conf.sample | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf8d4da..cae115e 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ Notes on behaviour: - Keep the most recent 12 monthly backups, and delete any older ones. - Do not delete any yearly backups. -- Times in archive names use UTC, not the server's timezone. TODO ---- diff --git a/acts b/acts index 5cd1613..1fb9286 100755 --- a/acts +++ b/acts @@ -71,6 +71,7 @@ fi # Use default values if anything is not set verbose="${verbose=0}" hostname="${hostname=$(hostname -s)}" +uselocaltime="${uselocaltime=0}" backuptargets="${backuptargets=}" prebackupscript="${prebackupscript=}" postbackupscript="${postbackupscript=}" @@ -84,6 +85,14 @@ if [ -z "$backuptargets" ] ; then die "config-error message=\"\$backuptargets is not set in acts.conf.\"" fi +if [ "$uselocaltime" = 0 ] ; then + utc="-u" +elif [ "$uselocaltime" = 1 ] ; then + utc="" +else + die "config-error message=\"invalid \$uselocaltime in acts.conf; valid options are 0 (for UTC) or 1 (for local time).\"" +fi + # Create the lock. mkdir is atomic test/set, so use that instead of the typical test -f/touch combo if [ -d "$lockfile" ] ; then die "acts-error message=\"$lockfile exists referencing PID $(cat "$lockfile/pid" 2>/dev/null || echo ""). Hint: If acts is not already running, rm -rf $lockfile.\"" @@ -108,7 +117,7 @@ archives=$(echo "$archives_unsorted" | sort -n) # When is now? # Instead of re-running date, be paranoid the day was microseconds away from ending -today=$(date -u "+%Y-%m-%d_%H:%M:%S") +today=$(date "$utc" "+%Y-%m-%d_%H:%M:%S") year=$(echo "$today" | cut -d_ -f1 | cut -d- -f1) month=$(echo "$today" | cut -d_ -f1 | cut -d- -f2) # day=$(echo "$today" | cut -d_ -f1 | cut -d- -f3) # unused diff --git a/acts.conf.sample b/acts.conf.sample index 043b472..872bfc0 100644 --- a/acts.conf.sample +++ b/acts.conf.sample @@ -29,6 +29,11 @@ verbose=1 # Default: $(hostname -s) #hostname=$(hostname) +# uselocaltime +# Use local time instead of UTC for the archive date and timestamps. +# Default: 0 (i.e. use UTC) +#uselocaltime=1 + # prebackupscript # This script is run before backups are created. Make sure it's executable. # Default: unset