是否有可能得到logrotate
考虑目录及其所有子目录中的日志文件? (即没有明确列出子目录。)
你的子目录有多深?
/var/log/basedir/*.log /var/log/basedir/*/*.log { daily rotate 5 }
将旋转basedir /中的所有.log文件以及任何basedir的直接子文件中的所有.log文件。 如果您还需要深入1级,则只需添加另一个/var/log/basedir/*/*/*.log
直到您覆盖每个级别。
这可以通过使用一个单独的logrotateconfiguration文件进行testing,该configuration文件包含一个不会被满足的约束条件(高大小),然后运行日志以详细模式
logrotate -d testconfig.conf
-d标志将列出它正在考虑旋转的每个日志文件。
在我的情况下,子目录的深度可以在没有警告的情况下改变,所以我设置了一个bash脚本来查找所有子目录,并为每个目录创build一个configuration条目。 对于我来说,保持循环后的子目录结构也很重要,这个通配符(即@ DanR的答案)似乎没有做到。 如果你每天做日志,你可以把这个脚本放在日常的工作中。
basedir=/var/log/basedir/ #destdir=${basedir} # if you want rotated files in the same directories destdir=/var/log/archivedir/ #if you want rotated files somewhere else config_file=/wherever/you/keep/it > ${config_file} #clear existing config_file contents subfolders = $(find ${basedir} -type d) for ii in ${subfolders} do jj=${ii:${#basedir}} #strip off basedir, jj is the relative path #append new entry to config_file echo "${basedir}${jj}/* { olddir ${destdir}${jj}/ daily rotate 5 }" >> ${config_file} #add one line as spacing between entries echo "\n" >> ${config_file} #create destination folder, if it doesn't exist [ -d ${destdir}${jj} ] || mkdir ${destdir}${jj} done
就像@DanRbuild议的那样,用logrotate -d
testing
这是旧的线程,但你可以做到以下几点:
/var/log/basedir/**/*.log { daily rotate 5 }
这两颗星星将匹配零个或多个目录。 但是,您必须小心,因为您可以旋转已经旋转的文件,因此如何定义要旋转的日志文件。 我会在这里引用logrotate的手册。
请谨慎使用通配符。 如果指定*,logrotate将旋转所有文件,包括以前旋转的文件。 解决这个问题的方法是使用olddir指令或更精确的通配符(如* .log)。