Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Can logrotate apply multiple rotate rules?
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Can logrotate apply multiple rotate rules?
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?
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?
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
You see the answer to my question there? Please tell me where...4D696B65 wrote:https://linux.die.net/man/8/logrotate
-
- Posts: 1394
- Joined: 2007-03-04 21:10
- Location: U.S.A. - WI.
Re: Can logrotate apply multiple rotate rules?
Read the man page. It's in there.
fortune -o
Your love life will be... interesting.
How did it know?
The U.S. uses the metric system too, we have tenths, hundredths and thousandths of inches
Your love life will be... interesting.
How did it know?
The U.S. uses the metric system too, we have tenths, hundredths and thousandths of inches
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
I already did.pendrachken wrote:Read the man page. It's in there.
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!
Re: Can logrotate apply multiple rotate rules?
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
Re: Can logrotate apply multiple rotate rules?
I believe you can't, as you would create conflicting actions.PsySc0rpi0n wrote: I can't fin any line saying "logrotate can apply multiple rules to a single file" or anything like that!
https://serverfault.com/questions/38810 ... -logrotate
so you would have to study the man pages and look for examples on the net.
https://www.thegeekstuff.com/2010/07/lo ... -examples/
https://linuxconfig.org/logrotate
https://www.tecmint.com/install-logrota ... -in-linux/
Debian 10 - Buster on Compulab Fitlet2
Debian 12 - Bookworm on Acer Spin 1
Debian 12 - Bookworm on Acer Spin 1
Re: Can logrotate apply multiple rotate rules?
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.
Most powerful FREE tech-support tool on the planet * HERE. *
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
I came across the first link from serverfault before coming here. But that's not the case.fred44nl wrote:I believe you can't, as you would create conflicting actions.PsySc0rpi0n wrote: I can't fin any line saying "logrotate can apply multiple rules to a single file" or anything like that!
https://serverfault.com/questions/38810 ... -logrotate
so you would have to study the man pages and look for examples on the net.
https://www.thegeekstuff.com/2010/07/lo ... -examples/
https://linuxconfig.org/logrotate
https://www.tecmint.com/install-logrota ... -in-linux/
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.
-
- Posts: 54
- Joined: 2013-07-23 08:23
Re: Can logrotate apply multiple rotate rules?
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.
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.
-
- Global Moderator
- Posts: 2709
- Joined: 2018-06-20 15:16
- Location: Colorado
- Has thanked: 41 times
- Been thanked: 201 times
Re: Can logrotate apply multiple rotate rules?
Follow this lead. I don't have a command list ready for you..L_V wrote:You have a logrotate service normally managed by systemd
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?
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
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!
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
Ok...CwF wrote:Follow this lead. I don't have a command list ready for you..L_V wrote:You have a logrotate service normally managed by systemd
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?
I'm not sure if "normally managed by systemd" means controlled by crontab or not.
But yeah going to take that route.
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
Hi again.
I'm back to this.
For some reason, my cron jobs are not running as supposed for logrotate.
I have a config file in /etc/logrotate.d/ to setup a rotation for a file.
Now, if I want to execute the rules in that config file inside /etc/logrotate.d/ hourly, what should I do? Add a file inside /etc/cron.hourly and put what inside it? Just `logrotate`or maybe /usr/sbin/logrotate` ??
I'm back to this.
For some reason, my cron jobs are not running as supposed for logrotate.
I have a config file in /etc/logrotate.d/ to setup a rotation for a file.
Now, if I want to execute the rules in that config file inside /etc/logrotate.d/ hourly, what should I do? Add a file inside /etc/cron.hourly and put what inside it? Just `logrotate`or maybe /usr/sbin/logrotate` ??
Re: Can logrotate apply multiple rotate rules?
so whats stopping you from using systemd.timer as opposed to cron?
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
I had this working with cron in that past. I see no need to change it now. I want to keep the thread focused in cron and logrotate if possible. After I get this working, I may try systemd.time or whatever that is.sickpig wrote:so whats stopping you from using systemd.timer as opposed to cron?
But in the meantime, I read a bit more and did the follwoing:
Created a file named 'myfile' in:
Code: Select all
/etc/logrotate.d
Code: Select all
/media/wdelements/debug.log {
rotate 5
daily
copytruncate
size 50M
dateext
dateformat -%d%m%Y
maxage 31
}
Code: Select all
/etc/cron.hourly
Code: Select all
#!/bin/bash
if [ -f /etc/logrotate.d/myfile ]; then
logrotate --verbose /etc/logrotate.d/myfile
else
echo "File not found!"
fi
- PsySc0rpi0n
- Posts: 322
- Joined: 2012-10-24 13:54
- Location: Bitcoin World
- Has thanked: 8 times
- Been thanked: 1 time
Re: Can logrotate apply multiple rotate rules?
I'm reviving this thread of mine.
In the meantime I had to re-install my Debian due to some hardware problems. I bought a new SSD because the old was was with hardware failures.
So, this said, I'm again trying to setup logrotate and cron/anacron. But I'm not sure I have this correctly set.
With anacron installed, cron jobs are kind of over ruled by anacron, if I understand correctly.
So, I added a file in /etc/logrotate.d/my-rotate-rules telling the rules I want for the file in question and I verified that inside /etc/anacrontab there are entreies to run cron jobs daily, weekly and monthly. So, I presume this is all I need.
Am I correct?
Edited:
I didn't remember my last post in this thread. I'll try to replicate it.
In the meantime I had to re-install my Debian due to some hardware problems. I bought a new SSD because the old was was with hardware failures.
So, this said, I'm again trying to setup logrotate and cron/anacron. But I'm not sure I have this correctly set.
With anacron installed, cron jobs are kind of over ruled by anacron, if I understand correctly.
So, I added a file in /etc/logrotate.d/my-rotate-rules telling the rules I want for the file in question and I verified that inside /etc/anacrontab there are entreies to run cron jobs daily, weekly and monthly. So, I presume this is all I need.
Am I correct?
Edited:
I didn't remember my last post in this thread. I'll try to replicate it.