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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...