0

I need to compress the files in var/log/remots/*/* with the following logrotate rule

/var/log/remots/*/* {
    rotate 178
    daily
    maxage 178
    compress
}

located in /etc/logrotate.d/remots.

I also have scripted and it looks like this.

cp rsyslog.conf /etc/rsyslog.conf
cp 10-remot.conf /etc/rsyslog.d/10-remot.conf
cp remots /etc/logrotate.d/remots

./rpgp.sh perms.txt

service rsyslog restart

However, when I force a logrotate with sudo logrotate -­d ­­--force /etc/logrotate.d/remots the log remains as plain text, is not compressed. The ouput is like a lot of messages like

renaming /var/log/remots/GSX/2019-03-25.2.gz to /var/log/remots/GSX/2019-03-25.3.gz (rotatecount 178, logstart 1, i 2)
renaming /var/log/remots/GSX/2019-03-25.1.gz to /var/log/remots/GSX/2019-03-25.2.gz (rotatecount 178, logstart 1, i 1),
renaming /var/log/remots/GSX/2019-03-25.0.gz to /var/log/remots/GSX/2019-03-25.1.gz (rotatecount 178, logstart 1, i 0),

and finally

/var/log/remots/GSX/2019-03-25.179.gz doesnt' exist -- wont't you try to dispose of it
renaming /var/log/remots/GSX/2019-03-25 to /var/log/remots/GSX(2019-03-25.1
compressing log with: /bin/gzip

PD: 10-remots.conf looks like

$template GuardaRemots, "/var/log/remots/%HOSTNAME%/%timegenerated:1:10:date-rfc3339%"
:source, !isequal, "localhost" -? GuardaRemots

and rsyslog.conf is just configurated to listen via UDP port 514

  • I don't understand you, @Phililp Couling. What is a PD, my PostData? Sorry, but I'm not good at English – sandalija Mar 25 at 10:58
  • I'd misread. See my answer. – Philip Couling Mar 25 at 11:12
2

From what I can see, logrotate is getting confused. Firstly you should be more restrictive with your name pattern. Instead of rotating /var/log/remots/*/* you should rotate:

/var/log/remots/*/*.log {
    rotate 178
    daily
    maxage 178
    compress
}

When you change the config, remember to check /var/lib/logrotate/status. Remove any entries for .*gz files.


It's less common to mix logrotate with programs rotating their own logs. You have configured rsyslog to write to dated log files. It's more common to use a static file name and allow logrotate to append dates for you. I note others have had problems with the same type of setup: https://stackoverflow.com/questions/8962477/logrotate-files-with-date-in-the-file-name

A simpler way to configure this is to write your "remots" (rsyslog) log to a static location such as:

$template GuardaRemots, "/var/log/remots/%HOSTNAME%.log"
:source, !isequal, "localhost" -? GuardaRemots

Then rotate:

/var/log/remots/*.log {
    rotate 178
    daily
    maxage 178
    compress
}

Logrotate will automatically append the date when it rotates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.