Logrotate - understand and implement correctly
by Micik from LinuxQuestions.org on (#6E13R)
Hello,
I'm having a hard time understanding why my logrotate implementation is not behaving as it should be.
There is an application that produces log files that can grow very big in size, so I decided to use logrotate functionality in Linux Mint 20, to keep this log file small.
The application writes to the file called app.log. I want to keep the size of the file about 1K (this is just for the purpose of testing, otherwise is 100M). I also want to have rotate possibility, so additional app.log.1 file is allowed.
So this is what I have done so far.
First, I created the .conf file in the logrotat.d directory:
Code:/home/user_AMA/logs/app.log {
copytruncate
rotate 1
size 10k
}And I put this into cronetab:
Code:*/2 * * * * /usr/sbin/logrotate -vf /etc/logrotate.d/app_log.confThis will execute every 2 minutes and I choose 2 mins only for testing.
Now, I have noticed that size 10K doesn't mean much. Since it is in the crontab, defined as a crone job, logrotate command will indeed execute every 2 minutes, it will rotate the files i.e. create app.log.1 from app.log and app.log is now zero bytes.
This works like every two minutes it just rotates files and clear the current one.
How to modify conf file to execute only if the log size is greater in size than some value (in this test case is 10k)?
Thank you.
I'm having a hard time understanding why my logrotate implementation is not behaving as it should be.
There is an application that produces log files that can grow very big in size, so I decided to use logrotate functionality in Linux Mint 20, to keep this log file small.
The application writes to the file called app.log. I want to keep the size of the file about 1K (this is just for the purpose of testing, otherwise is 100M). I also want to have rotate possibility, so additional app.log.1 file is allowed.
So this is what I have done so far.
First, I created the .conf file in the logrotat.d directory:
Code:/home/user_AMA/logs/app.log {
copytruncate
rotate 1
size 10k
}And I put this into cronetab:
Code:*/2 * * * * /usr/sbin/logrotate -vf /etc/logrotate.d/app_log.confThis will execute every 2 minutes and I choose 2 mins only for testing.
Now, I have noticed that size 10K doesn't mean much. Since it is in the crontab, defined as a crone job, logrotate command will indeed execute every 2 minutes, it will rotate the files i.e. create app.log.1 from app.log and app.log is now zero bytes.
This works like every two minutes it just rotates files and clear the current one.
How to modify conf file to execute only if the log size is greater in size than some value (in this test case is 10k)?
Thank you.