【问题标题】:How do I configure mongodb to remove old log files?如何配置 mongodb 以删除旧的日志文件?
【发布时间】:2019-06-09 22:28:48
【问题描述】:

我已阅读 mongodb 文档并正在 Windows 10 上轮换我的日志文件。但是,在我手动删除它们之前,日志数量会不断增加。我想保留 30 天的日志。

我希望有一个类似于 NLog 的配置设置,我可以在其中指定在重写之前要保留多少个文件。也许我误解了文档中的某些内容。自动删除旧日志文件的“最佳做法”是什么?

【问题讨论】:

    标签: mongodb logging windows-10


    【解决方案1】:

    多年后,但仍然有帮助的可能是这个 cmd 脚本。它是为了删除我个人资料中的旧内容而编写的,但扩展起来非常简单:

    @echo off
    @setlocal
    
    REM Remove everything older then "/D" days (ten/10 days in our examples below)
    REM BUT we can not remove directories with files in it, so we do it in two-steps ways:
    REM 1st remove all files by using the command: del
    REM 2nd remove all files by using the command: rd
    
    REM cleanup %TMP%
    forfiles -p "%TMP%"                   -m * /D -10 /C "cmd /c del /s/q @path > nul 2> nul"
    forfiles -p "%TMP%"                   -m * /D -10 /C "cmd /c  rd /s/q @path > nul 2> nul"
    
    REM cleanup %TEMP%
    forfiles -p "%TEMP%"                  -m * /D -10 /C "cmd /c del /s/q @path > nul 2> nul"
    forfiles -p "%TEMP%"                  -m * /D -10 /C "cmd /c  rd /s/q @path > nul 2> nul"
    
    REM cleanup the Downloads folder in the current profile
    forfiles -p "%USERPROFILE%\Downloads" -m * /D -10 /C "cmd /c del /s/q @path > nul 2> nul"
    forfiles -p "%USERPROFILE%\Downloads" -m * /D -10 /C "cmd /c  rd /s/q @path > nul 2> nul"
    
    @endlocal
    @echo on
    

    【讨论】:

    • 谢谢,我可以尝试扩展它以适合我的目的。
    【解决方案2】:

    看起来在没有 3rd 方实用程序的情况下执行此操作的最简单方法是创建一个每晚通过任务计划程序运行的批处理文件。

    【讨论】:

      猜你喜欢
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 2015-04-26
      • 2013-05-25
      • 1970-01-01
      相关资源
      最近更新 更多