Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hourly rotation of files using logrotate? [closed]

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?

like image 577
Kishore Avatar asked Aug 25 '14 11:08

Kishore


People also ask

How do you logrotate per hour?

Frequency hourly 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. daily Log files are rotated every day.

How often does logrotate run?

This command tells logrotate to check all the logs for that configuration block before running the postrotate script. If one or both of the logs is rotated, the postrotate script runs only once.

What is logrotate timer?

Logrotate allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file daily, weekly, monthly or when the log file gets to a certain size.

What is Sharedscripts in logrotate?

The sharedscripts means that the postrotate script will only be run once (after the old logs have been compressed), not once for each log which is rotated. Note that the double quotes around the first filename at the beginning of this section allows logrotate to rotate logs with spaces in the name.


1 Answers

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.

like image 52
scai Avatar answered Sep 20 '22 21:09

scai