make log file destination configurable

This commit is contained in:
2025-01-12 11:56:47 +01:00
parent a75604c097
commit 2833f12b1a
2 changed files with 12 additions and 2 deletions

View File

@@ -18,3 +18,6 @@ MAXBAK=3
# SSH key # SSH key
#SSH_KEY="~/.ssh/mykey_rsa" #SSH_KEY="~/.ssh/mykey_rsa"
# Logfile. Default: $CURDIR/backup.log
# LOG_FILE=/var/log/uberspace-backup.log

View File

@@ -15,6 +15,9 @@ set -Eeuo pipefail
# Set correct UTF-8 encoding (for FreeBSD jail) # Set correct UTF-8 encoding (for FreeBSD jail)
export LC_ALL=en_US.UTF-8 export LC_ALL=en_US.UTF-8
# Initialise variables
LOG_FILE=
CURDIR=$(dirname "$(readlink -f "$0")") CURDIR=$(dirname "$(readlink -f "$0")")
if [ ! -e "$CURDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi if [ ! -e "$CURDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
source "$CURDIR"/config.cfg source "$CURDIR"/config.cfg
@@ -29,9 +32,13 @@ else
SSH_KEY=~/.ssh/id_rsa SSH_KEY=~/.ssh/id_rsa
fi fi
if [ -z "${LOG_FILE}" ]; then
# defaults
LOG_FILE="$CURDIR"/backup.log
fi
# Get current date # Get current date
DATE=$(date +"%Y-%m-%d_%H-%M") DATE=$(date +"%Y-%m-%d_%H-%M")
LOG="$CURDIR"/backup.log
function trim { function trim {
sed -r -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' sed -r -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g'
@@ -43,7 +50,7 @@ function pdate {
function logecho { function logecho {
# Echo string and copy it to log while attaching the current date # Echo string and copy it to log while attaching the current date
echo "$(pdate) $*" echo "$(pdate) $*"
echo "$(pdate) $*" >> "$LOG" echo "$(pdate) $*" >> "$LOG_FILE"
} }
# Loop over all hosts # Loop over all hosts