Compress and archive IIS LogsRSS

15 replies

Last post Mar 10, 2009 02:09 PM by tomkmvp

  • Compress and archive IIS Logs

    Aug 31, 2006 10:18 AM|BTandy|LINK

    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.
  • Re: Compress and archive IIS Logs

    Aug 31, 2006 10:54 AM|tomkmvp|LINK

    ok ... what are you looking for help with specifically?
  • Re: Compress and archive IIS Logs

    Aug 31, 2006 06:50 PM|kryan762|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

     

  • Re: Compress and archive IIS Logs

    Sep 01, 2006 01:00 AM|steve schofield|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

  • Re: Compress and archive IIS Logs

    Sep 03, 2006 08:40 AM|BTandy|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.

  • Re: Compress and archive IIS Logs

    Sep 03, 2006 06:42 PM|steve schofield|LINK

    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.

    Steve Schofield
    Windows Server MVP - IIS
    http://iislogs.com/steveschofield
    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget

  • Re: Compress and archive IIS Logs

    Sep 03, 2006 09:16 PM|kryan762|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.

  • Re: Compress and archive IIS Logs

    Sep 04, 2006 12:06 AM|steve schofield|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

  • Re: Compress and archive IIS Logs

    Sep 04, 2006 10:52 AM|BTandy|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.

  • Re: Compress and archive IIS Logs

    Sep 04, 2006 11:38 AM|steve schofield|LINK

    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.

    Steve Schofield
    Windows Server MVP - IIS
    http://iislogs.com/steveschofield
    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget

  • Re: Compress and archive IIS Logs

    Oct 13, 2006 09:50 AM|Londonsa|LINK

    Hi Guys

     

    I am also looking to zip my IIS files and send them to another server for storage.I agree ,I would rather use a script,no offense but I used the app and didnt get any joy there and the support email never got back.

     

    But any way the script seems okay but I would like to know ,does the script assume the log files are in the default place in Windows.I have told IIS to say my logs files on another directory ?Where in the script can I change that path ?

     

    Many Thanks

  • Re: Compress and archive IIS Logs

    Oct 13, 2006 12:42 PM|steve schofield|LINK

    If you are referring to the script posted.  All you need to do is specify the start folder in your command line argument.  There shouldn't be a need to update the script unless the gzip.exe location is different than specified in the script.    Here is the portion of the script that read the VBS arguments and kicks off the zipping process.  Sorry to hear you didn't like IISLogsLite.  The script below should meet your needs. Good luck.

    If WScript.Arguments.Count <> 1 Then
     WScript.Echo "weblogs.vbs startdirectory"
     WScript.Quit (1)
    End If

    Steve Schofield
    Windows Server MVP - IIS
    http://iislogs.com/steveschofield
    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget

  • Re: Compress and archive IIS Logs

    Mar 10, 2009 12:40 PM|santosh.kuamr|LINK

     I downloaded gzip.exe from gzip.org and it is not working with VBS provided in this thread. Am i missing something? is this gzip.exe has the same alogorithm which IIS using?

     

    Thanks.

  • Re: Compress and archive IIS Logs

    Mar 10, 2009 01:46 PM|tomkmvp|LINK

    Do you realize this thread is 2 1/2 years old?

    What does "not working" mean?  What happens?

  • Re: Compress and archive IIS Logs

    Mar 10, 2009 01:53 PM|santosh.kuamr|LINK

     does 2 1/2 matters as far as logic goes? And moreover this link is given as reply to my other thread, which i posted yesterday. So, i felt it is appropriate to write on this thread.

     Basically i want to know, gzip.exe, which is discussed here is the same exe which i downloaded? I have downloaded from gzip.org but it does not allow me to zip file names more than 8 characters long.

  • Re: Compress and archive IIS Logs

    Mar 10, 2009 02:09 PM|tomkmvp|LINK

    The person who posted that script hasn't posted here since September 2006 so there's not a very good chance that he'll respond.  Obviously his logic worked for him.

    It probably is the same but there's no way to know unless he responds, but it really shouldn't matter what zip exe you use.  As far as help with a particular zip program's capabilities and command line reference, you'd probably be best served following up with the developer of that exe ...