Last active
June 29, 2020 04:56
-
-
Save mirhmousavi/e3fc2a7491e99b358ebf6ec506ad15b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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