logrotate: 打开 <log>.gz 时出错

logrotate: error opening <log>.gz

我现在正在 ubuntu 上设置 logrotate 以轮转日志。这是我的配置:

/etc/logrotate.d/test:

/var/log/test/*.log{
  weekly
  rotate 7
  compress
  delaycompress
  notifempty
  create 640 testuser testgroup
}

在 /var/log/test 中,它有以下测试日志文件:

-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-01.log
-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-02.log
-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-03.log
-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-04.log
-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-05.log
-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-06.log
-rw-r--r--  1 testuser testgroup 39 四月  1 00:00 2018-04-08.log
-rw-r--r--  1 testuser testgroup 0 四月  1 00:00 2018-04-09.log
-rw-r--r--  1 testuser testgroup 391938 四月  1 00:00 scheduler.log

当我运行logrotate -d -v test时,它告诉我没有所有日志不需要旋转:

reading config file zctest

Handling 1 logs

rotating pattern: /var/log/test/*.log  weekly (7 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/test/2018-04-01.log
  log does not need rotating
considering log /var/log/test/2018-04-02.log
......
considering log /var/log/test/2018-04-02.log

当我 运行 logrotate -d -v test -f 时,它给我如下错误:

renaming /var/log/KeyServer/2018-04-08.log.1.gz to 
/var/log/KeyServer/2018-04-08.log.2.gz (rotatecount 7, logstart 1, i 1), 
renaming /var/log/KeyServer/2018-04-08.log.0.gz to 
/var/log/KeyServer/2018-04-08.log.1.gz (rotatecount 7, logstart 1, i 0), 
renaming /var/log/KeyServer/2018-04-08.log to /var/log/KeyServer/2018-04-08.log.1
creating new /var/log/KeyServer/2018-04-08.log mode = 0640 uid = 1000 gid = 1000
removing old log /var/log/KeyServer/2018-04-08.log.8.gz
error: error opening /var/log/KeyServer/2018-04-08.log.8.gz: No such file or directory

谁能帮我解决这个问题?

我不知道你的 logrotate.conf 文件中是否有 missingok 作为默认参数,但没有它,logrotate 会抱怨那些丢失的文件。见 man logrotate:

missingok

If the log file is missing, go on to the next one without issuing an error message.