所以这让我发疯。我每周对一些不同的日志运行 logrotate,它的工作原理符合我的预期。但是,日志轮换发生在周日,这与记录到要轮换的目录的某些处理的完成一致。简而言之,我想在周四轮换这些日志文件,在此处理之前,我想将“修复”保留在 logrotate 配置本身中(副手动运行 logrotate --force,或将其放在脚本中)。
我正在使用以下配置运行 RHEL5:
cat /etc/logrotate.d/custom
/var/log/mpxx/mpxx_log {
daily
rotate 30
compress
missingok
olddir /var/log/mpxx.old/
create 644 user user
dateext
}
/var/log/mpxx/repo.log /var/log/mpxx/stop_repo.log {
weekly
rotate 90
compress
missingok
olddir /var/log/mpxx.old/
create 644 user user
dateext
}
cat /var/lib/logrotate.status
"/var/log/mpxx/repo.log" 2015-4-12
"/var/log/mpxx/stop_repo.log" 2015-4-12
4 月 10 日星期五,当我注意到这个问题时,我使用 logrotate --force/etc/logrotate.d/custom 手动轮转日志。然后,我手动编辑 logrotate.status 文件以反射(reflect)以下内容:
"/var/log/mpxx/repo.log" 2015-4-9
"/var/log/mpxx/stop_repo.log" 2015-4-9
不幸的是,如前所述,我手动运行 logrotate 以及对状态文件的编辑并没有阻止 logrotate 在 4 月 12 日轮换日志文件。
如何强制 logrotate 每周执行轮换,但在一周中的特定一天?我的搜索和研究并没有得到太多结果。
提前致谢!
最佳答案
我知道这已经过时了,但我自己必须实现这样的东西,并发现了这个问题并认为我会回答它。
logrotate(8)
有这个内置:
weekly [weekday]
Log files are rotated once each weekday, or if the date is advanced by at least 7 days since the last rotation (while ignoring the exact time). The weekday interpretation is following: 0
means Sunday, 1 means Monday, ..., 6 means Saturday; the special value 7 means each 7 days, irrespectively of weekday. Defaults to 0 if the weekday argument is omitted.
关于syslog - 每周在一周中的特定一天进行 Logrotate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29611216/