Actual combat: MySQL check for missing binary log files in physical disk

Source: Internet
Author: User

Scenario: Sometimes the binary files in the disk are deleted due to disk corruption or human error, resulting in a mismatch between the show binary logs record in MySQL and the binary file in the actual physical disk

#binlogdiff. Sh
#!/bin/sh
#[email protected]
#作用: MySQL show binary logs recorded binary log file and actual physical file comparison, check
#磁盘中对应的二进制日志文件是否有丢失

Source/usr/local/mysql/scripts/mysql_env.ini
Binlog_init=tmpinit. ' Date +%y%m%d%h%m%s '. txt
Binlog_midd=tmpmidd. ' Date +%y%m%d%h%m%s '. txt #mysql中show log file for binary logs records
Binlog_res=tmpres. ' Date +%y%m%d%h%m%s '. txt #binlog物理磁盘路径中的日志文件

MY_CNF=/USR/LOCAL/MYSQL/MY.CNF #mysql的配置文件
Log_bin_path= ' Grep-i "^log-bin" $my _cnf |cut-d =-F 2 '
Log_bin= ' dirname $log _bin_path '

#lookup Binlog Records in MySQL
Mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-e "show binary logs;" >${binlog_init}
Cat ${binlog_init} | Cut-f 1 |cut-d. -F 2 |grep-i ' ^[0-9] ' |sort-n >${binlog_midd}


#lookup Binlog Records in Disk
Ls-t ${log_bin}| grep ' ^mysql-bin ' |cut-d. -F 2 |grep-i ' ^[0-9] ' |sort-n >${binlog_res}

Diff-c ${binlog_midd} $binlog _res

#clean temp File
RM-RF ${binlog_init}
RM-RF ${binlog_midd}
RM-RF ${binlog_res}


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.