Can logrotate apply multiple rotate rules?

New to Debian (Or Linux in general)? Ask your questions here!

Can logrotate apply multiple rotate rules?

Postby PsySc0rpi0n » 2019-08-16 21:50

Hello.

Here I am again.
Usually I come here after trying to search in my preferred search engine. But most of the times, either if it's me that can't search properly by providing better search words and/or patterns or because there isn't really much about my search, fact is that I can't find answers to another question of mine.

I have a pretty big debug.log file I need to control how much space it uses. At this moment it's using over 500MB on my drive.
So, I search about how to deal with this and I came across logrotate.

My goal is to rotate the debug.log file in a regular daily basis OR based on size it is using in the drive. So I have 2 conditions to trigger the rotation. Is this possible directly with logrotate or do I need to write small bash script to take care of one of the tasks?
User avatar
PsySc0rpi0n
 
Posts: 109
Joined: 2012-10-24 13:54
Location: Portugal

Re: Can logrotate apply multiple rotate rules?

Postby 4D696B65 » 2019-08-16 21:54

User avatar
4D696B65
 
Posts: 2429
Joined: 2009-06-28 06:09

Re: Can logrotate apply multiple rotate rules?

Postby PsySc0rpi0n » 2019-08-16 22:01



You see the answer to my question there? Please tell me where...
User avatar
PsySc0rpi0n
 
Posts: 109
Joined: 2012-10-24 13:54
Location: Portugal

Re: Can logrotate apply multiple rotate rules?

Postby pendrachken » 2019-08-17 00:18

Read the man page. It's in there.
fortune -o
Your love life will be... interesting.
:twisted: How did it know?

The U.S. uses the metric system too, we have tenths, hundredths and thousandths of inches :-P
pendrachken
 
Posts: 1350
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Re: Can logrotate apply multiple rotate rules?

Postby PsySc0rpi0n » 2019-08-17 10:18

pendrachken wrote:Read the man page. It's in there.


I already did.
I can't fin any line saying "logrotate can apply multiple rules to a single file" or anything like that!

How would you configure logrotate to perform a rotation based on 1 of 2 rules? And how you say which of the rules to apply first? Or even if you try (by chance) to add 2 rules to see if it works the way you intend to, how do you know to which of the rules the rotation is applied?

None of this questions are explicitly answered there. Otherwise, quote it here!

The man pages don't reply questions like these ever. They explain general usage. Much more can be done "outside" the man pages!
User avatar
PsySc0rpi0n
 
Posts: 109
Joined: 2012-10-24 13:54
Location: Portugal

Re: Can logrotate apply multiple rotate rules?

Postby L_V » 2019-08-17 10:28

You have a logrotate service normally managed by systemd

Code: Select all
systemd-analyze blame | grep logrotate

systemctl status logrotate.service

systemctl cat logrotate.service
L_V
 
Posts: 1047
Joined: 2007-03-19 09:04

Re: Can logrotate apply multiple rotate rules?

Postby fred44nl » 2019-08-17 10:41

PsySc0rpi0n wrote:I can't fin any line saying "logrotate can apply multiple rules to a single file" or anything like that!


I believe you can't, as you would create conflicting actions.

https://serverfault.com/questions/388105/how-can-i-specify-multiple-rules-for-a-particular-log-files-with-logrotate

so you would have to study the man pages and look for examples on the net.

https://www.thegeekstuff.com/2010/07/logrotate-examples/
https://linuxconfig.org/logrotate
https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/
Debian 9.9 on Compulab Fitlet2
User avatar
fred44nl
 
Posts: 162
Joined: 2018-07-14 08:54

Re: Can logrotate apply multiple rotate rules?

Postby Deb-fan » 2019-08-17 18:07

Think you somewhat answered your own question or headed in a good direction. Something like a script + anacron or cron to set whatever schedule you want. Don't have a ready made script or command. Yep will have to take up the specifics with Google and hands on experimentation. Good luck.
Deb-fan
 
Posts: 273
Joined: 2012-08-14 12:27

Re: Can logrotate apply multiple rotate rules?

Postby PsySc0rpi0n » 2019-08-17 21:59

fred44nl wrote:
PsySc0rpi0n wrote:I can't fin any line saying "logrotate can apply multiple rules to a single file" or anything like that!


I believe you can't, as you would create conflicting actions.

https://serverfault.com/questions/388105/how-can-i-specify-multiple-rules-for-a-particular-log-files-with-logrotate

so you would have to study the man pages and look for examples on the net.

https://www.thegeekstuff.com/2010/07/logrotate-examples/
https://linuxconfig.org/logrotate
https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/


I came across the first link from serverfault before coming here. But that's not the case.
Second link, the same. I read it. Not the same I need though. The geekstuff one
Third link is new to me but also don't have what I need.. The linuxconfig one.
An I also read the last link. Not what I need either.

I appreciate the effort, I really do.
When I come here I have already did some research.

The multiple rules I need were never mixed on any of those links. I mean like to rotate based on "daily" rule OR "size" rule. Whichever is met first! Meaning that I want a lof file to change name or daily or if it reaches 50MB before a day is gone.
User avatar
PsySc0rpi0n
 
Posts: 109
Joined: 2012-10-24 13:54
Location: Portugal

Re: Can logrotate apply multiple rotate rules?

Postby kreemoweet » 2019-08-18 05:58

Logrotate will not perform real-time monitoring of a log file's size, but you can run logrotate as often as needed as a cron job.
The "daily" rotation parameter for the file can be included in the usual logrotate.conf, and the "size 50M" parameter can be included
in a special logrotate conf file, specified in the cron logrotate command, that applies only to the debug log.
kreemoweet
 
Posts: 52
Joined: 2013-07-23 08:23

Re: Can logrotate apply multiple rotate rules?

Postby CwF » 2019-08-18 13:22

L_V wrote:You have a logrotate service normally managed by systemd

Follow this lead. I don't have a command list ready for you..
but no need for more than 1 rule per step.
1 Limit log size, start new file at limit
2. set to compress those past logs
3. limit the number of compressed logs

Oh ya, Issue #1 = What is spamming your logs?
CwF
 
Posts: 446
Joined: 2018-06-20 15:16

Re: Can logrotate apply multiple rotate rules?

Postby PsySc0rpi0n » 2019-08-24 09:05

kreemoweet wrote:Logrotate will not perform real-time monitoring of a log file's size, but you can run logrotate as often as needed as a cron job.
The "daily" rotation parameter for the file can be included in the usual logrotate.conf, and the "size 50M" parameter can be included
in a special logrotate conf file, specified in the cron logrotate command, that applies only to the debug log.



I'm going to start researching about this option.

Thanks for the tip!
User avatar
PsySc0rpi0n
 
Posts: 109
Joined: 2012-10-24 13:54
Location: Portugal

Re: Can logrotate apply multiple rotate rules?

Postby PsySc0rpi0n » 2019-08-24 09:07

CwF wrote:
L_V wrote:You have a logrotate service normally managed by systemd

Follow this lead. I don't have a command list ready for you..
but no need for more than 1 rule per step.
1 Limit log size, start new file at limit
2. set to compress those past logs
3. limit the number of compressed logs

Oh ya, Issue #1 = What is spamming your logs?


Ok...

I'm not sure if "normally managed by systemd" means controlled by crontab or not.
But yeah going to take that route.
User avatar
PsySc0rpi0n
 
Posts: 109
Joined: 2012-10-24 13:54
Location: Portugal


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 12 guests

fashionable