From 3460be4852f86804d9509b41fcbfda2de1f1031a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 29 Aug 2023 20:30:24 +0000 Subject: [PATCH] Fixed error handle on backuptool --- bin/backuptool | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/backuptool b/bin/backuptool index c7807ee..75f5343 100755 --- a/bin/backuptool +++ b/bin/backuptool @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x # # Federated Backup / Restore Tool to B2 Backblaze . /federated/lib/functions.sh @@ -65,7 +65,8 @@ backupservice() { rm /federated/apps/wordpress/dump_$SERVICE.sql.gz else # For all other services, If the postgresql database exists for that service then dump it - if [ ! "`docker exec -it postgresql psql -U $SERVICE -c '\q' &>/dev/null`" ]; then + docker exec -it postgresql psql -U $SERVICE -c '\q' &>/dev/null + if [ $? -eq 0 ]; then docker exec postgresql /bin/bash -c "pg_dump $SERVICE -c -U postgres | gzip -9 > /docker-entrypoint-initdb.d/dump_$SERVICE.sql.gz" mv /federated/apps/postgresql/data/docker-entrypoint-initdb.d/dump_$SERVICE.sql.gz /federated/apps/$SERVICE/ fi @@ -103,7 +104,8 @@ backupserviceall() { PASSPHRASE=$GPG_PASSPHRASE duplicity /federated/apps/$i b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$i/ rm /federated/apps/wordpress/dump_$i.sql.gz else - if [ ! "`docker exec -it postgresql psql -U $i -c '\q' &>/dev/null`" ]; then + docker exec -it postgresql psql -U $i -c '\q' &>/dev/null + if [ $? -eq 0 ]; then docker exec postgresql /bin/bash -c "pg_dump $i -c -U postgres | gzip -9 > /docker-entrypoint-initdb.d/dump_$i.sql.gz" mv /federated/apps/postgresql/data/docker-entrypoint-initdb.d/dump_$i.sql.gz /federated/apps/$i/ fi