Hourly rotation of files using logrotate?
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.
Kishore
Updated on July 05, 2022Comments
-
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 over 9 yearsAs suggested, I have copied logrotate under /etc/cron.hourly but no luck.
-
EminezArtus almost 9 yearsThis also works in CentOS
-
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 about 7 yearswouldn't you want to move
logrotate
rather than copy? otherwise there will be a time when logrotate runs twice at the same time -
cherdt about 7 yearsI found I had to restart the
crond
service after movinglogrotate
to/etc/cron.hourly
. E.g. in CentOS 7sudo systemctl restart crond
-
Mario Mey almost 7 yearsCopy or move the file? Also, shouldn't I change "daily" to "hourly" inside /etc/logrotate.conf?
-
krad over 6 yearsI 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 over 3 yearsThe command I used for symlink:
ln -s /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
-
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 thecron.hourly
andcron.daily
schedules even if they run at the same moment. -
Pankaj Rathi about 2 yearsHi, I'm using Cent OS, even after adding cron.hourly. I still don't see it working.