轮换超过 7 天的日志并删除存档

轮换超过 7 天的日志并删除存档

我正在尝试配置logrotate为从某些目录中查找所有超过 7 天的日志文件并将其存档。必须删除存档文件。

我的结构如下。

/var/log/myapp/subfolder1/*.log (hundreds of logs)
/var/log/myapp/subfolder2/*.log (hundreds of logs)
/var/log/myapp/subfolder3/*.log (hundreds of logs)
/var/log/myapp/subfolder4/*.log (hundreds of logs)

我知道我应该在 中创建一个配置文件/etc/logrotate.d/,但是如何指定每个目录中超过 7 天的日志文件的归档并删除归档文件?

答案1

#While waiting for a real answer, you may wish to play w/ the following
#following alternative outline of a solution not using "logrotate"
#Needs sanity checks, failure recovery, et cetera
find $myLOGHOME -type f -mtime -7 | tee $myARCHIVE_FILES

#After archiving & renaming old files, $mySTREAM_ARCHIVER moves
#the originals to a holding directory, where they will be maintained
#for some time before eventually being deleted when they are too old
#Holding directory files remain there 
$mySTREAM_ARCHIVER $myOPTIONS < $myARCHIVE_FILES

#Implementation, testing and cleanup are left as an exercise for the reader

相关内容