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.
IP address
- that has been taken alreadyPort/hostname of the slave
- How to find theslave socket
from themaster
( In case thereport_xxxx
is not configured)socket of the running mysql
- How to find theslave 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?