I am trying to write a script that will compress the daily IIS logs into either a .zip or .rar file and send it of to a network share. I would like this to be an autmated thing to reduce administration overhead.
Below is a vbs script we use. Not sure if we found it on the net or someone from the team wrote it. Works very well. Does require some sort of commandline based zip program. We use gzip which is availiable free online. Hope this is what you are looking
for.
wscript.echo "Script run on date " & strDate
Wscript.echo "log files more than 5 days old will be zipped."
wscript.echo " "
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objWS = CreateObject ("WScript.Shell")
Set objFolder = objFSO.GetFolder (wscript.arguments (0))
For Each objF in objFolder.SubFolders
If bDebug Then wscript.echo "Checking folder " & objF.Path
DoDirectory (objF)
Next
Set objFSO = Nothing
Set objWS = Nothing
Sub DoDirectory (objFold)
Dim objUserDir, objFile, iDiff
For Each objUserDir in objFold.SubFolders
DoDirectory (objUserDir)
Next
For Each objFile in objFold.Files
If bDebug Then Wscript.echo "Checking file: " & objFile.Path
If LCase (Right (objFile.Name, 4)) = ".log" and LCase (Left (objFile.Name, 2)) = "ex" Then
Dim strCheckString, strY, strM, strD, strCommand, iResult
strCheckString = Mid (objFile.Name, 3, 6)
strY = "20" & Left (strCheckString, 2)
strM = Mid (strCheckstring, 3, 2)
strD = Right (strCheckString, 2)
iDiff = DateDiff ("d", strM & "/" & strD & "/" & strY, strDate)
If iDiff > 5 Then
strCommand = zipProgram & " " & objFile.Path & ".zip " & objFile.Path
If bDebug Then wscript.echo vbTab & "zip it: " & strCommand
iResult = objWS.Run (strCommand, 0, "true")
If iResult <> 0 Then
If bDebug Then wscript.echo vbTab & "result = " & iResult
Else
objFile.Delete
End If
Else
If bDebug Then wscript.echo vbTab & "don't zip it"
End If
End If
Next
End Sub
Shame-less plug - Download IISLogsLite 2.0, this is an application I wrote and provide free of charge. This will zip and/or delete logs and is very configurable plus can save to a remote share. This should meet most of your needs and doesn't require you
to find or purchase any compression programs. It does require the .NET 2.0 framework. One thing I added to this version it will auto-configure by reading the metabase. Hope that helps.
We are currently generating in the region of 1 GB of logs per day for each of our web sites hosted in IIS. We would like to schedule a script that will look for log files older than 24 hours old and then compress each of them into a compressed file format
and then send the compressed file to a network share from where they will be extracted when necessary for analysis purposes.
When you configure IISLogsLite 2.0 will do exactly what you described. The EXE will have no issues with log files that are 1 GB. To test this out, manually copy a few log files to folder on a test machine. Install and manually configure IISLogsLite 2.0 to
monitor the test folder. It will compress and move the files to the remote share. If you have any further questions about IISLogs, please email
info@iislogs.com with specific questions.
The script I posted previously will also zip files based off of date just change the line If iDiff > 5 Then to the days you want zipped.
The advantage of using a script such as thing is it does not require any additional software to be loaded on your web server. Keeping things simple "clean" and secure are important.
I don't want to sound like I'm pushing my EXE over the script, I almost hesitated in posting a link to it. I didn't want to sound like I was self-promoting my program. It comes down to whatever is easier for the person to support in their environment.
I agree having a vbs script along with a compression file either gzip or winzip with the command line add-on works great, although winzip is 29.95 I think. My program is written using the .NET 2.0 framework and if this framework is loaded on the server, you
can install my program on a separate machine then 'xcopy' without having to install on the server. It's whatever the person wants to-do. I've handled logs with scripts and that is what gave me the idea to develop it in the first place. Many administrators,
including me use VBS scripts over 3rd party apps because they have control of the source code. Either way these are just a couple of ways for him to achieve what he wants.
PS: Thanks for posting your VBS script. You should publish on a blog or write a short article on your script and how you use it. I'm sure there are lots of people would appreciate that. If you want, I can publish on my blog along with giving you the proper
credit. If you do publish, let me know and I'll link to the article. Thanks again!
I don't mean to be a pain, but the script seems to be the better option for me as I will be deploying this across many servers in a load balanced environment which do not currently run .Net Framework 2.0. I have copied the script to notepad and saved it
as a .vbs file, but I am not quite sure what to do next. If I run the script I get a message saying:
weblogs.vbs startdirectory
I am not very experienced at script writing so will need a bit of guidance.
That sounds good about using the script. You need a command line argument with the 'folder name' where the log files are located. For example, if the log files are stored in
D:\logfiles, you would put 'weblogs.vbs D:\Logfiles'. This should do what you need. Make sure to verify the variable where the gzip.exe is located is updated to where it resides on your server. I've done quite a bit of script so the script
was straight forward. Hope that helps.
BTandy
3 Posts
Compress and archive IIS Logs
Aug 31, 2006 02:18 PM|LINK
tomkmvp
7657 Posts
MVP
Moderator
Re: Compress and archive IIS Logs
Aug 31, 2006 02:54 PM|LINK
http://mvp.support.microsoft.com/
kryan762
8 Posts
Re: Compress and archive IIS Logs
Aug 31, 2006 10:50 PM|LINK
Below is a vbs script we use. Not sure if we found it on the net or someone from the team wrote it. Works very well. Does require some sort of commandline based zip program. We use gzip which is availiable free online. Hope this is what you are looking for.
Option Explicit
Const bDEBUG = False
Const zipProgram = "C:\gzip.exe"
Dim objFSO, objFolder, objF, objWS
Dim strYear, strDay, strMonth, strDate
If WScript.Arguments.Count <> 1 Then
WScript.Echo "weblogs.vbs startdirectory"
WScript.Quit (1)
End If
strDate = Date()
strYear = DatePart ("yyyy", strDate)
strDay = DatePart ("d", strDate)
strMonth = DatePart ("m", strDate)
wscript.echo "Script run on date " & strDate
Wscript.echo "log files more than 5 days old will be zipped."
wscript.echo " "
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objWS = CreateObject ("WScript.Shell")
Set objFolder = objFSO.GetFolder (wscript.arguments (0))
For Each objF in objFolder.SubFolders
If bDebug Then wscript.echo "Checking folder " & objF.Path
DoDirectory (objF)
Next
Set objFSO = Nothing
Set objWS = Nothing
Sub DoDirectory (objFold)
Dim objUserDir, objFile, iDiff
For Each objUserDir in objFold.SubFolders
DoDirectory (objUserDir)
Next
For Each objFile in objFold.Files
If bDebug Then Wscript.echo "Checking file: " & objFile.Path
If LCase (Right (objFile.Name, 4)) = ".log" and LCase (Left (objFile.Name, 2)) = "ex" Then
Dim strCheckString, strY, strM, strD, strCommand, iResult
strCheckString = Mid (objFile.Name, 3, 6)
strY = "20" & Left (strCheckString, 2)
strM = Mid (strCheckstring, 3, 2)
strD = Right (strCheckString, 2)
iDiff = DateDiff ("d", strM & "/" & strD & "/" & strY, strDate)
If iDiff > 5 Then
strCommand = zipProgram & " " & objFile.Path & ".zip " & objFile.Path
If bDebug Then wscript.echo vbTab & "zip it: " & strCommand
iResult = objWS.Run (strCommand, 0, "true")
If iResult <> 0 Then
If bDebug Then wscript.echo vbTab & "result = " & iResult
Else
objFile.Delete
End If
Else
If bDebug Then wscript.echo vbTab & "don't zip it"
End If
End If
Next
End Sub
steve schofi...
5681 Posts
MVP
Moderator
Re: Compress and archive IIS Logs
Sep 01, 2006 05:00 AM|LINK
Shame-less plug - Download IISLogsLite 2.0, this is an application I wrote and provide free of charge. This will zip and/or delete logs and is very configurable plus can save to a remote share. This should meet most of your needs and doesn't require you to find or purchase any compression programs. It does require the .NET 2.0 framework. One thing I added to this version it will auto-configure by reading the metabase. Hope that helps.
How to save to a remote share
http://iislogs.com/help/how_to_setup_iislogs_to_save_zip_to_remote_server.htm
Download link
http://www.iislogs.com/download/iislogslitesetup20.zip
Online help file
http://iislogs.com/help/configure_iislogs_lite_version20.htm
Steve Schofield
Windows Server MVP - IIS
http://iislogs.com/steveschofield
http://www.IISLogs.com
Log archival solution
Install, Configure, Forget
BTandy
3 Posts
Re: Compress and archive IIS Logs
Sep 03, 2006 12:40 PM|LINK
We are currently generating in the region of 1 GB of logs per day for each of our web sites hosted in IIS. We would like to schedule a script that will look for log files older than 24 hours old and then compress each of them into a compressed file format and then send the compressed file to a network share from where they will be extracted when necessary for analysis purposes.
It is important for us to automate this process.
I hope this makes more sense.
steve schofi...
5681 Posts
MVP
Moderator
Re: Compress and archive IIS Logs
Sep 03, 2006 10:42 PM|LINK
Steve Schofield
Windows Server MVP - IIS
http://iislogs.com/steveschofield
http://www.IISLogs.com
Log archival solution
Install, Configure, Forget
kryan762
8 Posts
Re: Compress and archive IIS Logs
Sep 04, 2006 01:16 AM|LINK
The script I posted previously will also zip files based off of date just change the line If iDiff > 5 Then to the days you want zipped.
The advantage of using a script such as thing is it does not require any additional software to be loaded on your web server. Keeping things simple "clean" and secure are important.
steve schofi...
5681 Posts
MVP
Moderator
Re: Compress and archive IIS Logs
Sep 04, 2006 04:06 AM|LINK
I don't want to sound like I'm pushing my EXE over the script, I almost hesitated in posting a link to it. I didn't want to sound like I was self-promoting my program. It comes down to whatever is easier for the person to support in their environment. I agree having a vbs script along with a compression file either gzip or winzip with the command line add-on works great, although winzip is 29.95 I think. My program is written using the .NET 2.0 framework and if this framework is loaded on the server, you can install my program on a separate machine then 'xcopy' without having to install on the server. It's whatever the person wants to-do. I've handled logs with scripts and that is what gave me the idea to develop it in the first place. Many administrators, including me use VBS scripts over 3rd party apps because they have control of the source code. Either way these are just a couple of ways for him to achieve what he wants.
PS: Thanks for posting your VBS script. You should publish on a blog or write a short article on your script and how you use it. I'm sure there are lots of people would appreciate that. If you want, I can publish on my blog along with giving you the proper credit. If you do publish, let me know and I'll link to the article. Thanks again!
Steve Schofield
Windows Server MVP - IIS
http://iislogs.com/steveschofield
http://www.IISLogs.com
Log archival solution
Install, Configure, Forget
BTandy
3 Posts
Re: Compress and archive IIS Logs
Sep 04, 2006 02:52 PM|LINK
I don't mean to be a pain, but the script seems to be the better option for me as I will be deploying this across many servers in a load balanced environment which do not currently run .Net Framework 2.0. I have copied the script to notepad and saved it as a .vbs file, but I am not quite sure what to do next. If I run the script I get a message saying:
weblogs.vbs startdirectory
I am not very experienced at script writing so will need a bit of guidance.
steve schofi...
5681 Posts
MVP
Moderator
Re: Compress and archive IIS Logs
Sep 04, 2006 03:38 PM|LINK
Steve Schofield
Windows Server MVP - IIS
http://iislogs.com/steveschofield
http://www.IISLogs.com
Log archival solution
Install, Configure, Forget