|
|
|
@@ -153,6 +153,10 @@ scriptHelp() {
|
|
|
|
|
newline
|
|
|
|
|
textblock "${magenta}--- script related parameters ---${norm}"
|
|
|
|
|
newline
|
|
|
|
|
switchTextblock "-b | --borg"
|
|
|
|
|
textblock "FULL path to borg executable file if not in the default location."
|
|
|
|
|
defaultsTextblock "(/usr/bin/borg)"
|
|
|
|
|
newline
|
|
|
|
|
switchTextblock "-c | --config | --details"
|
|
|
|
|
textblock "Path to the configuration key/value-pair file for this script."
|
|
|
|
|
defaultsTextblock "(scriptPath/scriptName.details)"
|
|
|
|
@@ -164,6 +168,10 @@ scriptHelp() {
|
|
|
|
|
textblock "Path to write log file"
|
|
|
|
|
defaultsTextblock "(scriptPath/scriptName.log)"
|
|
|
|
|
newline
|
|
|
|
|
switchTextblock "[SWITCH] --nc | --no-color | --no-colour"
|
|
|
|
|
textblock "Do NOT use ANSI colourization in the log file (in case your preferred log viewer does not support it)."
|
|
|
|
|
defaultsTextblock "(use ANSI colourization to make log file look good)"
|
|
|
|
|
newline
|
|
|
|
|
switchTextblock "--compression"
|
|
|
|
|
textblock "Compression algorithm(s) that borg should use. Please run 'borg help compression' for details."
|
|
|
|
|
defaultsTextblock "(not specified, use borg default of lz4)"
|
|
|
|
@@ -249,14 +257,16 @@ trapExit() {
|
|
|
|
|
## script related
|
|
|
|
|
# store logfile in the same directory as this script file using the same file
|
|
|
|
|
# name as the script but with the extension '.log'
|
|
|
|
|
scriptPath="$( CDPATH='' cd -- "$( dirname -- "$0" )" && pwd -P )"
|
|
|
|
|
scriptPath="$( CDPATH='' \cd -- "$( dirname -- "$0" )" && pwd -P )"
|
|
|
|
|
scriptName="$( basename "$0" )"
|
|
|
|
|
logFile="$scriptPath/${scriptName%.*}.log"
|
|
|
|
|
colourizeLogFile=1
|
|
|
|
|
warnCount=0
|
|
|
|
|
configDetails="$scriptPath/${scriptName%.*}.details"
|
|
|
|
|
err503Copied=0
|
|
|
|
|
sqlDumpDirCreated=0
|
|
|
|
|
exclusions=0
|
|
|
|
|
borgPath="/usr/bin/borg"
|
|
|
|
|
# borg output verbosity -- normal
|
|
|
|
|
borgCreateParams='--stats'
|
|
|
|
|
borgPruneParams='--list'
|
|
|
|
@@ -291,6 +301,19 @@ while [ $# -gt 0 ]; do
|
|
|
|
|
badParam empty "$@"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
--nc|--no-color|--no-colour)
|
|
|
|
|
# do NOT colourize log file
|
|
|
|
|
colourizeLogFile=0
|
|
|
|
|
;;
|
|
|
|
|
-b|--borg)
|
|
|
|
|
# specify non-default borg path
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
|
borgPath="${2%/}"
|
|
|
|
|
shift
|
|
|
|
|
else
|
|
|
|
|
badParam empty "$@"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
-c|--config|--details)
|
|
|
|
|
# location of config details file
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
@@ -412,8 +435,8 @@ if [ ! -f "$configDetails" ]; then
|
|
|
|
|
badParam dne "(--details default)" "$configDetails"
|
|
|
|
|
fi
|
|
|
|
|
# is borg installed?
|
|
|
|
|
if ! command -v borg > /dev/null; then
|
|
|
|
|
printf "\n%sERROR: BORG is not installed on this system!%s\n\n" "$err" "$norm"
|
|
|
|
|
if ! find "$borgPath" -type f -executable > /dev/null 2>&1; then
|
|
|
|
|
printf "\n%sERROR: BORG cannot be found in the specified or default location on this system!%s\n\n" "$err" "$norm"
|
|
|
|
|
exit 3
|
|
|
|
|
fi
|
|
|
|
|
# if 503 functionality is enabled, do 503 related files exist?
|
|
|
|
@@ -436,6 +459,17 @@ fi
|
|
|
|
|
if [ -n "$borgCompression" ]; then
|
|
|
|
|
borgCreateParams="${borgCreateParams} --compression ${borgCompression}"
|
|
|
|
|
fi
|
|
|
|
|
# remove colourization if parameter specified
|
|
|
|
|
if [ "$colourizeLogFile" -eq 0 ]; then
|
|
|
|
|
bold=""
|
|
|
|
|
cyan=""
|
|
|
|
|
err=""
|
|
|
|
|
magenta=""
|
|
|
|
|
norm=""
|
|
|
|
|
ok=""
|
|
|
|
|
warn=""
|
|
|
|
|
yellow=""
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
### read mailcow.conf and set vars as needed
|
|
|
|
|
# shellcheck source=./mailcow.conf.shellcheck
|
|
|
|
@@ -509,7 +543,16 @@ elif [ ! -f "${borgSSHKey}" ]; then
|
|
|
|
|
fi
|
|
|
|
|
printf "%sdetails:borgSSHKey %s-- %s[OK]%s\n" \
|
|
|
|
|
"$magenta" "$norm" "$ok" "$norm" >> "$logFile"
|
|
|
|
|
export BORG_RSH="ssh -i ${borgSSHKey}"
|
|
|
|
|
## check SSH port
|
|
|
|
|
if [ -z "${borgSSHPort}" ]; then
|
|
|
|
|
borgSSHPort=22
|
|
|
|
|
printf "%sdetails:borgSSHPort %s-- %s[DEFAULT]%s\n" \
|
|
|
|
|
"$magenta" "$norm" "$ok" "$norm" >> "$logFile"
|
|
|
|
|
else
|
|
|
|
|
printf "%sdetails:borgSSHPort %s-- %s[CUSTOM]%s\n" \
|
|
|
|
|
"$magenta" "$norm" "$ok" "$norm" >> "$logFile"
|
|
|
|
|
fi
|
|
|
|
|
export BORG_RSH="ssh -i ${borgSSHKey} -p ${borgSSHPort}"
|
|
|
|
|
|
|
|
|
|
## check borg repo connect string
|
|
|
|
|
if [ -z "${borgConnectRepo}" ]; then
|
|
|
|
@@ -550,7 +593,7 @@ fi
|
|
|
|
|
## export borg remote path, if specified
|
|
|
|
|
if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi
|
|
|
|
|
|
|
|
|
|
## check if exlusion list file is specified
|
|
|
|
|
## check if exclusion list file is specified
|
|
|
|
|
if [ -n "${borgExcludeListPath}" ]; then
|
|
|
|
|
# check if the file actually exists
|
|
|
|
|
if [ ! -f "${borgExcludeListPath}" ]; then
|
|
|
|
@@ -618,7 +661,7 @@ if [ "$use503" -eq 1 ]; then
|
|
|
|
|
printf "%s[%s] -- [INFO] Copying 503 error page to " \
|
|
|
|
|
"$cyan" "$(stamp)" >> "$logFile"
|
|
|
|
|
printf "webroot -- %s\n" "$norm">> "$logFile"
|
|
|
|
|
if ! cp --force "${err503Path}" "${webroot}/${err503File}" 2>> "$logFile"
|
|
|
|
|
if ! \cp --force "${err503Path}" "${webroot}/${err503File}" 2>> "$logFile"
|
|
|
|
|
then
|
|
|
|
|
printf "%s[%s] -- [WARNING] Failed to copy 503 error page. " \
|
|
|
|
|
"$warn" "$(stamp)" >> "$logFile"
|
|
|
|
@@ -660,7 +703,7 @@ docker-compose exec -T mysql-mailcow mysqldump --default-character-set=utf8mb4 \
|
|
|
|
|
dumpResult=$( docker-compose exec -T mysql-mailcow echo "$?" )
|
|
|
|
|
if [ "$dumpResult" -eq 0 ]; then
|
|
|
|
|
printf "%s[%s] -- [INFO] SQL database dumped successfully --%s\n" \
|
|
|
|
|
"cyan" "$(stamp)" "$norm" >> "$logFile"
|
|
|
|
|
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
|
|
|
|
else
|
|
|
|
|
exitError 118 'There was an error dumping the mailcow SQL database.'
|
|
|
|
|
fi
|
|
|
|
@@ -678,7 +721,7 @@ docker-compose exec -T redis-mailcow redis-cli save >> "$logFile" 2>&1
|
|
|
|
|
rdumpResult=$( docker-compose exec -T redis-mailcow echo "$?" )
|
|
|
|
|
if [ "$rdumpResult" -eq 0 ]; then
|
|
|
|
|
printf "%s[%s] -- [INFO] mailcow redis dumped successfully --%s\n" \
|
|
|
|
|
"cyan" "$(stamp)" "$norm" >> "$logFile"
|
|
|
|
|
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
|
|
|
|
else
|
|
|
|
|
exitError 119 'There was an error dumping the mailcow redis database.'
|
|
|
|
|
fi
|
|
|
|
@@ -690,7 +733,7 @@ printf "%s[%s] -- [INFO] Pre-backup tasks completed, calling borgbackup --%s\n"
|
|
|
|
|
## construct the proper borg commandline
|
|
|
|
|
# base command
|
|
|
|
|
if [ "$exclusions" -eq 0 ]; then
|
|
|
|
|
borgCMD="borg create --show-rc ${borgCreateParams} \
|
|
|
|
|
borgCMD="${borgPath} create --show-rc ${borgCreateParams} \
|
|
|
|
|
::$(date +%Y-%m-%d_%H%M%S) \
|
|
|
|
|
${mcConfig%/*} \
|
|
|
|
|
${sqlDumpDir} \
|
|
|
|
@@ -701,7 +744,7 @@ if [ "$exclusions" -eq 0 ]; then
|
|
|
|
|
${dockerVolumeCrypt} \
|
|
|
|
|
${xtraList}"
|
|
|
|
|
elif [ "$exclusions" -eq 1 ]; then
|
|
|
|
|
borgCMD="borg create --show-rc ${borgCreateParams} \
|
|
|
|
|
borgCMD="${borgPath} create --show-rc ${borgCreateParams} \
|
|
|
|
|
--exclude-from ${borgExcludeListPath} \
|
|
|
|
|
::$(date +%Y-%m-%d_%H%M%S) \
|
|
|
|
|
${mcConfig%/*} \
|
|
|
|
@@ -745,7 +788,7 @@ fi
|
|
|
|
|
if [ -n "${borgPruneSettings}" ]; then
|
|
|
|
|
printf "%s[%s] -- [INFO] Executing borg prune operation --%s\n" \
|
|
|
|
|
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
|
|
|
|
borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \
|
|
|
|
|
"${borgPath}" prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \
|
|
|
|
|
2>> "$logFile"
|
|
|
|
|
borgPruneResult="$?"
|
|
|
|
|
else
|
|
|
|
|