2

For some reason logrotate is rotating logs daily instead of weekly, even though all the config files for logrotate seem to be set to weekly. Any ideas?

/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
  • I'm having the exact same problem, were you able to solve it? Apr 19, 2016 at 15:39

2 Answers 2

1

Notice this line in /etc/logrorate.conf:

include /etc/logrotate.d

Perhaps you have some stale or backup files lying around in that directory, which get included, and specify daily rotation?

As a workaround, and if you still can't figure it out, and if you only ever want to have your files rotated weekly, then you can change the frequency with which logrotate is executed through cron, thus changing the precision of log rotation from daily to weekly.

2
  • 1
    The program-specific logrotate files in /etc/logrotate.d are actually what I want to run, my particular interest in this case being the Apache logrotate config file I posted above. There is only one apache file in that directory. No forgotten backups. Also, I'm trying to avoid using cron.weekly for this, as the impression I get is that that violates best practices. Mar 26, 2013 at 17:06
  • For me, in /etc/logrotate.d/apache2, the rotation was configured to occur daily. Apr 24, 2019 at 1:15
0

You have to force a rotation manually so it reloads the configuration:

sudo logrotate -f /etc/logrotate.conf

Also... don't force it on your crontab, there keep it without flags:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .