Reputation: 149
I am using logrotate
version 3.12.3. How do I tell logrotate
to exclude files that are already rotated/compressed?
For example, if I am rotating all files in /var/log
as
"/var/log/*" {
compress
missingok
dateext
rotate 4
size=5000k
}
after a file is compressed, how do I tell logrotate
to not rotate already rotated/compressed files? For example:
/var/log/file1
after logrotation it becomes
/var/log/file1.20211212.gz
I tried
tabooext + .gz
on top of definitions but it doesn't seem to take effect.
From man logrotate
include file_or_directory
Reads the file given as an argument as if it was included inline where the include directive appears. If a directory is given, most of the files in that directory are read in alphabetic order before processing of the including file continues. The only files which are ignored are files which are not regular files (such as directories and named pipes) and files whose names end with one of the taboo extensions, as specified by the tabooext directive.
If something like below worked, that would have been good.
/var/log/*[!".gz"] {
}
Thank you.
EDIT
Maybe do something like
/var/log/*[!.][!g][!z] {
..
}
but it skips file named /var/log/test1gz
. How do I match the .
character with globbing?
Upvotes: 6
Views: 6506
Reputation: 125
Try to find all glob possibilities that does not accept *.gz
. As you have three letters (.
, g
, z
), there are 2^3 = 8
possible combinations (3 characters, 2 states x
and !x
), minus one which is *.gz
.
The seven other possibilities are the following:
All files that don't have an extension point as third last but end with gz
(e.g. filegz
)
/var/log/*[!.]gz
All files which 2-letters extension doesn't begin by g
but ends by z
(e.g. file.7z
)
/var/log/*.[!g]z
All files which 2-letters extension begins by g
but doesn't end by z
(e.g. file.gg
)
/var/log/*.g[!z]
All files that don't end with .gz
but end with a z
(e.g. file.ezz
)
/var/log/*[!.][!g]z
All files that don't end with .gz
but with g
as second to last letter (e.g. file.cgi
)
/var/log/*[!.]g[!z]
All files which 2-letters extension is not gz
(e.g. file.hh
)
/var/log/*.[!g][!z]
Finally, all files that don't finish by .gz
(e.g. file.txt
)
/var/log/*[!.][!g][!z]
So this gives us:
/var/log/*[!.]gz
/var/log/*.[!g]z
/var/log/*.g[!z]
/var/log/*[!.][!g]z
/var/log/*[!.]g[!z]
/var/log/*.[!g][!z]
/var/log/*[!.][!g][!z]
{
...
The combinations can be generated with python:
import itertools as it
suffix = '.gz'
states = ([x, '![%c]' % x] for x in suffix)
for res in it.product(*states):
print ''.join(res)
Hope it helps!
Upvotes: 4
Reputation: 27295
You don't need to specify a complete folder. You can define a file aswell. So first you should make sub folders for every service that you have a better overview. There you can place your logs into. You shouldn't put that on your complete log folder because there are some more rotate scripts located.
for example:
/var/log/yum.log {
missingok
notifempty
size 30k
yearly
create 0600 root root
}
Upvotes: 1