Home > Database > Mysql Tutorial > 实战:mysql检查物理磁盘中的二进制日志文件是否有丢失_MySQL

实战:mysql检查物理磁盘中的二进制日志文件是否有丢失_MySQL

WBOY
Release: 2016-06-01 13:08:25
Original
834 people have browsed it

场景:有时候因为磁盘损坏或人为原因错误删除了磁盘中的二进制文件,导致mysql中的show binary logs记录和实际的物理磁盘中的二进制文件不匹配

#binlogdiff.sh
#!/bin/sh
#ocpyang@126.com
#作用:mysql中show binary logs记录的二进制日志文件和实际的物理文件比较,检查
#磁盘中对应的二进制日志文件是否有丢失

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 binary logs记录的日志文件
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}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template