regex - 如何从 logrotate 中的通配符中排除特定目录?
问题描述
我遇到了以下问题:我有一个网络服务器,上面有大约 50 个网站,每个人都有自己的目录/var/www/*sitename*
,例如/var/wwww/example.org/
.
在这些目录中,有一个 log 文件夹和一个 htdocs 文件夹,因此 apache 配置如下所示:
[...]
DocumentRoot /var/www/example.org/htdocs
CustomLog /var/www/example.org/logs/access.log combined
ErrorLog /var/www/example.org/logs/error.log
[...]
这对所有网站都是一样的,为了确保日志循环我将内容复制/etc/logrotate.d/apache2
到同一个文件中,但调整了这样的路径:/var/www/*/logs/*.log
,标准是这样的:/var/log/apache2/*.log
。
所以这个 logrotate 适用于所有网站,但现在我的问题是:一个特定的网站(将来可能更多)不应该每天轮换,而是每周轮换。然后不是14次,而是例如4次。
我现在已经尝试了很多来实现这一点,但我无法让它发挥作用。我创建了文件夹 test1 和 test2 并制作了一些 access.log 文件。logrotate conf 看起来像这样:
/var/log/apache2/test*/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
if /etc/init.d/apache2 status > /dev/null ; then \
/etc/init.d/apache2 reload > /dev/null; \
fi;
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \
endscript
}
/var/log/apache2/[!t][!e][!s][!t][!2]*/*.log {}
据我了解,这应该在 test1/ 中轮换日志文件,而不是在 test2/ 中,但它不起作用,上面的通配符规则仍然适用。
解决方案
尝试将此规则移至顶部并检查它是否有帮助。
/var/log/apache2/[!t][!e][!s][!t][!2]*/*.log {}
推荐阅读
- androidx - AuthenticationCallback.onAuthenticationFailed() 不会在 Pixel 4 上使用人脸生物识别技术调用
- python - 如何在不修改程序的情况下让请求打印出发送的原始 HTTP 请求?
- android - Jetpack Compose:使用 Modifier.selectable 时,如何防止可组合布局在滚动时可选?
- python - 在 Python 中将 15 分钟的数据重采样为 5 分钟的间隔
- svm - 无法理解 SVM 中的双重求和
- vue.js - v-if 中的路由器链接正在工作,但 url 没有改变
- jquery - Lua 中是否有像 jQuery 那样的“this”类型的选择器?
- angular - Angular + Capacitor:输入未与键盘对齐
- java - 如何使用 Jackson 将 json 对象的属性解析为地图
- python - 用 plotly 连接线之间的间隙