创建历史日志保存目录
/data/log/hislog
准备日志切割脚本
more /home/mysql/scripts/cut_general_log.sh
#!/bin/bash
setEnv()
{
USER=root
USER_PWD=123456
SOCKET=/tmp/mysql.sock
TIME=`date +"%Y%m%d%H%M"`
GENERAL_LOG=/data/log/node1.log
GENERAL_LOG_HIS=/data/log/hislog
}
cutLog()
{
if [ ! -d $GENERAL_LOG_HIS ];then
mkdir -p $GENERAL_LOG_HIS
fi
mv $GENERAL_LOG $GENERAL_LOG_HIS/node1.log.${TIME}
/usr/local/mysql/bin/mysqladmin -u$USER -p$USER_PWD --socket=$SOCKET flush-logs general
cd $GENERAL_LOG_HIS
tar -zcvf node1.log.${TIME}.tar.gz node1.log.${TIME} --remove-files
}
setEnv
cutLog
#不要忘记添加执行权限
chmod +x /home/mysql/scripts/cut_general_log.sh
创建定时任务
crontab -e
00 00 * * * /home/mysql/scripts/cut_general_log.sh