How to release disk space by clearing expired binlogs on 128 group of nodes in batches

Source: Internet
Author: User

If there are less than 10 databases, You can manually enter ssh, and clean is enough. But if there are hundreds of databases, you have to write scripts. General idea: On a db jump machine, write a script to access slave, remotely obtain the binlog location on the master that is being copied, and then remotely Go To The binlog on the purge master.

1. Create the slave dbserver list slavelist; one slave row.
2. Remotely obtain the binlog location on the slave db and the master Host Name (maybe IP address) of the slave)
3. Get the binlog location and master host name, and then remotely clear the binlog on the master using ssh.
4. shell for loop operation steps 2 and 3.
Script 1: clean_binlog.sh Copy codeThe Code is as follows :#! /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 ##### 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
"';

Copy codeThe Code is as follows: # obtain the master host name or IP address
Db01 = 'echo $ db01tmp | awk '{print $2 }''
# Start clearing binlog Information

Copy codeThe Code is as follows: 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 the binlog information on the master

Copy codeThe Code is as follows: ssh $ db01 "df-h/mysql/binlog ";

Copy codeThe Code is as follows: <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 solution, and there must be some shortcomings. My 128 group is a mm combination, so this operation is acceptable, and there will be changes in different architectures, this also involves the binlog backup before purge (with dedicated backup machines and backup scripts ).

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.