mysql复制数据库脚本_MySQL 复制检测脚本

以下是根据网上的脚本整理,并结合实际进行改进。

#!/bin/sh

usage="$0 -hlocalhost -uroot -pxxxx -P3306"

dbhost="localhost"

dbuser=""

dbpass=""

dbport=3306

for varin in $* ; do

if [ ${varin:0:2} = '-h' ] ; then

dbhost=${varin:2}

fi

if [ ${varin:0:2} = '-u' ] ; then

dbuser=${varin:2}

fi

if [ ${varin:0:2} = '-p' ] ; then

dbpass=${varin:2}

fi

if [ ${varin:0:2} = '-P' ] ; then

dbport=${varin:2}

fi

done

echo $dbhost

echo $dbuser

echo $dbpass

echo $dbport

now=`date +"%Y%m%d%H%M%S"`

datelog=`date +"%Y-%m-%d %H:%M:%S"`

StatFile="./slave_status.$now"

checklogfile="/var/log/MySQL_slavecheck.log"

echo "show slave status\G" | /usr/local/mysql/bin/mysql -u$dbuser -p$dbpass -h$dbhost -P$dbport > $StatFile

#get io_thread,sql_thread,last_errno status

#*************************** 1. row ***************************

#             Slave_IO_State: Connecting to master

#                Master_Host: 192.168.213.5

#                Master_User: synuser

#                Master_Port: 3306

#              Connect_Retry: 60

#            Master_Log_File: mysql-bin.000019

#        Read_Master_Log_Pos: 366270403

#             Relay_Log_File: Test-Web1-relay-bin.003133

#              Relay_Log_Pos: 98

#      Relay_Master_Log_File: mysql-bin.000019

#           Slave_IO_Running: No

#          Slave_SQL_Running: Yes

#            Replicate_Do_DB:

#        Replicate_Ignore_DB:

#         Replicate_Do_Table:

#     Replicate_Ignore_Table:

#    Replicate_Wild_Do_Table:

#Replicate_Wild_Ignore_Table:

#                 Last_Errno: 0

#                 Last_Error:

#               Skip_Counter: 0

#        Exec_Master_Log_Pos: 98

#            Relay_Log_Space: 98

#            Until_Condition: None

#             Until_Log_File:

#              Until_Log_Pos: 0

#         Master_SSL_Allowed: No

#         Master_SSL_CA_File:

#         Master_SSL_CA_Path:

#            Master_SSL_Cert:

#          Master_SSL_Cipher:

#             Master_SSL_Key:

#      Seconds_Behind_Master: NULL

IOSTAT=`grep "Slave_IO_Running" $StatFile |awk '{print $2}'`

SQLSTAT=`grep "Slave_SQL_Running" $StatFile |awk '{print $2}'`

Last_Errno=`grep "Last_Errno" $StatFile |awk '{print $2}'`

Last_Error=`grep "Last_Error" $StatFile |awk '{print $2}'`

Behind_Master=`grep "Seconds_Behind_Master" $StatFile |awk '{print $2}'`

if [ $IOSTAT = 'No' ] || [ $SQLSTAT = 'No' ] ; then

echo "Server $dbhost:$dbport Slave is down,Check Time is :$datelog " > $checklogfile

if [ $Behind_Master = 'NULL' ] ; then

echo "Server $dbhost:$dbport Slave not support slave-master,Check Time is :$datelog " >> $checklogfile

else

echo ">>Last_ErrNo:$Last_Errno" >>$checklogfile

echo ">>Last_Error:$Last_Error" >>$checklogfile

echo ">>slave is behind master $Behind seconds!" >>$checklogfile

fi

fi

/bin/rm -rf $StatFile0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值