在windows实现nginx滚动日志

转载自 https://www.cnblogs.com/luozx207/p/11056996.html

 

@echo off
rem nginx滚动日志
rem nginx工作目录
set workspace=D:\luozixi\nginx-1.16.0
rem 日志存放目录
set logdir=D:\luozixi\nginx-1.16.0\logs
rem 将当前日志重命名,用今日的日期
move %logdir%\access.log %logdir%\access_%date:~0,4%_%date:~5,2%_%date:~8,2%.log
move %logdir%\error.log %logdir%\error_%date:~0,4%_%date:~5,2%_%date:~8,2%.log
rem 重新打开日志文件,如果不做这一步,nginx会继续往已被重命名的日志文件中写入日志
%workspace%\nginx.exe -s reopen -p %workspace%
rem 删除三天前的日志
set DaysAgo=3
forfiles /p %logdir% /m *.log /d -%DaysAgo% /c "cmd /c del /f /q @path"
pause

  

然后将此bat脚本加到windows定时任务,每天凌晨执行

%date:~0,4%_%date:~5,2%_%date:~8,2%的说明:

C:\Users\luozixi>echo %date%
2019/06/19 周三
C:\Users\luozixi>echo %date:~0,4%
2019
C:\Users\luozixi>echo %date:~0,4%_%date:~5,2%_%date:~8,2%
2019_06_19

  

posted @ 2022-11-17 11:06  不知名的宋某某  阅读(471)  评论(0编辑  收藏  举报