Re: Apache 2.2, rotatelogs.exe, and Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the meantime, I managed to find this, which I thought worth sharing in spite of the bad English grammar:

AB's Useful Box - Apache for Win32 Log file Rotation

So you have finished installing Apache for Win32, one of the best web servers you can get on your WinNT / Win2K / WinXP machine, but find that it's log files, access.log and error.log just keep on growing !

Well fear not, it is possible to manage those log files, and automate the process with out to much grief.

The following batch file, the was written and tested on WinXP, but should just as well on WinNT and Win2K, should:

    * store the current date and time into a varible
    * stop the Apache web service
    * move the log files, using the date/time as unique filename
    * restart the Apache web service
    * if prefered, use a command line zip utility to zip the logs
    * keep only the last "x" logs, and delete old

@echo off
:: Name - svrlogmng.bat
:: Description - Server Log File Manager
::
:: History
:: Date Authory Change
:: 22-May-2005 AGButler Original
::

:: ========================================================
:: setup variables and parameters
:: ========================================================

:: generate date and time varibles
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=7


:: ========================================================
:: turn over log files
:: ========================================================

:: change to the apacge log file direcoty
cd "c:\program files\apache group\apache\logs\"


:: stop Apache Service, Move log files and restart Apache Service
net stop apache

echo %nftu% >> access.log
move "c:\program files\apache group\apache\logs\access.log" "c:\program
files\apache group\apache\logs\%nftu%_access.log"

echo %nftu% >> error.log
move "c:\program files\apache group\apache\logs\error.log" "c:\program
files\apache group\apache\logs\%nftu%_error.log"

net start apache


:: ========================================================
:: zip todays Access and Error log files, then delete old logs
:: ========================================================

:: zip the files
7za 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


:end

The command line 7za zip utility is available from http://www.7-zip.org

The best method is to just put the 7za.exe file into your system32 folder.

Then it is just a matter of calling the batch file from the windows scheduler. On WinNT this is done on the commend line via AT and on WinXP this is done via Scheduled Tasks found in the Control Panel.

Some other things that can be done after the files have been moved, but before they are zipped, it to produce statistics from the access.log data. For example, how many times pages are being visited and from where.


-------- Original Message  --------
Subject: Re:  Apache 2.2, rotatelogs.exe, and Windows
From: Phillip Hamilton <phillip@xxxxxxxxxxxxx>
To: users@xxxxxxxxxxxxxxxx
Date: Tuesday, September 18, 2007 07:17:50 PM

I'll be back at my post on Monday, from there I'll be able to access the
files and I'd be happy to share it.

It's very simple if you're familiar with batch files.

1. Stop apache (using net stop)
2. Move logs to new folder (xcopy)
3. Restart apache (net start)
4. Rar the logs up with Winrar (smaller files than Winzip, RAR.EXE -m file).

Lather, rinse, repeat every 12 hours. The server is only down a split second
so no one even notices. The file move (since it's not a copy) is almost
instant.

If you come up with something snazzy with WSH I'd be interested in taking a
peek
if you feel like sharing.





-----Original Message-----
From: Mark A. Craig [mailto:mark.a.craig@xxxxxxxxx] Sent: Tuesday, September 18, 2007 2:01 PM
To: users@xxxxxxxxxxxxxxxx
Subject: Re:  Apache 2.2, rotatelogs.exe, and Windows

Philip, do you use a scheduled CMD file to gracefully kill the server,
rotate the logs, and then restart the server? Given that rumor has it that piping is broken in 2.2.4, it seems something like that is the only way to do it right

now, eh?  If what you're using contains no trade secrets, I'd be very
curious to see exactly what you're using, so I can use it as boilerplate for my own solution. I wonder if it could also be accomplished via a WSH file instead, and whether that would provide extra flexibility or benefits?

Mark

-------- Original Message  --------
Subject: Re:  Apache 2.2, rotatelogs.exe, and Windows
From: Phillip Hamilton <phillip@xxxxxxxxxxxxx>
To: users@xxxxxxxxxxxxxxxx
Date: Tuesday, September 18, 2007 11:50:08 AM

I wholeheartedly disagree with this statement:
Apache holds only a tiny share of Windows servers.

Apache holds a very large share of Windows server market, hence the
pre-made binary.
Back on topic, I rotate via a bat file with a quick re-start on my windows
boxes ;)

-----Original Message-----
From: Dragon [mailto:dragon@xxxxxxxxxxxxxxxxxx] Sent: Tuesday, September 18, 2007 1:02 PM
To: users@xxxxxxxxxxxxxxxx
Subject: Re:  Apache 2.2, rotatelogs.exe, and Windows

Mark A. Craig wrote:
So this leads me to ask again, what are all of you successful 2.2.4 admins using to rotate your logs? If the piping mechanism is broken, at least in the Windows binary, then what other technique(s) are people using? Task Scheduler with a batch or CMD file?

So far I've been manually rotating the logs, but I'd understandably like to automate it.
---------------- End original message. ---------------------

I think you will find that the vast majority of people using Apache are not doing so on the Windows platform. Most people who have committed to the Windows platform have also committed to IIS. Apache dominates the Linux environment and is used frequently on BSD and similar Unix-based platforms. Apache holds only a tiny share of Windows servers.

I believe that those few who are using Apache on Windows tend to be hobbyists or developers using it to serve their own stuff or to do development off-line. I am willing to bet there are very few people using it in a production environment under Windows.

So it is entirely possible that there may be nobody on this list who has an answer for you. The set of people using it in the same manner you are is small to begin with and there may not be many of them subscribed to this list.

Repeatedly posting demanding

Dragon

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux