Batch clear 128 groups of nodes db above the expired binlog free disk space implementation idea

  • 2020-05-19 06:03:08
  • OfStack

If there are no more than 10 db, you can manually enter ssh, clean is enough, but if there are hundreds of db, you have to write scripts. General idea: write a script on one db hop machine, access slave, remotely obtain the binlog location above master which is being copied, and then remotely go to binlog above purge master.

1. Create slave dbserver list slavelist; 1 slave1 row.
2. Get binlog location above slave db and slave master hostname (maybe ip address) remotely
3. Get the binlog location and master hostname, then ssh will remotely clean binlog above master
4, shell for loops step 2 and step 3.
Attached script 1: clean_binlog.sh
 
#!/bin/bash 
# p1 the slave mysql db server 
db03=$1 
echo $dbserver; 
ster_Log_File=`ssh $db03 " mysql -uxx -pxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --s 
sl-cert=/opt/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem -e \"show slave status\G;\" |grep -i master_Log_File 
"`; 
# echo #####  To obtain binlog information  
log_file=`echo $ster_Log_File | awk '{print $2}'`; 
db01tmp=`ssh $db03 " mysql -uxx -pxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --s 
sl-cert=/opt/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem -e \"show slave status\G;\" |grep -i Master_Host 
"`; 

 
#  To obtain master Host name or ip address  
db01=`echo $db01tmp | awk '{print $2}'` 
#  Began to clean up binlog Log information  

 
ssh $db01 " mysql -uxxx -pxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --ssl-cert=/op 
t/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem -e \"purge master logs to '$log_file';\" " 
# check master The above binlog information  

 
ssh $db01 " df -h /mysql/binlog "; 

 
<STRONG><SPAN style="COLOR: #ff0000"></SPAN></STRONG>   

With batch for loop script 2:
for s in `cat slavelist`; do sh clean_binlog.sh $s; done
This is a rough scheme, which must have some shortcomings. My 128 groups are composed of mm, so this operation is ok. Different architectures are expected to change, and it also involves the backup of binlog before purge (there are special backup machines and backup scripts).

Related articles: