Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

Finding the least binary logs amount multiple slaves connected in master

$
0
0

I have the master server with multiple slaves (for ex: 4). I would like to purge the binary logs after checking the processed binlogs on all slaves. I wrote the below script to find the least binlogs (last second binarylogs) to purge.

#!/bin/bash
set -x
binlogval=""

Find the ip address

for i in $(mysql -u$user -p$pw  -e "show processlist" | egrep -i "Binlog Dump" | awk 'BEGIN{FS="\t"} {print $3}' | cut -d ':' -f1);
     do echo "$i"; 
     #shost=`echo IP$i| tr '.' '_'`;

Find the Relay_Master_Log_File on slave side

binlogv=`/usr/local/mysql/bin/mysql -u$user -p$pw -h $i  -sss -e "show slave status\G" | grep "Relay_Master_Log_File:" | awk -F"." '{print $2}'`;
binlogval="$binlogval:$binlogv";
done;
lowestvalue=`echo $binlogval | tr ':' '\n' | grep ^[0-9] | sort -n | head -1` 

Find the value of the lest binary log

safe_binlog="mysql-bin."$lowestvalue

Find the last second of the least binary logs for purging (safe)

last_binlog=`echo "$safe_binlog" | awk -F"." '{ res=$2 - 1 ; difflen=length($2) - length(res); if(difflen > 0){for(i=1;i<=difflen;i++){str=str 0}}print $1 "." str res}'`

Script to purge the binary logs from master server

echo $last_binlog

Here, if the mysql is placed in different socket, I can't access the mysql.

In simple terms, if the socket files placed it in different location for one instance, and by this script it throws error.

So, I would like to get the below values for the slaves.

  1. IP address - that has been taken already
  2. Port/hostname of the slave - How to find the slave socket from the master ( In case the report_xxxx is not configured)
  3. socket of the running mysql - How to find the slave socket from the master server.

    mysql -u$user -u$port -p -P$port -S$socket - that will work for me.  But I don't think we can find from master server.
    

Is there any approach to find the least binary logs?


Viewing all articles
Browse latest Browse all 17268

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>