I want to configure logrotate to handle /var/log/apache2/access.log separately from all other log files written to /var/log/apache2. Without specifying all the other logs by name explicitly, is there a way to get this to work?
I've read online that logrotate uses glob to pattern-match filenames, but I can't seem to write the correct pattern. I have tried many patterns, and they all error with:
considering log /var/log/apache2/!(access.log)
log /var/log/apache2/!(access.log) does not exist -- skipping
The above pattern does work in bash, but only with shopt -s extglob
. Is there a way to do this with logrotate, short of having apache write access.log to its own directory, or mangling the names of the non-access log files?
I have also tried getting this to work by using a prerotate script that fails when attempting to rotate access.log
, but logrotate complains that I'm trying to rotate access.log twice with:
error: /etc/logrotate.d/apache2:16 duplicate log entry for /var/log/apache2/access.log
This is the closest I have gotten:
# rotate access.log every time logrotate is called
/var/log/apache2/access.log {
missingok
rotate 168
compress
create 640 root adm
# rotate the log every time we call logrotate (size 0)
size 0
dateext
dateformat .%Y%m%d.%s
copytruncate
}
# rotate everything daily EXCEPT access.log
/var/log/apache2/*.log {
daily
missingok
rotate 7
compress
create 640 root adm
copytruncate
# filter out access.log, which we want to rotate on its own schedule above
nosharedscripts
prerotate
bash -c "[[ ! '$1' =~ /access.log ]]"
endscript
}