Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to get logrotate to keep the last week of logs in the current file?

for example :

errors.log contains 30 days of logs

after log rotate executes , I would have :

errors.log with the last 7 days of log

and

errors.log.1.gz compressed with the 23 other days.

Is that possible?

share|improve this question
    
Logrotate doesn't provide for this directly. You could write a small script to do it, but it would have to be able to parse the log format and filter out entries older than your threshold. (if there's no timestamp on the log lines, this would be impossible) Can I ask why you'd want to do it this way? –  SmallClanger Sep 1 '11 at 8:41

1 Answer 1

weekly
rotate 4
compress

followed by a postrotate script doing something like (untested):

TMP=$(mktemp)
zcat /var/log/errors.log.{4,3,2,1}.gz > $TMP
mv $TMP /var/log/errors.log.1
gzip /var/log/errors.log.1

Cheers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.