我想配置logrotate来处理/var/log/apache2/access.log,与写入/ var/log/apache2的所有其他日志文件分开处理.如果没有明确指定所有其他日志,有没有办法让它工作?
我在网上看到logrotate使用glob来模式匹配文件名,但我似乎无法编写正确的模式.我尝试过很多模式,但它们都错误:
considering log /var/log/apache2/!(access.log)
log /var/log/apache2/!(access.log) does not exist -- skipping
Run Code Online (Sandbox Code Playgroud)
上面的模式在bash中有效,但只能用于shopt -s extglob.有没有办法用logrotate执行此操作,没有apache将access.log写入其自己的目录,或者破坏非访问日志文件的名称?
我也尝试通过使用在尝试旋转时失败的prerotate脚本来实现此功能access.log,但是logrotate抱怨我正在尝试将access.log旋转两次:
error: /etc/logrotate.d/apache2:16 duplicate log entry for /var/log/apache2/access.log
Run Code Online (Sandbox Code Playgroud)
这是我得到的最接近的:
# 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1451 次 |
| 最近记录: |