Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /bin/bash
set -o nounset
set -o errexit
sanitize () {
sed 's/[^[:print:]]//g' | xargs
}
error_no=$(mysql -uroot -proot --database smcli --execute 'show slave status\G' | grep 'Last_SQL_Errno:' | awk -F: '{print $2}' | sanitize)
master_log_file=$(mysql -uroot -proot --database smcli --execute 'show slave status\G' | grep 'Relay_Master_Log_File:' | awk -F: '{print $2}' | sanitize)
master_log_pos=$(mysql -uroot -proot --database smcli --execute 'show slave status\G' | grep 'Exec_Master_Log_Pos:' | awk -F: '{print $2}' | sanitize)
# this error is because of incomplete write due to full disk or
# binlog event not written completely due to e.g. a power failure
# https://bugs.mysql.com/bug.php?id=70222
if [[ $error_no == '1594' ]]; then
# don't put cotations around `MASTER_LOG_POS` value (took 2 hours to understand this, so...)
mysql -uroot -proot --database smcli --execute \
"STOP SLAVE;RESET SLAVE;CHANGE MASTER TO MASTER_LOG_FILE='$master_log_file',MASTER_LOG_POS=$master_log_pos;START SLAVE;"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.