3

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
    postrotate
    /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true    
    endscript 
}

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?

1 Answer 1

7

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.

1
  • delaycompress is exactly what I looking for, useful to keep one rotated log as uncompressed to allow manipulations with already rotated log by a side parsers, etc. Jul 27, 2021 at 11:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .