Powered By Blogger

Thursday, 22 March 2012

keeping the slave always delayed

often DBA wll delete or drop table and will replicate to slave very fast.
In order to avoid that we should always have one slave delayed.
 for that we have two scripts :

########first script############
vi /home/kiran.chinta/scripts/checkslave.sh
#!/bin/sh
MUSER="kiran"
MPASS="kiran"
MHOST="db1"
mysql -u $MUSER -p$MPASS -h $MHOST -Bse "show master status" > /home/kiran.chinta/scripts/slavepos.txt

#### second scripts #############
vi /home/kiran.chinta/scripts/slavedetail.sh
#!/bin/sh
#tail -l /home/kil -l /home/kiran.chinta/slavepos.txt |  while read -r fname bpos
#ran.chinta/slavepos.txt |  while read -r fname bpos
#do
#echo $fname
#echo $bpos
#done
fname=`tr -s ' '  < slavepos.txt | awk -F ' ' '{print $1}'`
bpos=`tr -s ' '  < slavepos.txt | awk -F ' ' '{print $2}'`
user=dba
pass=dba
echo "$fname"
echo "$bpos"
mysql -u $user -p$pass -Bse "START SLAVE IO_THREAD UNTIL MASTER_LOG_FILE='$fname', MASTER_LOG_POS=$bpos"

After creating the two scripts
We should have the following crons

##### give below should run on the cronts #################
#getting the master status
30 02 * * * sh -xf /home/kiran.chinta/scripts/checkslave.sh  > checksucc.txt 2>checkfail.txt
#updating the slave status
30 22 * * * sh -xf /home/kiran.chinta/scripts/slavedetail.sh  > slavedetail_succ.txt 2>slavedetail_fail.txt



No comments:

Post a Comment