Script Teste Sincronismo Cluster MySQL

#!/bin/bash
# Testa sincronismo de nodes em cluster MySQL
 
DATA=$( date "+%d/%m/%Y %H:%M" )
 
IP_MYSQL_NODE1=192.168.0.1
IP_MYSQL_NODE2=192.168.0.2
USER_MYSQL='usermysql'
PASSWD_MYSQL='passwd_mysql'
 
LAST_COMMITTED_NODE1=$( mysql -h $IP_MYSQL_NODE1 -u $USER_MYSQL -p$PASSWD_MYSQL -e "SHOW STATUS LIKE 'wsrep_last_committed'" | tail -n 1 | cut -f2 )
LAST_COMMITTED_NODE2=$( mysql -h $IP_MYSQL_NODE2 -u $USER_MYSQL -p$PASSWD_MYSQL -e "SHOW STATUS LIKE 'wsrep_last_committed'" | tail -n 1 | cut -f2 )
 
SUM_DIFF_LAST_COMMITTED=$(( $LAST_COMMITTED_NODE1-$LAST_COMMITTED_NODE2 ))
 
echo -e "\nLAST COMMITTED $IP_MYSQL_NODE1: $LAST_COMMITTED_NODE1"
echo -e "LAST COMMITTED $IP_MYSQL_NODE2: $LAST_COMMITTED_NODE2\n"
 
echo DIFERENCA LAST COMMITTED ENTRE $IP_MYSQL_NODE1 E $IP_MYSQL_NODE2: $SUM_DIFF_LAST_COMMITTED
 
if [ $SUM_DIFF_LAST_COMMITTED -lt -1 ] || [ $SUM_DIFF_LAST_COMMITTED -gt 1 ]; then
  echo -e "\n\e[31;1m[ ERRO ]\e[m TESTE COMMIT: BASES DE DADOS NAO SINCRONIZADAS\n"
  echo -e "\e[33;1mCMD TESTE:\e[m SHOW STATUS LIKE 'wsrep_last_committed\n"
else
  echo -e "\n\e[32;1m[ OK ]\e[m TESTE COMMIT: BASES DE DADOS SINCRONIZADAS\n"
fi
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s