logrotate - compression files modified x number of days

user353829 picture user353829 · Dec 21, 2010 · Viewed 7.2k times · Source

Is there a way to get logrotate to only compress files modified X number of days ago (e.g. mtime +2)

Answer

ManicDee picture ManicDee · Apr 27, 2012

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.