ith*_*cat 76 directory logrotate recursive
是否可以logrotate考虑目录及其所有子目录中的日志文件?(即没有明确列出子目录。)
Dan*_*n R 113
你的子目录有多深?
/var/log/basedir/*.log /var/log/basedir/*/*.log {
daily
rotate 5
}
Run Code Online (Sandbox Code Playgroud)
将旋转所有的.log在BASEDIR /文件,以及所有的.log在BASEDIR的任何直接的子文件。如果您还需要更深一层,只需添加另一个,/var/log/basedir/*/*/*.log直到覆盖每个级别。
这可以通过使用单独的 logrotate 配置文件进行测试,该文件包含不会满足的约束(高最小化),然后在详细模式下运行 logrotate 自己
logrotate -d testconfig.conf
Run Code Online (Sandbox Code Playgroud)
-d 标志将列出它考虑轮换的每个日志文件。
就我而言,子目录的深度可以在没有警告的情况下更改,因此我设置了一个 bash 脚本来查找所有子目录并为每个目录创建一个配置条目。
在轮换后保持子目录的结构对我来说也很重要,通配符(即@DanR 的答案)似乎没有这样做。如果您正在执行每日日志轮换,则可以将此脚本放入每日 cron 作业中。
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
Run Code Online (Sandbox Code Playgroud)
就像@DanR 建议的那样,测试 logrotate -d
小智 5
这是旧线程,但您可以执行以下操作:
/var/log/basedir/**/*.log {
daily
rotate 5
}
Run Code Online (Sandbox Code Playgroud)
这两颗星将匹配零个或多个目录。不过,您必须小心如何定义要轮换的日志文件,因为您可以轮换已经轮换的文件。我在这里引用logrotate的手册。
请谨慎使用通配符。如果指定 *,logrotate 将轮换所有文件,包括之前轮换的文件。解决这个问题的方法是使用 olddir 指令或更精确的通配符(例如 *.log)。
| 归档时间: |
|
| 查看次数: |
86652 次 |
| 最近记录: |