@echo off


rem 这个脚本是为了完成Nginx服务日志滚动


rem nginx工作目录

set workspace=D:\NIIS\Nginx


rem 日志存放目录

set logdir=D:\NIIS\Nginx\logs


rem 查看系统中正在运行的nginx进程

rem tasklist /fi "p_w_picpathname eq nginx.exe"


rem 日志存放路径。保存日志的目录结构为:年\月\日

set rolldir=%logdir%\%date:~0,4%\%date:~5,2%\%date:~8,2%

set mdrolldir=md %rolldir%

call %mdrolldir%


rem 备份并根据时间重命名访问日志文件

rem 日志文件命名格式为:access.年-月-日-小时.log

set cmdstr=move %logdir%\access.log %rolldir%\access.%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%.log

call %cmdstr%


rem 备份并根据时间重命名错误日志文件

rem 日志文件命名格式为:access.年-月-日-小时.log

set cmdstr=move %logdir%\error.log %rolldir%\error.%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%.log

call %cmdstr%


rem 重新打开日志文件

%workspace%\nginx.exe -s reopen -p %workspace%