#!/bin/bash
# 日志文件路径、存档目录
log_path="/package/mysqldata"
archive_directory="/package/mysqldata/archive"
mkdir -p ${archive_directory}
# 移动日志文件到存档目录
mv ${log_path}/general.log ${archive_directory}/general_$(date +%Y%m%d_%H%M%S).log
# 连接MySQL执行FLUSH LOGS命令
mysql -uroot -pPwd123 -e "FLUSH LOGS"
# 删除历史日志文件超过30天的
find ${archive_directory} -name "general_*" -mtime +30 -exec rm {} \;