Skip to content

Commit

Permalink
fix(script): fix dockerCmd quoting error
Browse files Browse the repository at this point in the history
  • Loading branch information
asifbacchus committed Jul 15, 2022
1 parent 47adace commit 46b29df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions backup/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ doDocker() {
if [ "$1" = "stop" ]; then
printf "%s[%s] -- [INFO] Stopping %s-mailcow container --%s\n" \
"$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
dockerResultState="$(docker inspect -f '{{ .State.Running }}' "$containerName")"
dockerResultExit="$(docker inspect -f '{{ .State.ExitCode }}' "$containerName")"
elif [ "$1" = "start" ]; then
printf "%s[%s] -- [INFO] Starting %s-mailcow container --%s\n" \
"$cyan" "$(stamp)" "$2" "$norm" >>"$logFile"
"${dockerCmd}" -f "$mcDockerCompose" start "$2-mailcow" 2>>"$logFile"
${dockerCmd} -f "$mcDockerCompose" start "$2-mailcow" 2>>"$logFile"
# set result vars
dockerResultState="$(docker inspect -f '{{ .State.Running }}' "$containerName")"
fi
Expand Down Expand Up @@ -700,9 +700,9 @@ fi
### dump SQL
printf "%s[%s] -- [INFO] Dumping mailcow SQL database --%s\n" \
"$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"
dumpResult=$("${dockerCmd}" exec -T mysql-mailcow echo "$?")
dumpResult=$(${dockerCmd} exec -T mysql-mailcow echo "$?")
if [ "$dumpResult" -eq 0 ]; then
printf "%s[%s] -- [INFO] SQL database dumped successfully --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile"
Expand All @@ -718,8 +718,8 @@ fi
# dump redis
printf "%s[%s] -- [INFO] Dumping mailcow redis database --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile"
"${dockerCmd}" exec -T redis-mailcow redis-cli save >>"$logFile" 2>&1
rdumpResult=$("${dockerCmd}" exec -T redis-mailcow echo "$?")
${dockerCmd} exec -T redis-mailcow redis-cli save >>"$logFile" 2>&1
rdumpResult=$(${dockerCmd} exec -T redis-mailcow echo "$?")
if [ "$rdumpResult" -eq 0 ]; then
printf "%s[%s] -- [INFO] mailcow redis dumped successfully --%s\n" \
"$cyan" "$(stamp)" "$norm" >>"$logFile"
Expand Down
8 changes: 4 additions & 4 deletions backup/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ if [ "$restoreSQL" -eq 1 ]; then
if [ -n "$sqlBackup" ]; then
# 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
"${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
sqlRunning=1
else
Expand All @@ -418,7 +418,7 @@ if [ "$restoreSQL" -eq 1 ]; then

# restore sql
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'
else
writeLog 'done' 'error'
Expand All @@ -430,7 +430,7 @@ fi

### stop containers (necessary for all restore operations except SQL)
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 'error' '20' "Unable to bring mailcow containers down -- cannot reliably restore. Aborting."
exitError 20
Expand Down Expand Up @@ -622,7 +622,7 @@ fi

### restart 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 'warn' '21' "Unable to automatically start mailcow containers. Please attempt a manual start and note any errors."
warnCount=$((warnCount + 1))
Expand Down

0 comments on commit 46b29df

Please sign in to comment.