檢查並修復mysql數據庫表
01
#!/bin/sh
02
#code by scpman
03
#功能:檢查並修復mysql數據庫表
04
#將此腳本加到定時中,腳本執行時,等會讀庫,列出要修復的所有表,然後計時,開始修復
05
#修復過程中將損壞的表記錄下來,修復完成後,將損壞的表,發郵件通知。
06
fix_logs='/tmp/fix.log'
07
user=''
08
pass=''
09
check_fix()
10
{
11
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"`
12
echo start `date`>$fix_logs
13
for dbname in $dblist
14
do
15
echo $dbname
16
for tb_name in `/usr/bin/find /usr/dlm_db/mysql/$dbname -type f | awk -F'/' '{print $NF}' | awk -F'.' '{print $1}' | sort -
17
u`
18
do
19
mysql -u$user -p$pass $dbname<<fff>>$fix_logs
20
check table $tb_name;
21
repair table $tb_name;
22
FFF
23
done
24
done
25
echo `date` done>>$fix_logs
26
}
27
send_logs()
28
{
29
msgip=10.0.7.44
30
IP=`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p `
31
fix_info=`grep -rE "Error|start|done" $fix_logs`
32
/usr/bin/logger -p local1.info -h $msgip "the services: $IP mysql_table_fix_info:$fix_info"
33
}
34
check_fix
35
send_logs