Is there a way to get logrotate to only compress files modified X number of days ago (e.g. mtime +2)
Asked
Active
Viewed 9,078 times
3 Answers
14
One option could be to use logrotate
to rotate to a different extension, then use logrotate
to rotate into compressed files:
/var/log/raw.log {
daily
nocompress
extension .old
}
/var/log/*.old {
daily
compress
delaycompress
rotate 10
}
This Rube Goldberg contraption will result in the following:
raw.log
raw.log.old
raw.log.old.1
raw.log.old.2.gz
raw.log.old.3.gz
Thus you have two archived days of logs which are uncompressed.

ManicDee
- 732
- 6
- 16
5
Well you can use delaycompress to wait one more cycle. Basically if you rotate daily then it will keep yesterdays logs uncompressed.
Besides that you could try not using logrotate to compress the files and write a bash script to run like once a day and compress all files older than a certain date.
Here is a tutorial to bash that I personally like: http://www.linuxconfig.org/Bash_scripting_Tutorial

Patrick
- 178
- 1
- 6
-1
Could you do something like the following?
/var/log/access.log {
daily
nocompress
}
/var/log/access.7.log {
daily
compress
}
I think that will give you something like
access.log
access.1.log
access.2.log
access.3.log
access.4.log
access.5.log
access.6.log
access.7.log.gz
access.8.log.gz
access.log
-
Any verdict? this looks awesome – Kevin Jan 11 '14 at 07:04
-
This is not working because the uncompress logs are not removed. A compressed version is just added. – Nicolas BADIA Aug 09 '14 at 06:59