7

I have a file under logrotate.d that I would like not to run when the main logrotate is running. I have created a separate job for this in /etc/crontab

45 23   * * *   root    mv /var/log/RemoteSystems/*/*.log /var/log/Archiv/ && logrotate /etc/logrotate.d/test  

The job will move the files from a directory to another and then will apply logrotate. I would like that this job to run separately from main logrotate job in /etc/crontab. The problem is that because "test" is under /etc/logrotate.d/, it will run once again with the main logrotate. Is there any command that I can insert in logrotate.conf that can exclude "test" to run? I know that if I am having "test" file out of /etc/logrotate.d, this will not happen, but I would like to keep "test" at the same path.

Khaled
  • 36,533
  • 8
  • 72
  • 99
Ioan
  • 71
  • 1
  • 3

5 Answers5

6

If you look at the manual man logrotate.conf, you can read find tabooext option which enables you to exclude some files with specific extensions.

tabooext [+] list
     The current taboo extension list is changed (see the include directive for information on the taboo extensions). If a + precedes the
     list of extensions, the current taboo extension list is augmented, otherwise it is replaced. At startup, the  taboo  extension list
     contains  .rpmsave,  .rpmorig,  ~, .disabled, .dpkg-old, .dpkg-dist, .dpkg-new, .dpkg-bak, .dpkg-del, .cfsaved, .ucf-old, .ucf-dist,
     .ucf-new, .rpmnew, .swp, .cfsaved, .rhn-cfg-tmp-*

You can choose one of the default excluded extensions like .disabled or you can specifiy your own additional extension like:

tabooext + .test

All you need to do is to rename your file /etc/logrotate.d/test to have any of these extensions like /etc/logrotate.d/test.disabled.

Khaled
  • 36,533
  • 8
  • 72
  • 99
  • Yes, I read this, but I would like to keep the name as it is. I thought that maybe there is a line that I can add it in logrotate.conf in order to exclude "test" file... it seems there is not. Thanks! – Ioan Mar 04 '17 at 19:17
  • 1
    @Ioan: So, you want to exclude a file without doing any change!! – Khaled Mar 05 '17 at 08:08
  • 1
    I do want to do a change, but I thought that maybe there is a command that I can add in logrotate.conf. in order to exclude "test" . It seems there is not. Thank you. – Ioan Mar 05 '17 at 09:06
1

You could edit the config file as below:

before

include /etc/logrotate.d

after

include /etc/logrotate.d/*.conf

This should make only files ending .conf in /etc/logrotate.d/ to be picked up by logrotate excluding your test file

If you already have files in /etc/logrotate.d/ being used by logrotate, these would need updated to include .conf

Kev
  • 21
  • 3
0

As I write this, I'm using logrotate version 3.20.1 on Arch and in the man page is a feature I suspect has been added since this question was new in 2017. In addition to tabooext there is now taboopat which will exclude any file which matches a glob pattern in that list. e.g. adding the following to /etc/logrotate.conf:

taboopat + .gitignore

Results in:

# logrotate -v /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d
Ignoring .gitignore, because of .gitignore pattern match
reading config file snapper
reading config file syslog-ng
...
ericx
  • 416
  • 1
  • 4
  • 10
0

By placing the file test in the /etc/logrotate.d/ directory, it is going to be picked up by logrotate automatically.

If you're wanting to run it manually, you can force it to carry out logrotate on the particular file no matter the location.

logrotate --force /tmp/test

Where /tmp/test is the new location of the file.

0

If you don't want to touch "test", you could try to modify the include /etc/logrotate.d directive in /etc/logrotate.conf. By default it refers to a directory and thus parses all files in that directory, except for some file extensions.

What you can try is, modify the include directory to refer to individual files under /etc/logrotate.d, example /etc/logrotate.d/apt etc. You exclude "test" from that list. I haven't tested this, but it might be worth trying.

Daniel t.
  • 9,291
  • 1
  • 33
  • 36
  • This could be a sollution. The problem is I am not the only one that is administrating this system and I am thinking that if someone is adding a file under /etc/logrotate.d/ will expect this to run. In conclusion, I don't want to touch any global setting. I didn't test it so far, but maybe I will create another directory under logrotate.d and put the file under this directory. As far as I understood, logrotate will not look after files under directories. Thanks! – Ioan Mar 04 '17 at 19:27