zoukankan      html  css  js  c++  java
  • MySQL--运维内参中的binlog_summary脚本

    #!/bin/bash
    ##===================================================##
    ## 脚本出自《MySQL运维内参》
    ##===================================================##
    BINLOG_EXE="/export/servers/mysql/bin/mysqlbinlog"
    BINLOG_FILE="/export/data/mysql/data/mysql-bin.000002"
    START_TIME="2015-01-21 00:00:00"
    STOP_TIME="2019-01-01 00:00:00"
    OUTPUT_FILE="/tmp/binlog_summary.txt"
    "${BINLOG_EXE}" --base64-output=decode-rows -vv --start-datetime="${START_TIME}"  --stop-datetime="${STOP_TIME}" ${BINLOG_FILE} | awk 
    'BEGIN {xid="null";s_type=""; stm="";endtm="";intsta=0;inttal=0;s_count=0;count=0;insert_count=0;update_count=0;delete_count=0;flag=0;bf=0;period=0;} 
    {
    if (match($0, /^(BEGIN)/)) {bg=1;} 
    if (match($0, /#.*server id/)) {if(bg==1){statm=substr($1,2,6)" "$2;cmd=sprintf("date -d "%s" +%%s", statm);cmd|getline intsta;close(cmd);bg=0;bf=1;}else if(bf==1){endtm=substr($1,2,6)" "$2;cmd=sprintf("date -d "%s" +%%s", endtm);cmd|getline inttal;close(cmd);}} 
    if(match($0, /#.*Table_map:.*mapped to number/)) {printf "Timestamp : " $1 " " $2 " Table : " $(NF-4); flag=1} 
    else if (match($0, /#.*Xid =.*/)) {xid=$(NF)} 
    else if (match($0, /(### INSERT INTO .*..*)/)) {count=count+1;insert_count=insert_count+1;s_type="INSERT"; s_count=s_count+1;}  
    else if (match($0, /(### UPDATE .*..*)/)) {count=count+1;update_count=update_count+1;s_type="UPDATE"; s_count=s_count+1;} 
    else if (match($0, /(### DELETE FROM .*..*)/)) {count=count+1;delete_count=delete_count+1;s_type="DELETE"; s_count=s_count+1;}  
    else if (match($0, /^(# at) /) && flag==1 && s_count>0) {print " Query Type : "s_type " " s_count " row(s) affected" ;s_type=""; s_count=0; }  
    else if (match($0, /^(COMMIT)/)) {period=inttal-intsta;if(inttal==0){period=0};print "[Transaction total : " count " Insert(s) : " insert_count " Update(s) : " update_count " Delete(s) : " 
    delete_count " Xid : "xid" period : "period" ] 
    +----------------------+----------------------+----------------------+----------------------+"; 
    count=0;insert_count=0;update_count=0; delete_count=0;s_type=""; s_count=0; flag=0;bf=0;bg=0;} } ' 
    1 > "${OUTPUT_FILE}" 2>&1 
    
    if [ $? -eq 0 ]
    then
        echo "success,please see result in ${OUTPUT_FILE}"
    else
        echo "failed,please see result in ${OUTPUT_FILE}"
    fi
  • 相关阅读:
    不同权限访问详细细节
    文件搜索器
    java中依赖、关联、聚合
    子类重写父类成员方法
    java中子类对父类中的私有变量和私有方法有拥有权无使用权
    shell脚本在CentOS7自动更包
    LR虚拟用户已设置集合点,但controller无法设置集合点策略的解决方案
    LR工具使用之场景设置
    LR集合点策略
    LR录制附件上传后,回放报错
  • 原文地址:https://www.cnblogs.com/TeyGao/p/9077812.html
Copyright © 2011-2022 走看看