如何在Window 2000框上旋转Apache Access和Error日志?
我在下面提供我的批处理文件作为答案.
有没有办法直接通过Apache配置文件执行此操作?我目前正在使用以下customlog命令生成每日日志.
CustomLog'|""*Apache-Path/bin/rotatelogs.exe""*Apache-Path/logs/backup/internet_access_%d-%m-%y.log"86400'组合
这是DOS批处理文件,修改为带注释.我每周运行它,它保留了8周的压缩备份.你需要安装7个拉链.
我没有参数化路径,随意.
@echo off :: Name - svrlogmng.bat :: Description - Server Log File Manager :: :: History :: Date Authory Change :: 22-May-2005 AGButler Original :: 14-Jan-2008 AIMackenzie Changed net stops and paths where necessary :: ======================================================== :: setup variables and parameters :: ======================================================== :: generate date and time variables for /f "tokens=2,3,4 delims=/ " %%i in ('date /T') do set trdt=%%k%%j%%i for /f "tokens=1,2 delims=: " %%i in ('time /T') do set trtt=%%i%%j set nftu=%trdt%%trtt% :: set the Number Of Archives To Keep set /a noatk=8 :: ======================================================== :: turn over log files :: ======================================================== :: change to the apache log file directory cd /D "D:\Program Files\Apache Software Foundation\Apache2.2\logs\" :: stop Apache Service, Move log files and restart Apache Service "D:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe" -k stop echo %nftu% >> access.log move "D:\Program Files\Apache Software Foundation\Apache2.2\logs\access.log" "D:\Program Files\Apache Software Foundation\Apache2.2\logs\%nftu%_access.log" echo %nftu% >> error.log move "D:\Program Files\Apache Software Foundation\Apache2.2\logs\error.log" "D:\Program Files\Apache Software Foundation\Apache2.2\logs\%nftu%_error.log" "D:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe" -k start :: ======================================================== :: zip todays Access and Error log files, then delete old logs :: ======================================================== :: zip the files "D:\Program Files\7-Zip\7z.exe" a -tzip %nftu%_logs.zip %nftu%_access.log %nftu%_error.log :: del the files del /Q %nftu%_*.log :: ======================================================== :: rotate the zip files :: ======================================================== :: make list of archive zip files type NUL > arclist.dat for /F "tokens=1,2 delims=[] " %%i in ('dir /B *_logs.zip ^| find /N "_logs.zip"') do echo %%i = %%j>> arclist.dat :: count total number of files for /F "tokens=1 delims=" %%i in ('type arclist.dat ^| find /C "_logs.zip"') do set tnof=%%i :: setup for and create the deletion list set /a negtk=%noatk%*-1 set /a tntd=%tnof% - %noatk% type NUL>dellist.dat for /L %%i in (%negtk%,1,%tntd%) do find " %%i = " arclist.dat >> dellist.dat :: del the old files for /F "tokens=3 delims= " %%i in ('find "_logs.zip" dellist.dat') do del /Q %%i :: remove temp files del /Q arclist.dat del /Q dellist.dat