Script to Monitor Replication
Since I sometimes get replication problem, so I make several script to check replication automatically and report to me:
To check replication status when I in the console and playing with replication configuration or when I have nothing to do yet I want to see a black screen
monitorreplication.sh
#!/bin/bash
while [ 1 ]
do
# Your code goes here
echo ""
date
echo "=============================="
mysql -u backup -pmysqlback -e "show slave status\G;"
# Modify sleep time (in seconds) as needed below
sleep 10
done
Another scripts to send replication status via email
This script is for sending email to my dept. just incase replication stop. And I have manually delete file /root/backup/slave_problem.txt if problem solved.
checkreplication.sh
#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ###check if already notified### ###you have to manually delete the file after resolve the problem if [ -f /root/backup/slave_problem.txt ]; then exit 1; fi ###Check if slave running### ( echo "show slave status \G;" ) | mysql -u backup -pmysqlback 2>&1 | grep "Slave_IO_Running: No" if [ "$?" -ne "1" ]; then SUBJECT="DB23 - Replication IO failed" mysql -u backup -pmysqlback -e "show slave status \G;" > /root/backup/slave_problem.txt else ( echo "show slave status \G;" ) | mysql -u backup -pmysqlback 2>&1 | grep "Slave_SQL_Running: No" if [ "$?" -ne "1" ]; then SUBJECT="DB23 - Replication SQL failed" mysql -u backup -pmysqlback -e "show slave status \G;" > /root/backup/slave_problem.txt fi fi ###Send notification if replication down### if [ -f /root/backup/slave_problem.txt ]; then mail -s "$SUBJECT" it@myholding.com < /root/backup/slave_problem.txt fi
This script is just to send replication status to my email only so I can monitor it if it stops, or has an error, etc.
slave_report.sh
/root/backup/slave_report.sh #!/bin/sh mysql -u backup -pmysqlbackup -e "show slave status \G;" > /root/backup/slave_report.txt mail -s "Replication report on DB23" amin@rpxholding.com < /root/backup/slave_report.txt
Added the last 2 scripts into crontab:
#check replication 1,11,21,31,41,51 1-23 * * * /root/backup/checkreplication.sh > /dev/null 2>&1 5 2,6,10,14,18,22 * * * /root/backup/slave_report.sh > /dev/null 2>&1
Ref:
http://blog.taragana.com/index.php/archive/how-to-write-infinite-loop-in-bash/
http://howtoforge.com/script-to-check-if-mysql-master-master-replication-is-working-correctly
Related posts:
- Free Uptime Status Monitoring For SMB Company with few servers and network devices that...
Related posts brought to you by Yet Another Related Posts Plugin.