kdt*_*kdt 8 linux logging logrotate
有人刚刚问我“我们应该将应用程序的日志保留多长时间”,我的回答是“直到磁盘已满”,因为除了空间不足之外,没有理由将它们扔掉。
但是,标准 logrotate 要求我们指定特定的周期 + 旋转次数。是否有类似的东西可以让我们说“每天轮换,并尽可能多地保留历史记录,直到只有 5% 的可用空间”?
平台为 Redhat Linux。
您或许可以使用 firstaction 或 lastaction 指令来调用测试磁盘可用空间的 shell 脚本,然后对最旧的文件运行删除。
firstaction/endscript
The lines between firstaction and endscript (both of which must appear on lines by themselves) are
executed (using /bin/sh) once before all log files that match the wildcarded pattern are rotated,
before prerotate script is run and only if at least one log will actually be rotated. These
directives may only appear inside a log file definition. Whole pattern is passed to the script as
first argument. If the script exits with error, no further processing is done. See also lastac-
tion.
Run Code Online (Sandbox Code Playgroud)
更新:
这是关于您可以运行的脚本类型的 Stackoverflow 帖子:
logrotate 本身没有这样的选项。您可以添加一个 cron 脚本,该脚本会在可用空间低于您的标准时查找要删除的最旧日志。您还可以进行其他一些验证。但是,磁盘始终太满并不是一个好主意,因为系统将无法创建大型临时文件并可能导致应用程序故障。
| 归档时间: |
|
| 查看次数: |
4388 次 |
| 最近记录: |