Hourly rotation of files using logrotate?

99,308

Solution 1

The manpage of logrotate.conf contains an important advice for the hourly option:

Log files are rotated every hour. Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly.

As pointed out by yellow1pl the solution is to copy the file /etc/cron.daily/logrotate into the /etc/cron.hourly/ directory. This works at least for Debian and possibly some Debian derivates.

Solution 2

There is /etc/cron.daily/logrotate script for daily logrotates. However there is no such script by default in /etc/cron.hourly/ directory. Copy this script and it should work fine.

Share:
99,308
Kishore
Author by

Kishore

Updated on July 05, 2022

Comments

  • Kishore
    Kishore almost 2 years

    I tried to set up a log rotation of logs files located at /tmp/hr_logs/. For setting up, I used logrotate in linux and I'm able to rotate it on daily basis using the following config in my /etc/logrotate.conf

      /tmp/hr_logs {
      daily
      rotate 4
    

    With this config, file will rotate on daily basis and system will keep 4 copies of the log file appended with date [format: -YYYYMMDD]

    Now, I trying to set up a different set of log files which I need to make rotate on hourly basis and for it, i have done the configuration in logrotate.conf:

      /tmp/last_logs {
      hourly
      rotate 4
    

    But this is not at all working? Can anyone please guide me on this please?

  • Kishore
    Kishore over 9 years
    As suggested, I have copied logrotate under /etc/cron.hourly but no luck.
  • EminezArtus
    EminezArtus almost 9 years
    This also works in CentOS
  • f0ster
    f0ster almost 8 years
    @Kishore did you also use the "hourly" option? Make sure it is supported on your distro by reading the manpage on your OS, man logrotate
  • mulllhausen
    mulllhausen about 7 years
    wouldn't you want to move logrotate rather than copy? otherwise there will be a time when logrotate runs twice at the same time
  • cherdt
    cherdt about 7 years
    I found I had to restart the crond service after moving logrotate to /etc/cron.hourly. E.g. in CentOS 7 sudo systemctl restart crond
  • Mario Mey
    Mario Mey almost 7 years
    Copy or move the file? Also, shouldn't I change "daily" to "hourly" inside /etc/logrotate.conf?
  • krad
    krad over 6 years
    I would symlink as if the script gets updated you will inherit any changes. Also if you are using the dateext option you will need to reformat the extension so you can have multiple uniq filenames per day. I use the following. dateext dateformat -%Y%m%d-%s
  • Roland Pihlakas
    Roland Pihlakas over 3 years
    The command I used for symlink: ln -s /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
  • rvalue
    rvalue over 2 years
    @mulllhausen logrotate locks the state file by default and exits if the lock is already taken - so no there's no issue with being in both the cron.hourly and cron.daily schedules even if they run at the same moment.
  • Pankaj Rathi
    Pankaj Rathi about 2 years
    Hi, I'm using Cent OS, even after adding cron.hourly. I still don't see it working.