########################################################################### if [ $# -ne 1 ] then echo "脚本使用错误!!!!!!" echo "使用方法:${0} <master IP>" exit 11 fi
master_ip=${1}
#检查数据据库是否已经启动 netstat -nlpt | grep -w "mysqld" &> /dev/null if [ $? -ne 0 ] then echo "Mysqld server not start." exit 1 fi
#从新 主库 备份数据 mysqldump -u${user} -p${pas} -h${master_ip} -B -A > /tmp/bak.sql if [ $? -ne 0 ] then echo "!!!!!!备份主库失败." exit 4 fi
#恢复 mysql -uroot -pUplooking_123 -e "set sql_log_bin=0;source /tmp/bak.sql;set sql_log_bin=1;" if [ $? -ne 0 ] then echo "!!!!!!!恢复数据失败." exit 2 fi ##### mysql -uroot -pUplooking_123 -e "set global relay_log_purge=0;set global read_only=on;"
#检查运行状态(因为mha启动需要做N多检查,因此需要一定的时间等待) count=0 while : do ssh ${manger_ip} "masterha_check_status --conf=${mha_conf}" if [ $? -eq 0 ] then echo "MHA Start 成功,故障恢复完成!!!!!!!" exit 0 fi