How to make logrotate keep the last week into the current .log

log-fileslogrotate

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?

Best Answer

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.