Compare commits
8 Commits
a5bc4549e9
...
d9c662bb45
Author | SHA1 | Date | |
---|---|---|---|
|
d9c662bb45 | ||
|
e9884a347f | ||
|
8a5a87db12 | ||
|
0d32aaf40a | ||
|
bb952a3aba | ||
|
dccf5e17d0 | ||
|
35ce452dec | ||
|
604d3da07d |
149
backup/backup.sh
149
backup/backup.sh
@ -85,6 +85,16 @@ cleanup () {
|
||||
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
||||
fi
|
||||
fi
|
||||
# cleanup SQL dump directory if created
|
||||
if [ "$sqlDumpDirCreated" -eq 1 ]; then
|
||||
if ! rm -rf "$sqlDumpDir" 2>>"$logFile"; then
|
||||
printf "%s[%s] -- [WARNING] Could not remove temporary SQL-dump directory. Sorry for the mess. --%s\n" \
|
||||
"$warn" "$(stamp)" "$norm" >> "$logFile"
|
||||
else
|
||||
printf "%s[%s] -- [INFO] Temporary SQL-dump directory removed successfully --%s\n" \
|
||||
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# call cleanup and then exit with error report
|
||||
@ -199,6 +209,12 @@ err503Path="$scriptPath/503_backup.html"
|
||||
err503File="${err503Path##*/}"
|
||||
webroot="/usr/share/nginx/html"
|
||||
|
||||
# mailcow/docker related
|
||||
mcConfig='/opt/mailcow-dockerized/mailcow.conf'
|
||||
mcDockerCompose="${mcConfig}/docker-compose.yml"
|
||||
dockerStartTimeout=180
|
||||
dockerStopTimeout=120
|
||||
|
||||
|
||||
### process startup parameters
|
||||
while [ $# -gt 0 ]; do
|
||||
@ -217,11 +233,6 @@ while [ $# -gt 0 ]; do
|
||||
badParam empty "$@"
|
||||
fi
|
||||
;;
|
||||
-v|--verbose)
|
||||
# set verbose logging from borg
|
||||
borgCreateParams='--list --stats'
|
||||
borgPruneParams='--list'
|
||||
;;
|
||||
-c|--config|--details)
|
||||
# location of config details file
|
||||
if [ -n "$2" ]; then
|
||||
@ -235,6 +246,11 @@ while [ $# -gt 0 ]; do
|
||||
badParam empty "$@"
|
||||
fi
|
||||
;;
|
||||
-v|--verbose)
|
||||
# set verbose logging from borg
|
||||
borgCreateParams='--list --stats'
|
||||
borgPruneParams='--list'
|
||||
;;
|
||||
-5|--use-503)
|
||||
# enable copying 503 error page to webroot
|
||||
use503=1
|
||||
@ -266,6 +282,46 @@ while [ $# -gt 0 ]; do
|
||||
badParam empty "$@"
|
||||
fi
|
||||
;;
|
||||
-d|--docker-compose)
|
||||
# path to mailcow docker-compose file
|
||||
if [ -n "$2" ]; then
|
||||
if [ -f "$2" ]; then
|
||||
mcDockerCompose="${2%/}"
|
||||
shift
|
||||
else
|
||||
badParam dne "$@"
|
||||
fi
|
||||
else
|
||||
badParam empty "$@"
|
||||
fi
|
||||
;;
|
||||
-m|--mailcow-config)
|
||||
# path to mailcow configuration file
|
||||
if [ -n "$2" ]; then
|
||||
if [ -f "$2" ]; then
|
||||
mcConfig="${2%/}"
|
||||
shift
|
||||
else
|
||||
badParam dne "$@"
|
||||
fi
|
||||
else
|
||||
badParam empty "$@"
|
||||
fi
|
||||
;;
|
||||
-t1|--timeout-start)
|
||||
if [ -z "$2" ]; then
|
||||
badParam empty "$@"
|
||||
else
|
||||
dockerStartTimeout="$2"
|
||||
fi
|
||||
;;
|
||||
-t2|--timeout-stop)
|
||||
if [ -z "$2" ]; then
|
||||
badParam empty "$@"
|
||||
else
|
||||
dockerStopTimeout="$2"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
printf "\n%sUnknown option: %s\n" "$err" "$1"
|
||||
printf "%sUse '--help' for valid options.%s\n\n" "$cyan" "$norm"
|
||||
@ -299,6 +355,23 @@ if [ "$use503" -eq 1 ]; then
|
||||
badParam dne "(--webroot default)" "$webroot"
|
||||
fi
|
||||
fi
|
||||
# verify mailcow.conf location and extract path
|
||||
if [ -f "$mcConfig" ]; then
|
||||
# strip filename and get path
|
||||
mcPath=${mcConfig%/*/}
|
||||
else
|
||||
badParam dne "(--mailcow-config)" "$mcConfig"
|
||||
fi
|
||||
# verify docker-compose file exists
|
||||
if [ ! -f "$mcDockerCompose" ]; then
|
||||
badParam dne "(--docker-compose)" "$mcDockerCompose"
|
||||
fi
|
||||
|
||||
|
||||
### read mailcow.conf and set vars as needed
|
||||
. "$mcConfig"
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
export COMPOSE_HTTP_TIMEOUT="$dockerStartTimeout"
|
||||
|
||||
|
||||
### start logging
|
||||
@ -308,24 +381,22 @@ printf "%s[%s] -- [INFO] Log located at %s%s%s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$yellow" "$logFile" "$cyan" "$norm" >> "$logFile"
|
||||
|
||||
|
||||
### 503 functionality
|
||||
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"
|
||||
then
|
||||
printf "%s[%s] -- [WARNING] Failed to copy 503 error page. " \
|
||||
"$warn" "$(stamp)" >> "$logFile"
|
||||
printf "Web users will NOT be notified --%s\n" "$norm" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
else
|
||||
printf "%s[%s] -- [SUCCESS] 503 error page copied --%s\n" \
|
||||
"$ok" "$(stamp)" "$norm" >> "$logFile"
|
||||
# set cleanup flag
|
||||
err503Copied=1
|
||||
fi
|
||||
fi
|
||||
### get location of docker volumes
|
||||
dockerVolumeMail=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_vmail-vol-1)
|
||||
printf "%s[%s] -- [INFO] Using MAIL volume: %s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$dockerVolumeMail" "$norm" >> "$logFile"
|
||||
dockerVolumeRspamd=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_rspamd-vol-1)
|
||||
printf "%s[%s] -- [INFO] Using RSPAMD volume: %s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$dockerVolumeRspamd" "$norm" >> "$logFile"
|
||||
dockerVolumePostfix=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_postfix-vol-1)
|
||||
printf "%s[%s] -- [INFO] Using POSTFIX volume: %s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$dockerVolumePostfix" "$norm" >> "$logFile"
|
||||
dockerVolumeRedis=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_redis-vol-1)
|
||||
printf "%s[%s] -- [INFO] Using REDIS volume: %s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$dockerVolumeRedis" "$norm" >> "$logFile"
|
||||
dockerVolumeCrypt=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_crypt-vol-1)
|
||||
printf "%s[%s] -- [INFO] Using MAILCRYPT volume: %s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$dockerVolumeCrypt" "$norm" >> "$logFile"
|
||||
|
||||
|
||||
### read details file to get variables needed run borg
|
||||
@ -458,6 +529,37 @@ fi
|
||||
export TMPDIR="${borgBaseDir}/tmp"
|
||||
|
||||
|
||||
### set location of sql dump
|
||||
if ! sqlDumpDir=$( mktemp -d 2>/dev/null ); then
|
||||
exitError 115 'Unable to create temp directory for SQL dump.'
|
||||
else
|
||||
sqlDumpFile="backup-$( date +%Y%m%d_%H%M%S ).sql"
|
||||
sqlDumpDirCreated=1
|
||||
printf "%s[%s] -- [INFO] SQL dump file will be stored at: %s --%s\n" \
|
||||
"$cyan" "$(stamp)" "$sqlDumpDir/$sqlDumpFile" "$norm" >> "$logFile"
|
||||
fi
|
||||
|
||||
|
||||
### 503 functionality
|
||||
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"
|
||||
then
|
||||
printf "%s[%s] -- [WARNING] Failed to copy 503 error page. " \
|
||||
"$warn" "$(stamp)" >> "$logFile"
|
||||
printf "Web users will NOT be notified --%s\n" "$norm" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
else
|
||||
printf "%s[%s] -- [SUCCESS] 503 error page copied --%s\n" \
|
||||
"$ok" "$(stamp)" "$norm" >> "$logFile"
|
||||
# set cleanup flag
|
||||
err503Copied=1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
### execute borg depending on whether exclusions are defined
|
||||
|
||||
## construct the proper borg commandline
|
||||
@ -566,6 +668,7 @@ exit 0
|
||||
# 2: not run as root
|
||||
# 3: borg not installed
|
||||
# 99: TERM signal trapped
|
||||
# 115: unable to create temp dir for SQL dump
|
||||
# 130: null configuration variable in details file
|
||||
# 131: invalid configuration variable in details file
|
||||
# 138: borg exited with a critical error
|
||||
|
Loading…
Reference in New Issue
Block a user