logrotate - 压缩文件修改了 x 天数
有没有办法让 logrotate 只压缩 X 天前修改的文件(例如 mtime +2)
Is there a way to get logrotate to only compress files modified X number of days ago (e.g. mtime +2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种选择是使用
logrotate
旋转到不同的扩展名,然后使用logrotate
旋转为压缩文件:这个 Rube Goldberg 装置将导致以下结果:
因此,您有两天的未压缩日志存档。
One option could be to use
logrotate
to rotate to a different extension, then uselogrotate
to rotate into compressed files:This Rube Goldberg contraption will result in the following:
Thus you have two archived days of logs which are uncompressed.
那么你可以使用delaycompress再等待一个周期。基本上,如果您每天轮换,那么它会保留昨天的日志未压缩。
除此之外,您可以尝试不使用 logrotate 来压缩文件并编写一个 bash 脚本每天运行一次并压缩所有早于特定日期的文件。
这是我个人喜欢的 bash 教程: http://www.linuxconfig.org/Bash_scripting_Tutorial
Well you can use delaycompress to wait one more cycle. Basically if you rotate daily then it will keep yesterdays logs uncompressed.
Besides that you could try not using logrotate to compress the files and write a bash script to run like once a day and compress all files older than a certain date.
Here is a tutorial to bash that I personally like: http://www.linuxconfig.org/Bash_scripting_Tutorial
你能做类似下面的事情吗?
我认为这会给你类似的东西
Could you do something like the following?
I think that will give you something like