脚本作用:1、删除一个月前的errolog
2、按天分割slow日志,删除一个月前的slow日志
3、删除5分钟前的MD5,备份文件
5 7 * * * /home/mysql/scripts/logstatus.sh
- #!/bin/sh
-
DATE=`date +'%Y%m%d'`
-
LDATE=`date -d last-day +'%Y%m%d'`
-
lastmonth=`date -d last-month +'%Y%m%d'`
-
DATADIR=/data1/mysqldata/data
-
SLOWLOGDIR=/data/mysqllog/slowquery
-
DBBAK_DIR=/data/dbbak
-
MD5_DIR=/home/mysql/logs/logmd5
-
#####################
-
#errlog clear every month
-
#####################
-
vdate=`date +'%d'`
-
if [ $vdate -eq 11 ];then
-
cd $DATADIR
-
cp -f ${HOSTNAME}.err bak_${DATE}_${HOSTNAME}.err
-
:>${HOSTNAME}.err
-
rm -f bak_${lastmonth}_${HOSTNAME}.err
-
fi
-
#####################
-
#slowlog swith every day
-
#####################
-
cd $SLOWLOGDIR
-
cp -f slow-query.log ${LDATE}-slow.log
-
:>slow-query.log
-
rm -f ${lastmonth}-slow.log
-
######################
-
#MD5 clear every day
-
######################
-
cd $MD5_DIR
-
find -mtime +5 -name '*.md5' | xargs rm -f {}\;
-
#####################
-
#dbbak clear every day
-
######################
-
cd $DBBAK_DIR
-
find -mtime +5 -name 'bak_*' | xargs rm -f {}\;
阅读(3058) | 评论(0) | 转发(1) |