Last active
December 18, 2022 11:56
-
-
Save hershkoy/bfc47d59a39dcf07f05dfd6e0e8501a4 to your computer and use it in GitHub Desktop.
log rotate apache on windows + zip
This file contains 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
ErrorLog "logs/error.log" | |
#rotate every 2 minutes | |
ErrorLog "|bin/rotatelogs.exe -p C:/.../zip_logs.bat -l logs/errorlog.%Y-%m-%d-%H_%M_%S.log 120" | |
# or rotate every 20Mb | |
ErrorLog "|bin/rotatelogs.exe -p C:/.../zip_logs.bat -n 20 logs/error.log 20M" |
This file contains 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
REM params passed from rotatelogs.exe are with forward slashes. it is not recognized by cmd del command, | |
REM use forward slashes everywhere! | |
setlocal EnableDelayedExpansion | |
set apache_server_path="../path/to/apache/folder/..." | |
set curr_log=%1 | |
set prev_log=%2 | |
powershell -ExecutionPolicy Bypass -Command "& Compress-Archive -DestinationPath '%apache_server_path%\%prev_log%.zip' -Path ('%apache_server_path%\%prev_log%')" | |
del '%apache_server_path%\%prev_log%' | |
REM waiting for zip file to be created | |
set count=0 | |
:loop | |
if exist '%apache_server_path%/%prev_log%.zip' ( | |
goto delete | |
) else ( | |
set /a count+=1 | |
if !count! == 5 ( | |
goto end | |
) | |
timeout /t 10 | |
goto loop | |
) | |
:delete | |
REM using powershell to delete, because cmd del command has issue with forward slashes | |
powershell -ExecutionPolicy Bypass -Command "& Remove-Item -Path ('%apache_server_path%/%prev_log%')" | |
:end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment