我有一个应用程序每天生成一个非常重的大日志文件(每天约800MB),因此我需要压缩它们,但由于压缩需要时间,我希望在将HUP信号重新加载/发送到应用程序后,该logrotate压缩该文件.
/var/log/myapp.log { rotate 7 size 500M compress weekly postrotate /bin/kill -HUP `cat /var/run/myapp.pid 2>/dev/null` 2>/dev/null || true endscript }
压缩发生在后旋后(已经是反直觉的)了吗?
如果没有任何人可以告诉我,如果可以这样做没有额外的命令脚本(一个选项或一些技巧)?
谢谢
托马斯
解决方法
后转脚本在压缩发生之前运行:从
logrotate的手册页
The next section of the config files defined how to handle the log file
/var/log/messages. The log will go through five weekly rotations before
being removed. After the log file has been rotated (but before the old
version of the log has been compressed),the command /sbin/killall -HUP
syslogd will be executed.
无论如何,您可以使用delaycompress选项将压缩推迟到下一轮.