Created
October 4, 2021 23:05
-
-
Save keoy7am/e97235d750707b715b0c6df9fcda4e03 to your computer and use it in GitHub Desktop.
Nginx Log Rotate On Windows
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 Restarting Nginx | |
| echo off | |
| :: 參數設定 :: | |
| set "NginxDir=C:\Users\Srv\Desktop\nginx" | |
| set "LogDir=%NginxDir%\logs" | |
| :: 整理Log Start :: | |
| :: 退出Nginx | |
| nginx.exe -s quit | |
| :: 強制退出 | |
| :: > taskkill -f /im nginx.exe | |
| :: 需透過 date /t 指令確認格式 | |
| :: ref: https://blog.miniasp.com/post/2010/09/24/How-to-parse-text-from-file-or-command-using-Batch | |
| :: 週二 2021/10/05 格式 | |
| For /f "tokens=2-4 delims=/ " %%i in ('date /t') do (set YMD=%%i-%%j-%%k) | |
| :: 2021/10/05 週二 格式 | |
| :: > For /f "tokens=1-3 delims=/ " %%i in ('date /t') do (set YMD=%%i-%%j-%%k) | |
| IF EXIST "%LogDir%\access.log" (echo "FileExist") | |
| IF EXIST "%LogDir%\access.log" (move "%LogDir%\access.log" "%LogDir%\access_%YMD%.log") | |
| IF EXIST "%LogDir%\error.log" (move "%LogDir%\error.log" "%LogDir%\error_%YMD%.log") | |
| :: 整理Log End :: | |
| cd "%NginxDir%" | |
| start nginx.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment