Compare commits

...

3 Commits

Author SHA1 Message Date
Asif Bacchus 5e7d2fe6d2 check SQL vars are defined in details file 2019-05-27 06:17:38 -06:00
Asif Bacchus 62107ed611 fixed missing space in sqldumpdir command 2019-05-27 06:13:03 -06:00
Asif Bacchus f33f4824fa syntax and var name corrections 2019-05-27 06:10:06 -06:00
1 changed files with 27 additions and 10 deletions

View File

@ -12,7 +12,7 @@ warn=$(tput bold)$(tput setaf 3)
ok=$(tput setaf 2) ok=$(tput setaf 2)
yellow=$(tput setaf 3) yellow=$(tput setaf 3)
cyan=$(tput setaf 6) cyan=$(tput setaf 6)
mag=$(tput setaf 5) magenta=$(tput setaf 5)
### functions ### functions
@ -330,7 +330,7 @@ fi
### start logging ### start logging
printf "${mag}[%s] --- Start %s execution ---${norm}\n" \ printf "${magenta}[%s] --- Start %s execution ---${norm}\n" \
"$(stamp)" "$scriptName" >> "$logFile" "$(stamp)" "$scriptName" >> "$logFile"
printf "${cyan}[%s] -- [INFO] Log located at ${yellow}%s${cyan} --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Log located at ${yellow}%s${cyan} --${norm}\n" \
"$(stamp)" "$logFile" >> "$logFile" "$(stamp)" "$logFile" >> "$logFile"
@ -381,10 +381,26 @@ printf "${cyan}[%s] -- [INFO] ${yellow}%s${cyan} imported --${norm}\n" \
### dump sql databases ### dump sql databases
## verify SQL variables are defined in details file
# sqlServer
if [ -z "${sqlServer}" ]; then
badDetails empty 'sqlServer'
fi
# sqlUser
if [ -z "${sqlUser}" ]; then
badDetails empty 'sqlUser'
fi
# sqlPass
if [ -z "${sqlPass}" ]; then
badDetails empty 'sqlPass'
fi
## create tmp directory and generate dumpfile names
printf "${cyan}[%s] -- [INFO] Dumping SQL databases --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Dumping SQL databases --${norm}\n" \
"$(stamp)" >> "$logFile" "$(stamp)" >> "$logFile"
# create temporary directory to dump files before borg backup # create temporary directory to dump files before borg backup
if ! sqlDumpDir=$( mktemp -d 2>>"$logFile"); then if ! sqlDumpDir=$( mktemp -d 2>>"$logFile" ); then
exitError 111 "Could not create temporary directory to dump SQL files" exitError 111 "Could not create temporary directory to dump SQL files"
fi fi
# set cleanup flag # set cleanup flag
@ -396,6 +412,7 @@ printf "\n${yellow}%s/${cyan} --${norm}\n" "$sqlDumpDir" >> "$logFile"
sqlDump_ccnet="backup-$(date +%Y%m%d_%H%M%S)_${ccnetDB_name}.sql" sqlDump_ccnet="backup-$(date +%Y%m%d_%H%M%S)_${ccnetDB_name}.sql"
sqlDump_seafile="backup-$(date +%Y%m%d_%H%M%S)_${seafileDB_name}.sql" sqlDump_seafile="backup-$(date +%Y%m%d_%H%M%S)_${seafileDB_name}.sql"
sqlDump_seahub="backup-$(date +%Y%m%d_%H%M%S)_${seahubDB_name}.sql" sqlDump_seahub="backup-$(date +%Y%m%d_%H%M%S)_${seahubDB_name}.sql"
## dump databases ## dump databases
# dump CCNET-DB # dump CCNET-DB
if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \ if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \
@ -432,7 +449,7 @@ elif [ ! -d "${borgBaseDir}" ]; then
badDetails dne 'borgBaseDir' badDetails dne 'borgBaseDir'
fi fi
printf "${magenta}details:borgBaseDir ${norm}-- ${ok}[OK]${norm}\n" \ printf "${magenta}details:borgBaseDir ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile" >> "$logFile"
export BORG_BASE_DIR="${borgBaseDir%/}" export BORG_BASE_DIR="${borgBaseDir%/}"
## check path to SSH keyfile ## check path to SSH keyfile
@ -442,7 +459,7 @@ elif [ ! -d "${borgSSHKey}" ]; then
badDetails dne 'borgSSHKey' badDetails dne 'borgSSHKey'
fi fi
printf "${magenta}details:borgSSHKey ${norm}-- ${ok}[OK]${norm}\n" \ printf "${magenta}details:borgSSHKey ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile" >> "$logFile"
export BORG_RSH="ssh -i ${borgSSHKey}" export BORG_RSH="ssh -i ${borgSSHKey}"
## check borg repo connect string ## check borg repo connect string
@ -450,13 +467,13 @@ if [ -z "${borgConnectRepo}" ]; then
badDetails empty 'borgConnectRepo' badDetails empty 'borgConnectRepo'
fi fi
printf "${magenta}details:borgConnectRepo ${norm}-- ${ok}[OK]${norm}\n" \ printf "${magenta}details:borgConnectRepo ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile" >> "$logFile"
export BORG_REPO="${borgConnectRepo}" export BORG_REPO="${borgConnectRepo}"
## check borg repo password ## check borg repo password
if [ -n "${borgRepoPassphrase}" ]; then if [ -n "${borgRepoPassphrase}" ]; then
printf "${magenta}details:borgRepoPassphrase ${norm}-- ${ok}[OK]${norm}\n" \ printf "${magenta}details:borgRepoPassphrase ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile" >> "$logFile"
export BORG_PASSPHRASE="${borgRepoPassphrase}" export BORG_PASSPHRASE="${borgRepoPassphrase}"
else else
# if passwd is blank intentionally, this is insecure # if passwd is blank intentionally, this is insecure
@ -489,7 +506,7 @@ if [ -n "${borgXtraListPath}" ]; then
$( sed -e '/^\s*#.*$/d' -e '/^\s*$/d' "${borgXtraListPath}" ) $( sed -e '/^\s*#.*$/d' -e '/^\s*$/d' "${borgXtraListPath}" )
EOF EOF
printf "${magenta}details:borgXtraListPath ${norm}-- ${ok}[OK]${norm}\n" \ printf "${magenta}details:borgXtraListPath ${norm}-- ${ok}[OK]${norm}\n" \
>> "$logfile" >> "$logFile"
includeXtra=1 includeXtra=1
fi fi
@ -578,7 +595,7 @@ fi
if [ -n "${borgPruneSettings}" ]; then if [ -n "${borgPruneSettings}" ]; then
printf "${cyan}[%s] -- [INFO] Executing borg prune operation --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Executing borg prune operation --${norm}\n" \
"$(stamp)" >> "$logFile" "$(stamp)" >> "$logFile"
borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \ borg prune --show-rc -v "${borgPruneParams}" "${borgPruneSettings}" \
2>> "$logFile" 2>> "$logFile"
borgPruneResult="$?" borgPruneResult="$?"
else else
@ -625,7 +642,7 @@ cleanup
# note complete success, tally warnings and exit # note complete success, tally warnings and exit
printf "${ok}[%s] -- [SUCCESS] All processes completed --${norm}\n" \ printf "${ok}[%s] -- [SUCCESS] All processes completed --${norm}\n" \
"$(stamp)" >> "$logFile" "$(stamp)" >> "$logFile"
printf "${mag}[%s] --- %s execution completed ---${norm}\n" \ printf "${magenta}[%s] --- %s execution completed ---${norm}\n" \
"$(stamp)" "$scriptName" >> "$logFile" "$(stamp)" "$scriptName" >> "$logFile"
if [ "$warnCount" -gt 0 ]; then if [ "$warnCount" -gt 0 ]; then
printf "${warn}%s warnings issued!${norm}\n" "${warnCount}" >> "$logFile" printf "${warn}%s warnings issued!${norm}\n" "${warnCount}" >> "$logFile"