[SOLVED] - logrotate with compresscmd and compressext

Issues related to applications and software problems
Post Reply
User avatar
warron.french
Posts: 401
Joined: 2014/03/27 20:21:58

[SOLVED] - logrotate with compresscmd and compressext

Post by warron.french » 2019/11/12 21:34:53

I am trying to configure a /etc/logrotate.d/messages (for this example, named after the /var/log/messages file).
I would like to use logrotate to keep no more than 2 backups; hence, rotate 2.
I am going to use a datestamp in the newly generated filename; hence, dateext.
I would like to specify the use of the compression tool "xz"; hence, compresscmd /bin/xz.
Because I am using xz, I know that I also have to specify the extension on the file as ".xz"; hence, compressext .xz.

So, I made a copy of /etc/logrotate.d/syslog and named it /etc/logrotate.d/messages, and initially had the following:

Code: Select all

/var/log/cron
/var/log/maillog
/var/log/secure
/var/log/spooler
{
    missingok
    sharedscripts
    postrotate 
       /bin/kill -HUP  `cat /var/run/syslog.pid 2> /dev/null`  2> /dev/null  || true
    endscript
}
Then I added my new lines based on my requirements in BOLD RED, to produce the following /etc/logrotate.d/messages:

Code: Select all

/var/log/messages
{
    missingok
    sharedscripts
    dateext
    rotate 2
    compress
    compresscmd /bin/xz
    compressext  .xz
    compressoptions   -9 -S  .xz
    postrotate 
       /bin/kill -HUP  `cat /var/run/syslog.pid 2> /dev/null`  2> /dev/null  || true
    endscript
}
The problem is that it appears that logrotate still does not function properly with compression alternatives. I had searched the CentOS Forums and found my own post on this for CentOS/RHEL 6.x.

The file will rotate sometimes, the file will take on the -dateext of the day, the file will not compress at all.

I really need this feature working. Has anyone ever gotten all of the compress[XYZ,etc.. etc...] options to work, ever?
Last edited by warron.french on 2019/11/13 17:59:53, edited 2 times in total.
Thanks,
War

User avatar
Errosion
Posts: 27
Joined: 2014/12/03 19:58:02

Re: logrotate with compresscmd and compressext

Post by Errosion » 2019/11/12 23:00:24

Possibly a silly question, but one that I've found in my logrotate meddlings...

You said you made a copy of your /etc/logrotate.d/syslog file and named it messages.

Are both the "syslog" and "messages" files sitting in /etc/logrotate.d/?

I've found that if you have two files in logrotate.d that are referencing the same files to be rotated, it will result in some funky results with how logrotate works, if it works at all.

Aside from that, have you referenced the logrotate man pages to make sure that you are properly defining those options?

User avatar
warron.french
Posts: 401
Joined: 2014/03/27 20:21:58

Re: logrotate with compresscmd and compressext

Post by warron.french » 2019/11/13 16:37:58

@Errosion thanks for pointing that out.

In reality I had the two files under /etc/logrotate.d/ with separate files to logrotate.

Thanks for your comment, I went back and updated my original post to reflect the situation I have currently.
Thanks,
War

User avatar
warron.french
Posts: 401
Joined: 2014/03/27 20:21:58

Re: logrotate with compresscmd and compressext

Post by warron.french » 2019/11/13 17:59:36

I solved the problem(s) that I was having. Here is the final result!

Code: Select all

/var/log/messages
{
    missingok
    weekly                          <----- This was missing!  You could use hourly as well!
    sharedscripts
    dateext
    rotate 2
    compress
    compresscmd /bin/xz
    compressext  .xz
    compressoptions   -9       #  Things to the right of this hashtag are unnecessary  -S  .xz; heck the entire line isn't really required.
    postrotate 
       /bin/kill -HUP  `cat /var/run/syslog.pid 2> /dev/null`  2> /dev/null  || true
    endscript
}
Thanks,
War

Post Reply

Return to “CentOS 7 - Software Support”