1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#! /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 |