Compare commits

...

6 Commits

Author SHA1 Message Date
Asif Bacchus 2b66d9e118 check if exclusion list has been specified 2019-05-27 03:17:08 -06:00
Asif Bacchus d7a8d0ce28 add include/exclude flag vars 2019-05-27 03:13:48 -06:00
Asif Bacchus 163bcd2a84 read file listing extra locations to backup 2019-05-27 03:10:23 -06:00
Asif Bacchus 4a83cdb755 noted new error codes 2019-05-27 03:09:21 -06:00
Asif Bacchus b95981e4bb func badDetails for missing or invalid details 2019-05-27 03:08:54 -06:00
Asif Bacchus 68a51bf3c5 check borg vars and export env vars 2019-05-27 03:08:21 -06:00
1 changed files with 98 additions and 1 deletions

View File

@ -17,6 +17,15 @@ mag=$(tput setaf 5)
### functions
# bad configuration value passed in details file
badDetails () {
if [ "$1" = "empty" ]; then
exitError 130 "details:${2} cannot be NULL (undefined)"
elif [ "$1" = "dne" ]; then
exitError 131 "details:${2} file or directory does not exist."
fi
}
# bad parameter passed to script
badParam () {
if [ "$1" = "dne" ]; then
@ -128,6 +137,8 @@ borgPruneParams='--list'
configDetails="$scriptPath/seafbackup.details"
err503Copied=0
sqlCopied=0
includeXtra=0
exclusions=0
# 503 related
use503=0
@ -401,6 +412,90 @@ printf "${ok}[%s] -- [SUCCESS] SQL databases dumped successfully --${norm}\n" \
"$(stamp)" >> "$logFile"
### pre-backup tasks completed -- move to borg tasks
printf "${cyan}[%s] -- [INFO] Pre-backup tasks completed --${norm}\n" \
"$(stamp)" >> "$logFile"
### Run borg variable checks
printf "${cyan}[%s] -- [INFO] Verifying supplied borg details --${norm}\n" \
"$(stamp)" >> "$logFile"
## verify borg base directory
if [ -z "${borgBaseDir}" ]; then
badDetails empty 'borgBaseDir'
elif [ ! -d "${borgBaseDir}" ]; then
badDetails dne 'borgBaseDir'
fi
printf "${magenta}details:borgBaseDir ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile"
export BORG_BASE_DIR="${borgBaseDir%/}"
## check path to SSH keyfile
if [ -z "${borgSSHKey}" ]; then
badDetails empty 'borgSSHKey'
elif [ ! -d "${borgSSHKey}" ]; then
badDetails dne 'borgSSHKey'
fi
printf "${magenta}details:borgSSHKey ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile"
export BORG_RSH="ssh -i ${borgSSHKey}"
## check borg repo connect string
if [ -z "${borgConnectRepo}" ]; then
badDetails empty 'borgConnectRepo'
fi
printf "${magenta}details:borgConnectRepo ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile"
export BORG_REPO="${borgConnectRepo}"
## check borg repo password
if [ -n "${borgRepoPassphrase}" ]; then
printf "${magenta}details:borgRepoPassphrase ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile"
export BORG_PASSPHRASE="${borgRepoPassphrase}"
else
# if passwd is blank intentionally, this is insecure
printf "${warn} -- [WARNING] Using a borg repo without a password is an " \
>> "$logFile"
printf "insecure configuration --${norm}\n" >> "$logFile"
# if this was an accident, we need to provide a bogus passwd so borg fails
# otherwise it will sit forever just waiting for input
export BORG_PASSPHRASE="DummyPasswordSoBorgFails"
fi
## read additional files
if [ -n "${borgXtraListPath}" ]; then
# check if file actually exists
if [ ! -f "${borgXtraListPath}" ]; then
badDetails dne 'borgXtraListPath'
fi
# read file contents into concatenated list for echo to cmdline
while read -r xtraItem; do
if [ -z "${xtraList}" ]; then
xtraList="${xtraItem}"
else
xtraList="${xtraList} ${xtraItem}"
fi
done <<EOF
$( sed -e '/^\s*#.*$/d' -e '/^\s*$/d' "${borgXtraListPath}" )
EOF
printf "${magenta}details:borgXtraListPath ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile"
includeXtra=1
fi
## check if exlusion list file is specified
if [ -n "${borgExcludeListPath}" ]; then
# check if the file actually exists
if [ ! -f "${borgExcludeListPath}" ]; then
badDetails dne 'borgExcludeListPath'
fi
exclusions=1
fi
@ -417,4 +512,6 @@ exit 0
# 111: could not create tmp dir for SQL dump files
# 115: could not dump CCNET-DB
# 116: could not dump SEAFILE-DB
# 117: could not dump SEAHUB-DB
# 117: could not dump SEAHUB-DB
# 130: null borg configuration variable
# 131: invalid borg configuration variable