使用shell检查并修复mysql数据库表的脚本
时间:2024-01-27 23:52:35
#!/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
标签:mysql,数据库,shell
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaScript使用canvas实现flappy bird全流程详解
2024-04-18 09:34:49
![](https://img.aspxhome.com/file/2023/2/136442_0s.gif)
python3 解决requests出错重试的问题
2021-02-05 10:26:27
![](https://img.aspxhome.com/file/2023/4/105794_0s.jpg)
Python在groupby分组后提取指定位置记录方法
2023-06-09 08:48:16
![](https://img.aspxhome.com/file/2023/7/95207_0s.jpg)
MySQL存储过程中使用动态行转列
2024-01-16 22:03:16
![](https://img.aspxhome.com/file/2023/3/116753_0s.jpg)
python 存储json数据的操作
2022-10-02 13:14:14
![](https://img.aspxhome.com/file/2023/2/82672_0s.png)
python中的生成器、迭代器、装饰器详解
2022-03-01 20:36:46
![](https://img.aspxhome.com/file/2023/5/117925_0s.png)
浅谈Django学习migrate和makemigrations的差别
2021-05-11 03:36:11
部署ASP.NET Core程序到Windows系统
2024-05-09 09:04:38
![](https://img.aspxhome.com/file/2023/5/129805_0s.jpg)
mysql 分页优化解析
2024-01-15 00:33:40
python实现将range()函数生成的数字存储在一个列表中
2021-12-19 08:01:51
![](https://img.aspxhome.com/file/2023/8/93498_0s.gif)
使用Python的Flask框架表单插件Flask-WTF实现Web登录验证
2021-03-31 12:42:31
![](https://img.aspxhome.com/file/2023/0/77710_0s.jpg)
mint-ui在vue中的使用示例
2023-07-02 16:52:17
![](https://img.aspxhome.com/file/2023/8/139808_0s.png)
Python中Requests-get方法的使用
2021-05-31 08:35:31
![](https://img.aspxhome.com/file/2023/0/133810_0s.png)
用Python Turtle画棵樱花树送给自己
2022-06-30 10:16:47
![](https://img.aspxhome.com/file/2023/8/88968_0s.jpg)
pandas读取csv文件,分隔符参数sep的实例
2021-05-03 11:38:58
使用DIV+CSS设计网页的好处
2007-10-14 15:02:00
python字典DICT类型合并详解
2023-01-03 07:37:12
![](https://img.aspxhome.com/file/2023/7/82757_0s.jpg)
比较规范的验证Email地址是否正确的正则表达式
2009-07-28 17:55:00
如何在Cloud Studio上执行Python代码?
2023-12-23 02:12:15
![](https://img.aspxhome.com/file/2023/9/97289_0s.png)
js 上传文件预览的简单实例
2024-06-05 09:11:59