Last active
February 10, 2024 08:29
-
-
Save reke592/0c58f16e8875e485c58c636ad98ea471 to your computer and use it in GitHub Desktop.
nginx windows and log rotation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo Off | |
| REM requirements: | |
| 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 | |
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment