How to batch clear the expired binlogs on the 128 group of node databases and release disk space

Source: Internet
Author: User

How can I batch clear the expired binlogs on the 128 group of node databases and release the disk space? If there are less than 10 databases, manually enter the binlogs through ssh. clean is enough, but there are hundreds of databases, you have to write the script. 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. Obtain the binlog location and master host name, and then ssh remotely cleans up binlog 4 on the master, shell for loop operations step 2 and step 3. Script 1: clean_binlog.sh [python] #! /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 "'; [python] # obtain the master host name or IP address db01 = 'echo $ db01tmp | awk '{print $2} ''# start to clear binlog log information [python] 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/serve R-key.pem-e \ "purge master logs to '$ log_file'; \" "# check binlog information on the master [python] ssh $ db01" df-h/mysql/binlog "; [python] <strong> <span style = "color: # ff0000;"> </span> </strong> comes with a batch for loop Script 2: for s in 'cat slavelist'; do sh clean_binlog.sh $ s; done is a rough solution and there must be deficiencies. My 128 groups are mm combinations, therefore, this operation can be performed, and the estimation may change depending on the architecture. Here, we also need to back up the binlog 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.