2

I have a logrotate policy which runs once daily as it is part of cron.daily. I want to trigger logrotate for files when the reach a certain size. So i am looking for a way to make file size the trigger, rather than it happening at hourly, daily or some set interval of time. Is it possible to do something like that?

Example for one file (I have many such files with different size value)

/var/log/folder/localhost.access {
    size 500M
    copytruncate
    create somestr somestr
    dateext
    rotate 5
    compress
    missingok
}
maverick
  • 549
  • 2
  • 10
  • 18

1 Answers1

1

Yes it's correct, you can use the policy configuration file you posted to rotate based on limit size.

Youssef NAIT
  • 1,362
  • 11
  • 27
  • 1
    True. When i submit the policy i have mentioned above to say cron.daily folder, the rotation runs once per day (By default 6:25 AM every day). So imagine a scenario where the localhost.access file grows to 2GB within next day 6:25 AM. The rotation would not occur until 6:25AM even though the file went beyond 500M. I want to ensure that once the file hits 500M, there is an instantaneous rotation that happens. That way rotation is more on demand (when 500M is hit) versus on a time interval basis (checking at specific time interval if size limit is hit or not). – maverick Mar 16 '16 at 21:40
  • Have you thought about submitting the policy to cron.hourly ? – Youssef NAIT Mar 17 '16 at 11:03
  • As of now i just created a cron job that runs every 5 hours. 0 0/5 * * * /etc/logrotate Hourly is too aggressive and Daily rotation is too slow. But, the advantage of size based rotation versus time interval based rotation is that if there is no activity and the log file does not grow for days we are good and if there is lot of activity and the log file grows at a fast pace, then just hitting the size limit no matter how quickly that happens will ensure rotation at 500M in this case. – maverick Mar 18 '16 at 00:07