2 Commits

Author SHA1 Message Date
asif 46b29dfce9 fix(script): fix dockerCmd quoting error 2022-07-15 13:49:59 -06:00
asif 47adaceed0 feature(version): add version display to script 2022-07-12 15:07:36 -06:00
2 changed files with 16 additions and 10 deletions
+6 -6
View File
@@ -117,14 +117,14 @@ doDocker() {
if [ "$1" = "stop" ]; then if [ "$1" = "stop" ]; then
printf "%s[%s] -- [INFO] Stopping %s-mailcow container --%s\n" \ printf "%s[%s] -- [INFO] Stopping %s-mailcow container --%s\n" \
"$cyan" "$(stamp)" "$2" "$norm" >>"$logFile" "$cyan" "$(stamp)" "$2" "$norm" >>"$logFile"
"${dockerCmd}" -f "$mcDockerCompose" stop --timeout "$dockerStopTimeout" "$2-mailcow" 2>>"$logFile" ${dockerCmd} -f "$mcDockerCompose" stop --timeout "$dockerStopTimeout" "$2-mailcow" 2>>"$logFile"
# set result vars # set result vars
dockerResultState="$(docker inspect -f '{{ .State.Running }}' "$containerName")" dockerResultState="$(docker inspect -f '{{ .State.Running }}' "$containerName")"
dockerResultExit="$(docker inspect -f '{{ .State.ExitCode }}' "$containerName")" dockerResultExit="$(docker inspect -f '{{ .State.ExitCode }}' "$containerName")"
elif [ "$1" = "start" ]; then elif [ "$1" = "start" ]; then
printf "%s[%s] -- [INFO] Starting %s-mailcow container --%s\n" \ printf "%s[%s] -- [INFO] Starting %s-mailcow container --%s\n" \
"$cyan" "$(stamp)" "$2" "$norm" >>"$logFile" "$cyan" "$(stamp)" "$2" "$norm" >>"$logFile"
"${dockerCmd}" -f "$mcDockerCompose" start "$2-mailcow" 2>>"$logFile" ${dockerCmd} -f "$mcDockerCompose" start "$2-mailcow" 2>>"$logFile"
# set result vars # set result vars
dockerResultState="$(docker inspect -f '{{ .State.Running }}' "$containerName")" dockerResultState="$(docker inspect -f '{{ .State.Running }}' "$containerName")"
fi fi
@@ -700,9 +700,9 @@ fi
### dump SQL ### dump SQL
printf "%s[%s] -- [INFO] Dumping mailcow SQL database --%s\n" \ printf "%s[%s] -- [INFO] Dumping mailcow SQL database --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile" "$cyan" "$(stamp)" "$norm" >>"$logFile"
"${dockerCmd}" exec -T mysql-mailcow mysqldump --default-character-set=utf8mb4 \ ${dockerCmd} exec -T mysql-mailcow mysqldump --default-character-set=utf8mb4 \
-u${DBUSER} -p${DBPASS} ${DBNAME} >"$sqlDumpDir/$sqlDumpFile" 2>>"$logFile" -u${DBUSER} -p${DBPASS} ${DBNAME} >"$sqlDumpDir/$sqlDumpFile" 2>>"$logFile"
dumpResult=$("${dockerCmd}" exec -T mysql-mailcow echo "$?") dumpResult=$(${dockerCmd} exec -T mysql-mailcow echo "$?")
if [ "$dumpResult" -eq 0 ]; then if [ "$dumpResult" -eq 0 ]; then
printf "%s[%s] -- [INFO] SQL database dumped successfully --%s\n" \ printf "%s[%s] -- [INFO] SQL database dumped successfully --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile" "$cyan" "$(stamp)" "$norm" >>"$logFile"
@@ -718,8 +718,8 @@ fi
# dump redis # dump redis
printf "%s[%s] -- [INFO] Dumping mailcow redis database --%s\n" \ printf "%s[%s] -- [INFO] Dumping mailcow redis database --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile" "$cyan" "$(stamp)" "$norm" >>"$logFile"
"${dockerCmd}" exec -T redis-mailcow redis-cli save >>"$logFile" 2>&1 ${dockerCmd} exec -T redis-mailcow redis-cli save >>"$logFile" 2>&1
rdumpResult=$("${dockerCmd}" exec -T redis-mailcow echo "$?") rdumpResult=$(${dockerCmd} exec -T redis-mailcow echo "$?")
if [ "$rdumpResult" -eq 0 ]; then if [ "$rdumpResult" -eq 0 ]; then
printf "%s[%s] -- [INFO] mailcow redis dumped successfully --%s\n" \ printf "%s[%s] -- [INFO] mailcow redis dumped successfully --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile" "$cyan" "$(stamp)" "$norm" >>"$logFile"
+10 -4
View File
@@ -175,6 +175,7 @@ writeLog() {
### parameter defaults ### parameter defaults
# script related # script related
scriptVersion="4.0"
scriptPath="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" scriptPath="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
scriptName="$(basename "$0")" scriptName="$(basename "$0")"
errorCount=0 errorCount=0
@@ -209,6 +210,11 @@ while [ $# -gt 0 ]; do
# display help # display help
scriptHelp scriptHelp
;; ;;
--version)
# display script version
printf "\nMailcowRestore - Restore Mailcow from a borgbackup repo : Version %s\n\n" ${scriptVersion}
exit 0
;;
-l | --log) -l | --log)
# set logfile location # set logfile location
if [ -z "$2" ]; then if [ -z "$2" ]; then
@@ -393,7 +399,7 @@ if [ "$restoreSQL" -eq 1 ]; then
if [ -n "$sqlBackup" ]; then if [ -n "$sqlBackup" ]; then
# start mysql container if not already running # start mysql container if not already running
if ! docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then if ! docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then
"${dockerCmd}" up -d mysql-mailcow >/dev/null 2>&1 ${dockerCmd} up -d mysql-mailcow >/dev/null 2>&1
if docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then if docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then
sqlRunning=1 sqlRunning=1
else else
@@ -412,7 +418,7 @@ if [ "$restoreSQL" -eq 1 ]; then
# restore sql # restore sql
if [ "$sqlRunning" -eq 1 ]; then if [ "$sqlRunning" -eq 1 ]; then
if docker exec -i "$("${dockerCmd}" ps -q mysql-mailcow)" mysql -u${DBUSER} -p${DBPASS} ${DBNAME} <"${sqlBackup}" >/dev/null 2>&1; then if docker exec -i "$(${dockerCmd} ps -q mysql-mailcow)" mysql -u${DBUSER} -p${DBPASS} ${DBNAME} <"${sqlBackup}" >/dev/null 2>&1; then
writeLog 'done' writeLog 'done'
else else
writeLog 'done' 'error' writeLog 'done' 'error'
@@ -424,7 +430,7 @@ fi
### stop containers (necessary for all restore operations except SQL) ### stop containers (necessary for all restore operations except SQL)
writeLog 'task' "Stopping mailcow" writeLog 'task' "Stopping mailcow"
if ! "${dockerCmd}" down --timeout "${dockerStopTimeout}" >/dev/null 2>&1; then if ! ${dockerCmd} down --timeout "${dockerStopTimeout}" >/dev/null 2>&1; then
writeLog 'done' 'error' writeLog 'done' 'error'
writeLog 'error' '20' "Unable to bring mailcow containers down -- cannot reliably restore. Aborting." writeLog 'error' '20' "Unable to bring mailcow containers down -- cannot reliably restore. Aborting."
exitError 20 exitError 20
@@ -616,7 +622,7 @@ fi
### restart mailcow ### restart mailcow
writeLog 'task' "Starting mailcow" writeLog 'task' "Starting mailcow"
if ! "${dockerCmd}" up -d >/dev/null 2>&1; then if ! ${dockerCmd} up -d >/dev/null 2>&1; then
writeLog 'done' 'warn' writeLog 'done' 'warn'
writeLog 'warn' '21' "Unable to automatically start mailcow containers. Please attempt a manual start and note any errors." writeLog 'warn' '21' "Unable to automatically start mailcow containers. Please attempt a manual start and note any errors."
warnCount=$((warnCount + 1)) warnCount=$((warnCount + 1))