Logrotate daily/weekly/monthly

11,926

The relationship between crond and logrotate is fairly simple: cron runs logrotate once a day (see /etc/cron.daily/logrotate), and logrotate then decides what to do based on the configuration files. Your specific question regarding monthly is clarified in the logrotate(8) manpage:

monthly
Log files are rotated the first time logrotate is run in a month (this is normally on the first day of the month).

The effect of your config is that logfiles will grow over a month, and once a new month is started, logrotate will rename and then compress any non-zero-sized files that match the filespec you supplied.

Finally, if you use logrotate -f, logrotate will rotate the logs, regardless of the period set in the configuration. If you aren't using a distro-supplied cronjob, then remember not to supply -f.

(Note this answer assumes Debian and Ubuntu, as that's what I'm able to test easily on, but should apply more generally).

Share:
11,926
ilya_direct
Author by

ilya_direct

Updated on June 04, 2022

Comments

  • ilya_direct
    ilya_direct almost 2 years

    Why are we setting daily/weekly/monthly option in config file, if we can do it in cron (and actually do)? What is the sense of this option ?

    For example: I set to execute "logrotate -f /etc/logrotate.d/app" every day(daily). But in config file (/etc/logrotate.d/app) I'll set weekly:

    /home/dirnov/www/letsee/logs/*.log {
            monthly
            missingok
            rotate 4
            compress
            notifempty
    }
    

    And I see that there is no sense of "monthly", because cron will do it "daily".