Logrotate 每日轮换,但应该每周轮换

Logrotate 每日轮换,但应该每周轮换

由于某种原因,logrotate 每天轮换一次日志,而不是每周轮换一次,尽管 logrotate 的所有配置文件似乎都设置为每周轮换一次。有什么想法吗?

/etc/cron.daily/logrotate

#!/bin/sh

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

/etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
    missingok
    monthly
    create 0664 root utmp
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0660 root utmp
    rotate 1
}


# system-specific logs may be configured here

/etc/logrotate.d/apache

/var/log/apache2/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
                        /etc/init.d/apache2 reload > /dev/null
                fi
        endscript
}

答案1

请注意这一行/etc/logrorate.conf

include /etc/logrotate.d

也许您在该目录中有一些陈旧或备份的文件,这些文件被包含在内,并指定每日轮换?

作为一种解决方法,如果您仍然无法弄清楚,并且如果您只希望每周轮换一次文件,那么您可以通过logrotatecron 更改执行的频率,从而将日志轮换的精度从每日更改为每周。

答案2

您必须手动强制旋转以便重新加载配置:

sudo logrotate -f /etc/logrotate.conf

另外...不要强迫它在你的 crontab 上,保持它没有标志:

#logrotate
0  0    * * *   /usr/sbin/logrotate /etc/logrotate.conf

相关内容