Fix save_mysql_dbs for missing dbs

In change I075eb5a88113acfa36519e2c6e2aab87836be065 to workaround the
potentially missing dbs in a cells environment it turned off exiting on
error. This is a bad idea since it will mask real failures. This commmit
fixes the function to check if the db exists before trying to do a
mysqldump and report whether it's missing or not.

Change-Id: I54aac82e412a298cd1d2066a0fa51131a6da2af0
This commit is contained in:
Matthew Treinish 2017-08-16 15:56:21 -04:00 committed by Davanum Srinivas (dims)
parent 377780e774
commit 5451c45577
1 changed files with 8 additions and 3 deletions

View File

@ -37,11 +37,16 @@ function save_mysql_dbs {
set +o xtrace &&
source $dir/stackrc &&
echo ${DATABASE_USER:-root})
set +e
db_names=( $(mysql -u$database_user -p$mysql_pass -Bse "show databases;") )
for db in $DATABASES_TO_SAVE; do
mysqldump -u$database_user -p$mysql_pass $db >$SAVE_DIR/$db.sql.$release
for db_found in "${db_names[@]}"; do
if [[ "$db" == "$db_found" ]]; then
echo "Saving database :" $db
mysqldump -u$database_user -p$mysql_pass $db >$SAVE_DIR/$db.sql.$release
break
fi
done
done
set -e
}
# register a database we should save