File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
2- set -eo pipefail
32
43backup_tool=" /google-cloud-sdk/bin/gsutil"
54backup_options=" -m rsync -r"
@@ -15,7 +14,7 @@ FORCE=""
1514if [ ! -z " $MYSQL_DUMP_FORCE " ]; then
1615 FORCE=" --force"
1716else
18- set -eo pipefail # if we do not force, we want clean exit codes on mysqldump command
17+ set -euo pipefail # if we do not force, we want clean exit codes on mysqldump command
1918fi
2019
2120if [ ! -z " $GOOGLE_APPLICATION_CREDENTIALS " ]; then
2524mkdir -p /tmp/backup/
2625rm -rf -- /tmp/backup/*
2726
28- candidates=$( echo " show databases" | mysql -u " $MYSQL_USER " -p" $MYSQL_PASSWORD " -h " $MYSQL_HOST " -P " $MYSQL_PORT " | grep -Ev " ^(Database|sys|performance_schema|information_schema)$" )
29-
30- mysqldump -u " $MYSQL_USER " -p" $MYSQL_PASSWORD " --databases $candidates --single-transaction -h " $MYSQL_HOST " -P " $MYSQL_PORT " --result-file=/tmp/backup/dump.sql --verbose $FORCE
31- echo $?
27+ for i in ` echo " show databases" | mysql -u " $MYSQL_USER " -p" $MYSQL_PASSWORD " -h " $MYSQL_HOST " -P " $MYSQL_PORT " | grep -Ev " ^(Database|sys|performance_schema|information_schema|$MYSQL_IGNORE_DBS )$" ` ; do
28+ echo $i
29+ mysqldump -u " $MYSQL_USER " -p" $MYSQL_PASSWORD " --databases $i --single-transaction -h " $MYSQL_HOST " -P " $MYSQL_PORT " --result-file=/tmp/backup/${i} _dump.sql --verbose $FORCE || echo " ${i} database backup has failed!" >> /tmp/fails
30+ gzip -v /tmp/backup/${i} _dump.sql || true
31+ done
3232
3333echo " export done, now gzip output and transfer it to GCS"
3434
35- gzip -v /tmp/backup/dump.sql
3635$backup_tool $backup_options /tmp/backup/ gs://$GS_URL /
36+
37+ if [ -f /tmp/fails ]; then
38+ cat /tmp/fails
39+ exit 1
40+ fi
You can’t perform that action at this time.
0 commit comments