有人刚问我’我们应该为我们的应用程序保留多长时间’,我的回答是“直到磁盘已满”,因为除了空间不足之外没有理由把它们扔掉.
但是,标准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.
更新:
这是关于您可以运行的脚本类型的Stackoverflow帖子:
https://stackoverflow.com/questions/7523059/remove-oldest-file-in-repository