如何通过另一个配置覆盖 logrotate 的配置

如何通过另一个配置覆盖 logrotate 的配置

我的磁盘上有一个日志文件夹,其轮换策略如下

"/mnt/foo/shared/log/*.log" {
  # rotate the files daily
  daily
  # Save the last 7 days worth of logs before deleting
  rotate 7
  # missing file is not an error case - just ignore.
  missingok
  # this is important for the logs
  copytruncate
}

文件夹中有一组日志文件,/mnt/foo/shared/log名为indexer_cron_1.logindexer_cron_4.log我只想将这 4 个文件轮换 14 天”。我如何覆盖这个配置?我想过创建另一个配置,但出现重复旋转的想法,我停止了这种操作。我之前没有可以测试这个的机器,因此在这里询问。

答案1

您可以使用 globbing 来执行此操作,这意味着您必须明确指定哪些日志文件应该轮换 14 天,哪些不应该轮换:

/mnt/foo/shared/log/other_log_file_*_1.log
/mnt/foo/shared/log/other_log_file_*_2.log
/mnt/foo/shared/log/other_log_file_*_3.log
{
  # rotate the files daily
  daily
  # Save the last 7 days worth of logs before deleting
  rotate 7
  # missing file is not an error case - just ignore.
  missingok
  # this is important for the logs
  copytruncate
}

这些日志文件轮换 14 天:

/mnt/foo/shared/log/indexer_cron_[1234].log
{
  # rotate the files daily
  daily
  # Save the last 14 days worth of logs before deleting
  rotate 14
  # missing file is not an error case - just ignore.
  missingok
  # this is important for the logs
  copytruncate
}

没有其他更简单的方法可以在轮换规则中包含或排除某些日志文件。

相关内容