有些文件被压缩为 1.gz
/var/log/apt/history.log.1.gz
/var/log/apt/term.log.1.gz
/var/log/mosquitto/mosquitto.log.1.gz
/var/log/mysql/error.log.1.gz
有些没有压缩,第一层第二层是2.gz
/var/log/apache2/access.log.1
/var/log/apache2/error.log.1
/var/log/apache2/other_vhosts_access.log.1
/var/log/dbconfig-common/dbc.log.1
/var/log/exim4/mainlog.1
/var/log/letsencrypt/letsencrypt.log.1
我有时会在邮件中收到错误消息:
/etc/cron.daily/logrotate:
error: Compressing program wrote following message to stderr
when compressing log /var/log/mosquitto/mosquitto.log.1:
gzip: stdin: file size changed while zipping
因为 mosquitto 显然在旋转日志时将其写入日志。
rotate 脚本是 debian 默认安装的:
/var/log/mosquitto/mosquitto.log {
rotate 7
daily
compress
size 100k
nocreate
missingok
postrotate
/usr/bin/killall -HUP mosquitto
endscript
}
我也更喜欢未压缩的最新日志。
答案1
我认为我已经找到了解决方案:其他脚本包含关键字
delayrotate
据该男子说,这将延迟压缩一个周期。
答案2
您缺少这个重要的选项来避免在压缩阶段更改文件:
copytruncate