我正在尝试在tomcat中运行logrotate以访问,hostmanager和manager日志。我在旋转后编写了以下脚本清空文件。除此之外,postrotate和preroate的删除和压缩工作正常。
/srv/www/tomcat/Container*/logs/access*
/srv/www/tomcat/Container*/logs/catalina.*.log
/srv/www/tomcat/Container*/logs/host-manager.*.log
/srv/www/tomcat/Container*/logs/localhost.*.log
/srv/www/tomcat/Container*/logs/manager.*.log
{
missingok
notifempty
daily
rotate 0
prerotate
/bin/find /srv/www/tomcat/Container*/logs/ -maxdepth 1 -mtime +2 -name "*.log" -exec gzip {} \; || true
endscript
postrotate
/bin/find /srv/www/tomcat/Container*/logs/ -mindepth 1 -mtime +10 -name "*.gz" -delete || true
endscript
}
答案 0 :(得分:0)
以下内容应该有效,压缩每个旋转的文件并使用maxage而不是find命令:
{
missingok
notifempty
daily
compress
maxage 12
}
如果你想在两天后压缩:
{
missingok
notifempty
daily
maxage 12
postrotate
/bin/find /srv/www/tomcat/Container*/logs/ -maxdepth 1 -mtime +2 -name "*.log.?" -exec gzip {} \;
endscript
}