Logrotate

一些日誌旋轉到 log.1 一些到 log.1.gz

  • December 4, 2017

一些文件被壓縮到 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 在旋轉時似乎會寫入日誌。

旋轉腳本是 debian 預設安裝的:

/var/log/mosquitto/mosquitto.log {
   rotate 7
   daily
   compress
   size 100k
   nocreate
   missingok
   postrotate
           /usr/bin/killall -HUP mosquitto
   endscript
}

我也更喜歡未壓縮的最新日誌。

我想我找到了解決方案:其他腳本包含關鍵字

delayrotate

據該男子稱,它會將壓縮延遲一個週期。

您錯過了這個重要的選項,以避免在壓縮階段更改文件:

copytruncate

引用自:https://serverfault.com/questions/886411