Compare commits
No commits in common. "d9c662bb454e9693a5c414b2a7536ea4cb8c7a9d" and "a5bc4549e9828958f8f33e55c1d291b3a6f5e526" have entirely different histories.
d9c662bb45
...
a5bc4549e9
149
backup/backup.sh
149
backup/backup.sh
@ -85,16 +85,6 @@ cleanup () {
|
|||||||
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
"$cyan" "$(stamp)" "$norm" >> "$logFile"
|
||||||
fi
|
fi
|
||||||
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
|
# call cleanup and then exit with error report
|
||||||
@ -209,12 +199,6 @@ err503Path="$scriptPath/503_backup.html"
|
|||||||
err503File="${err503Path##*/}"
|
err503File="${err503Path##*/}"
|
||||||
webroot="/usr/share/nginx/html"
|
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
|
### process startup parameters
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
@ -233,6 +217,11 @@ while [ $# -gt 0 ]; do
|
|||||||
badParam empty "$@"
|
badParam empty "$@"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
-v|--verbose)
|
||||||
|
# set verbose logging from borg
|
||||||
|
borgCreateParams='--list --stats'
|
||||||
|
borgPruneParams='--list'
|
||||||
|
;;
|
||||||
-c|--config|--details)
|
-c|--config|--details)
|
||||||
# location of config details file
|
# location of config details file
|
||||||
if [ -n "$2" ]; then
|
if [ -n "$2" ]; then
|
||||||
@ -246,11 +235,6 @@ while [ $# -gt 0 ]; do
|
|||||||
badParam empty "$@"
|
badParam empty "$@"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-v|--verbose)
|
|
||||||
# set verbose logging from borg
|
|
||||||
borgCreateParams='--list --stats'
|
|
||||||
borgPruneParams='--list'
|
|
||||||
;;
|
|
||||||
-5|--use-503)
|
-5|--use-503)
|
||||||
# enable copying 503 error page to webroot
|
# enable copying 503 error page to webroot
|
||||||
use503=1
|
use503=1
|
||||||
@ -282,46 +266,6 @@ while [ $# -gt 0 ]; do
|
|||||||
badParam empty "$@"
|
badParam empty "$@"
|
||||||
fi
|
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 "\n%sUnknown option: %s\n" "$err" "$1"
|
||||||
printf "%sUse '--help' for valid options.%s\n\n" "$cyan" "$norm"
|
printf "%sUse '--help' for valid options.%s\n\n" "$cyan" "$norm"
|
||||||
@ -355,23 +299,6 @@ if [ "$use503" -eq 1 ]; then
|
|||||||
badParam dne "(--webroot default)" "$webroot"
|
badParam dne "(--webroot default)" "$webroot"
|
||||||
fi
|
fi
|
||||||
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
|
### start logging
|
||||||
@ -381,22 +308,24 @@ printf "%s[%s] -- [INFO] Log located at %s%s%s --%s\n" \
|
|||||||
"$cyan" "$(stamp)" "$yellow" "$logFile" "$cyan" "$norm" >> "$logFile"
|
"$cyan" "$(stamp)" "$yellow" "$logFile" "$cyan" "$norm" >> "$logFile"
|
||||||
|
|
||||||
|
|
||||||
### get location of docker volumes
|
### 503 functionality
|
||||||
dockerVolumeMail=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_vmail-vol-1)
|
if [ "$use503" -eq 1 ]; then
|
||||||
printf "%s[%s] -- [INFO] Using MAIL volume: %s --%s\n" \
|
printf "%s[%s] -- [INFO] Copying 503 error page to " \
|
||||||
"$cyan" "$(stamp)" "$dockerVolumeMail" "$norm" >> "$logFile"
|
"$cyan" "$(stamp)" >> "$logFile"
|
||||||
dockerVolumeRspamd=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_rspamd-vol-1)
|
printf "webroot -- %s\n" "$norm">> "$logFile"
|
||||||
printf "%s[%s] -- [INFO] Using RSPAMD volume: %s --%s\n" \
|
if ! cp --force "${err503Path}" "${webroot}/${err503File}" 2>> "$logFile"
|
||||||
"$cyan" "$(stamp)" "$dockerVolumeRspamd" "$norm" >> "$logFile"
|
then
|
||||||
dockerVolumePostfix=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_postfix-vol-1)
|
printf "%s[%s] -- [WARNING] Failed to copy 503 error page. " \
|
||||||
printf "%s[%s] -- [INFO] Using POSTFIX volume: %s --%s\n" \
|
"$warn" "$(stamp)" >> "$logFile"
|
||||||
"$cyan" "$(stamp)" "$dockerVolumePostfix" "$norm" >> "$logFile"
|
printf "Web users will NOT be notified --%s\n" "$norm" >> "$logFile"
|
||||||
dockerVolumeRedis=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_redis-vol-1)
|
warnCount=$((warnCount+1))
|
||||||
printf "%s[%s] -- [INFO] Using REDIS volume: %s --%s\n" \
|
else
|
||||||
"$cyan" "$(stamp)" "$dockerVolumeRedis" "$norm" >> "$logFile"
|
printf "%s[%s] -- [SUCCESS] 503 error page copied --%s\n" \
|
||||||
dockerVolumeCrypt=$(docker volume inspect -f '{{ .Mountpoint }}' ${COMPOSE_PROJECT_NAME}_crypt-vol-1)
|
"$ok" "$(stamp)" "$norm" >> "$logFile"
|
||||||
printf "%s[%s] -- [INFO] Using MAILCRYPT volume: %s --%s\n" \
|
# set cleanup flag
|
||||||
"$cyan" "$(stamp)" "$dockerVolumeCrypt" "$norm" >> "$logFile"
|
err503Copied=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
### read details file to get variables needed run borg
|
### read details file to get variables needed run borg
|
||||||
@ -529,37 +458,6 @@ fi
|
|||||||
export TMPDIR="${borgBaseDir}/tmp"
|
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
|
### execute borg depending on whether exclusions are defined
|
||||||
|
|
||||||
## construct the proper borg commandline
|
## construct the proper borg commandline
|
||||||
@ -668,7 +566,6 @@ exit 0
|
|||||||
# 2: not run as root
|
# 2: not run as root
|
||||||
# 3: borg not installed
|
# 3: borg not installed
|
||||||
# 99: TERM signal trapped
|
# 99: TERM signal trapped
|
||||||
# 115: unable to create temp dir for SQL dump
|
|
||||||
# 130: null configuration variable in details file
|
# 130: null configuration variable in details file
|
||||||
# 131: invalid configuration variable in details file
|
# 131: invalid configuration variable in details file
|
||||||
# 138: borg exited with a critical error
|
# 138: borg exited with a critical error
|
||||||
|
Loading…
Reference in New Issue
Block a user