Yes, you can use multiple wild cards. You can test your file without performing the actual rotations by doing this:
logrotate -d -f /etc/logrotate.conf
-d = Turns on debug mode. In debug mode, no changes will be made to the logs or to the logrotate state file.
-f = Tells logrotate to force the rotation, even if it doesn’t think
this is necessary. Sometimes this is useful after adding new
entries to logrotate, or if old log files have been removed by
hand, as the new files will be created, and logging will con-
tinue correctly.`
I don't know if later versions do, but after researching further I found that shell wildcards are supported. Both *
(match multiple characters) and ?
(match a single character) can be combined to match specific files.
As an example, here are patterns which match your use case along with the rest of a file which could be found at /etc/logrotate.d/process
/path/to/my/logfiles/process.????.????????.log
/path/to/my/logfiles/process.????.log
{
# Look for previously matched log files and rotate daily if found
daily
# use date as a suffix of the rotated file
dateext
# Compress log file, optional if the files are small enough
compress
# Allow for a log file pattern to NOT match in order to support both
# filename formats
missingok
# Do not create replacement log files, the application will do that
nocreate
# Keep 30 days worth of rotated logs
maxage 30
}
However if you intended for process
to be a placeholder for an actual process id, then I believe you can get away with using a wildcard in place of the process id number like so:
/path/to/my/logfiles/*.????.????????.log
/path/to/my/logfiles/*.????.log
{
...
}
I hope this helps. I too went searching for a regex approach that would work and finally decided on the use of shell wildcards instead of what I felt were workable, but more complex solutions.
An example:
While searching for a regex solution I found a blog post titled, "Excluding files from logrotate globbing matches" which provided this solution:
/var/log/upstart/*.log {
daily
missingok
rotate 7
compress
notifempty
nocreate
nosharedscripts
prerotate
bash -c "[[ ! $1 =~ testprogram ]]"
endscript
}
I ended up pulling two items out of that example and modified the match slightly. In my situation I wanted to rotate all files in a directory except for some input files which have a .inp
extension.
This is what I came up with:
# Force the prerotate "script" below to be run on each individual file
# in order to verify that it isn't an unprocessed input file
nosharedscripts
# Skip rotating any unprocessed input files (*.inp extension)
prerotate
bash -c "[[ ! $1 =~ \.inp$ ]]"
endscript
According to logrotate -d /etc/logrotate.d/myfilename
it appears to work. However as I mentioned I opted for the shell wildcards approach as it seemed easier for someone coming behind me to maintain.
Best Answer
Do I need to specify daily if I'm specifying a maxage of 1?
Yes, you need daily as you want this section to execute everyday. This control how execution frequency of the section, while maxage control how long rotated files are kept. They are 2 different things.
What exactly is missingok doing?
missingok means logrotate will not complain/generate error if the log file for rotation does not exist. If this is not specified and the log file intended for rotation is missing, logrotate will generate an error log.
Do I even need copytruncate if I'm specifying daily/maxage 1?
If copytruncate is working for you now, don't change it. It apply to original log file
To run logrotate at mid-night
There are 2 methods to do it.
Method 1 - Change when daily cron is run
Look for following lines in /etc/crontab
Change 25 6 (means 6:25AM), to 0 0. This also change ALL daily cron job starting time to mid-night.
Method 2 - Use custom crontab line
Move logrotate out of default daily cron schedule
Create custom cron job. Add following line into /etc/crontab