From ca8a663707727d6098e3eca60dca67b3547ed060 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 4 Apr 2013 12:57:28 -0700 Subject: [PATCH] Fix mysql migration script to handle errors. Errors in mysqldump would have been missed due to not having pipefail set. Also there was a type-o in the invocation of mysqldump that was going undetected, that has been repaired. Finally we should not pass --master-data if we don't have slave credentials, as the master data, even if provided, is useless without a valid slave user/pass. Change-Id: I0f80af34c747f465250ef17fae4a44dac919c9cd --- .../os-refresh-config/migration.d/10-bootstrap-mysql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/elements/mysql-migration/os-refresh-config/migration.d/10-bootstrap-mysql b/elements/mysql-migration/os-refresh-config/migration.d/10-bootstrap-mysql index d8a6ca35..2427fc42 100755 --- a/elements/mysql-migration/os-refresh-config/migration.d/10-bootstrap-mysql +++ b/elements/mysql-migration/os-refresh-config/migration.d/10-bootstrap-mysql @@ -16,6 +16,7 @@ # under the License. set -eux +set -o pipefail # Quietly go away unless a migration has been asked for DEFAULTS=/etc/mysql/migration_default @@ -52,15 +53,16 @@ local_mysql -e 'SHOW GRANTS' if [ -n "$MIGRATION_HOST" ] ; then local_mysql -e 'STOP SLAVE' || : # If we are planning on setting up a full slave + SLAVE_OPTS="" if [ -n "$MIGRATION_USER" ] && [ -n "$MIGRATION_PASSWORD" ] ; then local_mysql -e "CHANGE MASTER TO master_host='${MIGRATION_HOST}', master_user='${MIGRATION_USER}', master_password='${MIGRATION_PASSWORD}'" + SLAVE_OPTS="--master-data" fi mysqldump --defaults-extra-file=/root/metadata.my.cnf \ - -u $MIGRATION_DUMP_USER + -u $MIGRATION_DUMP_USER \ --single-transaction \ --all-databases \ - --master-data \ - -h $MIGRATION_HOST | local_mysql + $SLAVE_OPTS -h $MIGRATION_HOST | local_mysql # After this following command, our ~/.my.cnf may stop working as its # password may change due to the dump loaded above.