linux
#!/bin/bash
logs_path="/usr/local/nginx/logs"
bak_path="/usr/local/nginx/logs/bak"
DAYS=15
mv ${logs_path}/access.log ${bak_path}/access_$(date -d "yesterday" +"%Y%m%d%H%M%S").log
mv ${logs_path}/error.log ${bak_path}/error_$(date -d "yesterday" +"%Y%m%d%H%M%S").log
#mv ${logs_path}access.log ${logs_path}access_$(date +"%Y年%m月%d日%H时%M分%S秒星期%w").log
#mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y年%m月%d日%H时%M分%S秒星期%w").log
nginx -s reload
find ${bak_path} -name "*.log" -type f -mtime +$DAYS -exec rm {} \;
windows
windows
@echo off
D:
set NGINX_PATH="D:\javaServer\nginx 1.13.10.1 Crow"
cd %NGINX_PATH%
rem date格式:Wed 11/02/2016
set today=%date:~0,4%-%date:~5,2%-%date:~8,2%
set dir="D:\javaServer\nginx 1.13.10.1 Crow\logs\backup"
rem access log
move %NGINX_PATH%\logs\access.log %dir%\access-%today%.log
move %NGINX_PATH%\logs\error.log %dir%\error-%today%.log
nginx_basic.exe -s reload
rem 删除 D:\javaServer\nginx\logs目录及子目录下,修改时间大于15天的、tmp结尾的文件
forfiles /p "D:\javaServer\nginx 1.13.10.1 Crow\logs\backup" /s /m *.log /d -15 /c "cmd /c del /f /q /a @path"