zoukankan      html  css  js  c++  java
  • 批量清除过期的binlog释放磁盘空间

    方案,总共24台db,一台台进去清理肯定不行,得需要写一个脚本,进行批量操作,方案思路大概如下

    1,  建立双master列表masterlist; 一个master一行。

     

    2,远程获取master db上面的binlog位置以及对应master的master主机名(也许是ip地址)

     

    3,拿到binlog位置以及master主机名,然后ssh远程清理掉远程master上面的binlog

     

    4, 采用shell for循环操作step 2以及step 3。


    clearbinlog.sh脚本如下

     

    1. for masterdb in `cat master.db.full`;do  
    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 statusG;" |grep -i master_Log_File "`  
    4.     echo $str_log_files;  
    5.     log_file=`echo $str_log_files | awk '{print $2}'`;   
    6.     echo $log_file;  
    7.   
    8.     #2 echo get the master ip address or master hostname  
    9.     db01tmp=`ssh $masterdb "  /opt/mysql/product/5.5.25a/bin/mysql  -uroot  --password=""  -e "show slave statusG;" |grep -i Master_Host  "`;    
    10.     db01=`echo $db01tmp | awk '{print $2}'`  
    11.   
    12.     #3 begin to clear the old binlog   
    13.     ssh $db01 "/opt/mysql/product/5.5.25a/bin/mysql  -uroot  --password="" -e "purge master logs to '$log_file';""  
    14.   
    15.     #4 check the disk space for master  
    16.     ssh $db01 "df -h"  
    17.     echo " "  
    18.     echo " -- -- -- ";  
    19. done;  


    OK,run sh脚本 

    sh clearbinlog.sh 就可以开始清理所有db的binlog了。


    最后再次check disk space,执行check_disk.sh脚本,脚本内容如下:

     

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

    执行sh check_disk.sh开始check

  • 相关阅读:
    python—内置函数-filter,map,reduce
    python—模块-练习
    python—模块-re正则表达式
    python—模块-logging
    python—模块-subprocess
    python—模块-hashlib加密
    python—模块-configparser
    SpringBoot结合设计模式(观察者模式、策略模式)- 个人记录
    Spring事务-随笔
    Servlet、Tomcat、SpringMVC-整理-随笔
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/5741350.html
Copyright © 2011-2022 走看看