Jump to content

Need help backing up server logs


Recommended Posts

I have been working on this script that creates a zip file by month and moves the proper log files to that specific zip file, then delete the log files and send an email What I'd like it to do now is have the ability to tell the script, zip files x days old and add tracking information on the email that is being sent to include all log files that have been moved to a specific zip file. Hopefully someone can assist.Version:0.9 StartHTML:00000107 EndHTML:00019141 EndFragment:00019101 EndFragment:00000000 '============================================================================= '  Scheduled Task - Visual Basic ActiveX Script '============================================================================= '  Date    : 05/31/2012'  Auth    : Kookers'  Desc    : VBScript file that Zips log files by Month and Year'  Opt     : '============================================================================= strRoot = "C:\WINDOWS\system32\LogFiles\MSFTPSVC1"strExt = "log"strServer = "SERVER_NAME"blnDeleteOriginals = TrueNumberOfDays = 15'Anything older than this many days will be archived and deleted'Constants / VariablesConst EmailFrom = "LogFileCleanup@MyDomain.com"Const EmailTo = "kookers@MyDomain.com"Dim CurrentDateDim MsgDim fsCurrentDate = NowSet fs = CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject")Set objRoot = objFSO.GetFolder(strRoot)Set objEmail = CreateObject("CDO.Message")ForEach objFileIn objRoot.Files    strFile = objFile.Path    strFileExt = objFSO.GetExtensionName(strFile)        IfLCase(strFileExt) = LCase(strExt) Then        dtmFile = objFile.DateLastModified        strZIP = strRoot & "\" & Year (dtmFile) &_            MonthName(Month(dtmFile)) & ".zip"        ZipFile strFile, strZip                'If blnDeleteOriginals Then        If blnDeleteOriginalsANDDateDiff("d",objFile.DateCreated,Date) > 0Then            objFile.DeleteTrue        EndIf    EndIfNextSub ZipFile(strFileToZip, strArchive)    Set objFSO = CreateObject("Scripting.FileSystemObject")        IfNot objFSO.FileExists(strArchive) Then        Set objTxt = objFSO.CreateTextFile(strArchive)        objTxt.Write"PK" & Chr(5) & Chr(6) & String(18, Chr(0))        objTxt.Close    EndIf        WScript.Sleep2000    Set objApp = CreateObject("Shell.Application")    intCount = objApp.NameSpace(strArchive).Items.Count + 1    objApp.NameSpace(strArchive).CopyHere strFileToZip        Do        WScript.Sleep200        Set objNameSpace = objApp.NameSpace(strArchive)        IfNot objNameSpaceIsNothingThen            If objNameSpace.Items.Count = intCountThen                ExitDo            EndIf        EndIf    LoopEndSub        objEmail.From = EmailFromobjEmail.To = EmailToobjEmail.Subject = "Log File Complete on Server"'objEmail.Textbody = "Log Files for %Server% have been Zipped and deleted from server"'objEmail.TextBody = "Log File original path"(strRoot)objEmail.TextBody = "The monthly scheduled task to remove logs on" & "strServer" & "older than 30 days has completed." & vbCrLf & vbCrLf & "Deleted " & intFiles & " File(s) on " & strPath2Logs & vbCrLf & _    vbCrLf & "FILES:" & vbCrLf & "===================" & vbCrLf & strFilesobjEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ExchangeServerName.MyDomain.com"objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25objEmail.Configuration.Fields.UpdateobjEmail.Send    

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...