shell检查并修复mysql数据库表

前端之家收集整理的这篇文章主要介绍了shell检查并修复mysql数据库表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/sh
#code by scpman
#功能:检查并修复MysqL数据库表
#将此脚本加到定时中,脚本执行时,等会读库,列出要修复的所有表,然后计时,开始修复
#修复过程中将损坏的表记录下来,修复完成后,将损坏的表,发邮件通知。
fix_logs='/tmp/fix.log'
user=''
pass=''
check_fix()
{
dblist=`/usr/bin/find /usr/dlm_db/MysqL/ -type d | grep -vE "logs|_[1-9]|*bak|test"| sed -e "s#/usr/dlm_db/MysqL/##g"`
echo start `date`>$fix_logs
for dbname in $dblist
do
echo $dbname
for tb_name in `/usr/bin/find  /usr/dlm_db/MysqL/$dbname -type f | awk -F'/' '{print $NF}' | awk -F'.' '{print $1}' | sort -
u`
do
MysqL -u$user -p$pass  $dbname<<fff>>$fix_logs
check table $tb_name;
repair table $tb_name;
FFF
done
done
echo `date` done>>$fix_logs
}
send_logs()
{
msgip=10.0.7.44
IP=`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p `
fix_info=`grep -rE "Error|start|done" $fix_logs`
/usr/bin/logger -p local1.info -h $msgip "the services: $IP MysqL_table_fix_info:$fix_info"
}
check_fix
send_logs
原文出处http://www.scpman.com/article/show/19/?classid=10

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章