12 groups of nodes MySQL databases, two Master-Master instances in each group, batch clear expired binlogs to release disk space

Source: Internet
Author: User



Solution: a total of 24 databases, and one database cannot be cleaned up. You need to write a script to Perform Batch operations. The solution is roughly as follows:

1,Creates a master list with one master row.

2,Remotely obtain the binlog location on the master database and the master Host Name (maybe IP address) of the corresponding master)

3,Obtain the binlog location and master host name, and then remotely clear the binlog on the remote master using ssh.

4,Shell for loop operations step 2 and step 3.

for masterdb in `cat master.db.full`;do#1 echo get the binlog position infomationstr_log_files=`ssh $masterdb "/opt/mysql/product/5.5.25a/bin/mysql -uroot --password="" -e \"show slave status\G;\" |grep -i master_Log_File "`echo $str_log_files;log_file=`echo $str_log_files | awk '{print $2}'`; echo $log_file;#2 echo get the master ip address or master hostnamedb01tmp=`ssh $masterdb "  /opt/mysql/product/5.5.25a/bin/mysql  -uroot  --password=""  -e \"show slave status\G;\" |grep -i Master_Host  "`;  db01=`echo $db01tmp | awk '{print $2}'`#3 begin to clear the old binlog ssh $db01 "/opt/mysql/product/5.5.25a/bin/mysql  -uroot  --password="" -e \"purge master logs to '$log_file';\""#4 check the disk space for masterssh $db01 "df -h"echo " "echo " -- -- -- ";done;

OK, run sh script

Check disk space again and run the check_disk.sh script. The script content is as follows:

for masterdb in `master.db.full`;do  ssh  $masterdb "df -h" |grep -i mysqldatadir;done;

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.