Batch Purge 128 group node db above expired Binlog free disk space implementation idea _mysql

Source: Internet
Author: User
Tags ssh
If 10 of the DB within the word, their own manual ssh in, clean enough, but hundreds of Taiwan, it is necessary to write a script. General idea: In a db hop above, write a script, access the slave, remotely get the Binlog location on the copy master, and then remotely to purge master Binlog.

1, establish slave dbserver list slavelist; A slave line.
2, remotely obtain the Binlog location above slave db and Slave's master hostname (perhaps an IP address)
3, get the Binlog location and master hostname, and then ssh to remotely clean up the binlog above master
4,shell for loop operation Step 2 and step 3.
Companion script 1:clean_binlog.sh
Copy Code code as follows:

#!/bin/bash
# p1 the slave MySQL DB server
Db03=$1
Echo $dbserver;
ster_log_file= ' ssh $db 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 ##### get binlog information
Log_file= ' echo $ster _log_file | awk ' {print $} ';
db01tmp= ' ssh $db 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
"`;

Copy Code code as follows:

# get Master host name or IP address
Db01= ' echo $db 01tmp | awk ' {print $} '
# Start cleaning up Binlog log information

Copy Code code as follows:

SSH $db "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's Binlog information

Copy Code code as follows:

SSH $db "Df-h/mysql/binlog";

Copy Code code as follows:

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

shipped with Batch for loop Script 2:
For S in ' Cat slavelist '; do sh clean_binlog.sh $s; Done
This is a relatively rough solution, there must be some deficiencies, my 128 group is a mm combination, so this operation is possible, the structure of different estimates will be changed, here also involves purge before the Binlog backup and so on (with a dedicated backup machine and backup script).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.