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
This commit is contained in:
Clint Byrum 2013-04-04 12:57:28 -07:00
parent 352516381f
commit ca8a663707

View File

@ -16,6 +16,7 @@
# under the License. # under the License.
set -eux set -eux
set -o pipefail
# Quietly go away unless a migration has been asked for # Quietly go away unless a migration has been asked for
DEFAULTS=/etc/mysql/migration_default DEFAULTS=/etc/mysql/migration_default
@ -52,15 +53,16 @@ local_mysql -e 'SHOW GRANTS'
if [ -n "$MIGRATION_HOST" ] ; then if [ -n "$MIGRATION_HOST" ] ; then
local_mysql -e 'STOP SLAVE' || : local_mysql -e 'STOP SLAVE' || :
# If we are planning on setting up a full slave # If we are planning on setting up a full slave
SLAVE_OPTS=""
if [ -n "$MIGRATION_USER" ] && [ -n "$MIGRATION_PASSWORD" ] ; then 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}'" local_mysql -e "CHANGE MASTER TO master_host='${MIGRATION_HOST}', master_user='${MIGRATION_USER}', master_password='${MIGRATION_PASSWORD}'"
SLAVE_OPTS="--master-data"
fi fi
mysqldump --defaults-extra-file=/root/metadata.my.cnf \ mysqldump --defaults-extra-file=/root/metadata.my.cnf \
-u $MIGRATION_DUMP_USER -u $MIGRATION_DUMP_USER \
--single-transaction \ --single-transaction \
--all-databases \ --all-databases \
--master-data \ $SLAVE_OPTS -h $MIGRATION_HOST | local_mysql
-h $MIGRATION_HOST | local_mysql
# After this following command, our ~/.my.cnf may stop working as its # After this following command, our ~/.my.cnf may stop working as its
# password may change due to the dump loaded above. # password may change due to the dump loaded above.