Skip to content

Instantly share code, notes, and snippets.

@reke592
Last active February 10, 2024 08:29
Show Gist options
  • Save reke592/0c58f16e8875e485c58c636ad98ea471 to your computer and use it in GitHub Desktop.
Save reke592/0c58f16e8875e485c58c636ad98ea471 to your computer and use it in GitHub Desktop.

Revisions

  1. reke592 revised this gist Feb 10, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion rotatelogs.bat
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    @echo Off
    REM requirements:
    REM nginx build for windows (fixed issue 1024 limit) - http://nginx-win.ecsds.eu/download/
    REM This Nginx build for windows, available at http://nginx-win.ecsds.eu/download/
    REM this build has fixed issues related to the 1024 worker_connection limit.
    REM rar.exe - for archive, replace this if you don't want rar.exe

    REM Current installation directory of nginx
  2. reke592 created this gist Feb 10, 2024.
    33 changes: 33 additions & 0 deletions rotatelogs.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    @echo Off
    REM requirements:
    REM nginx build for windows (fixed issue 1024 limit) - http://nginx-win.ecsds.eu/download/
    REM rar.exe - for archive, replace this if you don't want rar.exe

    REM Current installation directory of nginx
    pushd c:\nginx

    REM Log folder name
    set dt=%DATE:~10,4%%Date:~4,2%%Date:~7,2%%Time:~0,2%%Time:~3,2%%Time:~6,2%
    set dt=%dt: =0%
    set tmp=logs%dt%
    set archive=%tmp%.rar
    mkdir %tmp%

    REM move log files to temporary folder
    move logs\*.log %tmp%

    REM signal nginx to reopen log files
    nginx.exe -s reopen

    REM wait before we archive, to avoid file locks created by nginx -s reopen
    timeout /t 3

    REM archive log files
    rar a %archive% %tmp%

    REM remove temporary files
    del /Q %tmp%
    rmdir %tmp%
    if not exist logs_rotate mkdir logs_rotate
    move %archive% logs_rotate
    popd