Friday, April 07, 2006

As I said earlier, I was working on a little script to archive IIS logfiles. Microsoft has the logfile rotation working nicely now but provides no other mechanism to keep your logfiles from eating your diskspace. Here is my first attempt at a solution for that. It's still very simple and you need to set the logfile directory yourself.
Things that need doing:
  • Read logfile location from metabase
  • Allow working with multiple logfile folders
When trying to solve the first issue I came acros something weird. On some IIS 6 boxes the metabase was a binary file like in the old days, on most others it was the XML you'd expect. I noticed that only on IIS on XP the log file location was coded in the registry. If anyone has an explanation for this or suggestions how to get the logfile location I'd apprieciate hearing them

Anyway, here it is, if you find it useful I'd apprieciate a note. If you improve on it (which shouldn't be too difficult) please send me your copy so that I can learn from your improvements

What's needed:
7zip's command line version
the batch file itself

Assumptions:
  1. You are running IIS 5 or later
  2. You have not modified the standard IIS logfile naming convention which is exAABBCC.log where AA= year, BB=month and CC is day.
Howto:
  1. Open the 7zip download and extract 7za.exe to somewhere in your path (system32 for example)
  2. Place the batch file somewhere.
  3. Edit this line in the batch file:
  4. rem set iis logfile location
    set logfolder=d:\logfiles

    So that it points to your logfile folder
  5. Create a user with read access to the script and the 7za.exe and write access to your IIS log folder.
  6. Schedule the batch file under that user's credentials so that it runs every 1st of the month.
And that's pretty much it. When running it will zip last month's logfiles and then delete the originals.

Of course It would be really easy to integrate a logfile analysis tool somewhere into this. I've had good experiences with WebLog Expert but anything that can be called from a command line should do nicely.

All this is tested on a few of my systems, it works there but I provide it with no warranty whatsoever. If you use it and your server is suddenly sucked into a wormhole and ends up in the dungeon dimensions it's your problem.

No comments: