Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

This is my logrotate config:

/var/log/messages {                                                                                              daily
    rotate 60
    /bin/kill -HUP `cat /var/run/ 2> /dev/null` 2> /dev/null || true    

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

So is there a way to make it compress ONLY the last 30 logs?

share|improve this question

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


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.