首页 > 解决方案 > 如何从 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/ 中,但它不起作用,上面的通配符规则仍然适用。

标签: regexapachelogrotate

解决方案


尝试将此规则移至顶部并检查它是否有帮助。

/var/log/apache2/[!t][!e][!s][!t][!2]*/*.log {}

推荐阅读