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.

I need to make daily rotate /var/log/messages to be kept for 60 days, last 30 logs must be compressed with bzip2.

That's my logrotate config:

/var/log/messages {                                                                                              daily
    rotate 60
    postrotate
    /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true    
    endscript 
}

but result is keeping last 60 daily not compressed logs. If add compress, then all 60 logs will be compressed

So is there a way do make compress ONLY LAST 30 logs?

share|improve this question

1 Answer 1

I think there is no such option for logrotate to do it directly. Only one relevant option is delaycompress which delay the compression by one log rotate cycle (one day in your case). Possibly, you can make use of the compresscmd option by writing a shell script to check how many log files you have so far and compress/uncompress the files you want.

Another possibility is to schedule a daily cron job to run a script to check your log files and compress/uncompress what you want.

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.