Bulk purge of expired Binlog free disk space

Source: Internet
Author: User

program, a total of 24 db, a set to go in clean-up certainly not, you need to write a script, to do batch operations, the scenario is probably the following ideas

1, set up double master list masterlist; a master row.

2, remotely obtain the Binlog location above the master DB and the master hostname (perhaps IP address) corresponding to master

3, get the Binlog location and master hostname, then ssh remotely clean off the remote master above the Binlog

4, use shell for loop operation Step 2 and step 3.


The clearbinlog.sh script is as follows

[Python]View Plaincopy print?
  1. For Masterdb in ' cat master.db.full ';d o
  2. #1 Echo Get the binlog position infomation
  3. str_log_files= ' ssh $masterdb "/opt/mysql/product/5.5.25a/bin/mysql-uroot--password=""-e \" show slave status \g;\ "| Grep-i master_log_file "'
  4. echo $str _log_files;
  5. Log_file= ' echo $str _log_files |   awk ' {print $} ';
  6. echo $log _file;
  7. #2 Echo Get the master IP address or master hostname
  8. db01tmp= ' ssh $masterdb "/opt/mysql/product/5.5.25a/bin/mysql-uroot--password=""-e \" show Slave status\g;\ "    |grep-i master_host "';
  9. Db01= ' echo $db 01tmp | awk ' {print $} '
  10. #3 begin to clear the old Binlog
  11. SSH $db "/opt/mysql/product/5.5.25a/bin/mysql-uroot--password=""-e \" Purge master logs to ' $log _file '; \ ""
  12. #4 Check the disk space for master
  13. SSH $db "Df-h"
  14. echo ""
  15. echo "------";
  16. Done


Ok,run SH Script

SH clearbinlog.sh can start cleaning up all db binlog.


Finally, check disk space again and execute the check_disk.sh script with the following script:

[HTML]View Plaincopy print?
    1. For Masterdb in ' Master.db.full ';d o
    2. SSH $masterdb "df-h" |grep-i mysqldatadir;
    3. Done

Execute SH check_disk.sh start check

Bulk purge of expired Binlog free disk space

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.