Dlala
asked on
Script to email latest backup log
Dear All
Currently Im running daily system state backup on around 35 servers using dedicated backup administrator user account I need script that
will do the following:
1- check the last updated log file.
2- check the status of the log file (Success / Fail)
3- copy that log file to other location (that mean 35 log file in one folder)
4- send me e-mail containing the folder that have all 35 log file
I check many scrips that may do some of the past request but its not working so please any one can help me on this.
Currently Im running daily system state backup on around 35 servers using dedicated backup administrator user account I need script that
will do the following:
1- check the last updated log file.
2- check the status of the log file (Success / Fail)
3- copy that log file to other location (that mean 35 log file in one folder)
4- send me e-mail containing the folder that have all 35 log file
I check many scrips that may do some of the past request but its not working so please any one can help me on this.
ASKER
Hi Dear i'm using windows NTBackup on windows server 2003 which don't have option to send e-mail
Do you have an SMTP server that you can send your emails through, that is contactable by the server that will be running the script?
Regards,
Rob.
Regards,
Rob.
ASKER
yes we have SMTP server but any information about the script
Yeah, we'll write something shortly...just getting some info....
Will the script
a) be run from one computer, which will then pull the log files from each of the servers, or
b) run on each PC, and only copy the latest log from itself, to a central location?
I'm assuming it would be option A, so that you can empty the target folder before starting to copy the latest files?
When you say you want the email to contain the folder, do you just mean you want the folder path in the body of the email?
Regards,
Rob.
Will the script
a) be run from one computer, which will then pull the log files from each of the servers, or
b) run on each PC, and only copy the latest log from itself, to a central location?
I'm assuming it would be option A, so that you can empty the target folder before starting to copy the latest files?
When you say you want the email to contain the folder, do you just mean you want the folder path in the body of the email?
Regards,
Rob.
ASKER
ok dear Rob
yes it's option A for example it will be on one central server for example SMTP server the script will do the following
1- check the last update backup log file on each of 35 server (OR) i can configure other script to just Xcopy the last log from each server then it will cleare all the logs then move to the central server
2- after all logs arrive to the central folder from the 35 server the folder that contain all log will be zipped and be attaced as send to me via e-mail
yes it's option A for example it will be on one central server for example SMTP server the script will do the following
1- check the last update backup log file on each of 35 server (OR) i can configure other script to just Xcopy the last log from each server then it will cleare all the logs then move to the central server
2- after all logs arrive to the central folder from the 35 server the folder that contain all log will be zipped and be attaced as send to me via e-mail
OK, makes more sense now...I'll write a script tomorrow...it's late afternoon here...
Regards,
Rob.
Regards,
Rob.
ASKER
ok i see thanks it will be Useful not only for me but in general.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, I forgot to mention, for the zipping of the logs, this requires that you have the UltimateZip Command Line Tool available from here:
http://www.ultimatezip.com/download.htm
Regards,
Rob.
http://www.ultimatezip.com/download.htm
Regards,
Rob.
ASKER
Thanks Dear Rob
i think it will work i will modify it and let you know one more thing can you just modify that after it collect the log file can it clear the hall folder in
C:\Documents and Settings\user\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\
so i will be sure that it collect the last log on each server.
i think it will work i will modify it and let you know one more thing can you just modify that after it collect the log file can it clear the hall folder in
C:\Documents and Settings\user\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\
so i will be sure that it collect the last log on each server.
It doesn't really need to, but it could.....It will always find the file that has the latest modified date.
In any case, this will now also copy the latest log file to the central location, then delete all log files, except that one, from the local folder on each machine.
Regards,
Rob.
In any case, this will now also copy the latest log file to the central location, then delete all log files, except that one, from the local folder on each machine.
Regards,
Rob.
' Computer name array
arrComputers = Array( _
"SERVER1", _
"SERVER2", _
"SERVER3" _
)
' Backup log variables
' This should be the local path on each server that the logs are written to
strPathToLogs = "C:\NTBackup\Logs"
' This should be the UNC path of the location to copy the latest logs to
strCopyLogsTo = "\\Server\Share\LatestLogs"
' Provide the path to the Ultimate Zip command line tool here
strUZip = "\\server\share\UltimateZip Command Line Tool\uzcomp.exe"
' This is the name of the zip file that you want to create
strZipFile = "\\Server\Share\LatestLogs\LatestBackupFiles.zip"
' Email variables:
strServer = "smtp_server_name"
strTo = "recipient@domain.com"
strFrom = "sender@domain.com"
strSubject = "Compressed Backup Logs"
strBody = "Please find attached the compressed backup logs." & VbCrLf
If Right(strCopyLogsTo, 1) <> "\" Then strCopyLogsTo = strCopyLogsTo & "\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strCopyLogsTo) = True Then
' This line will delete all of the logs inthe destination folder before starting to copy the latest ones
objFSO.DeleteFile strCopyLogsTo & "*", True
' Now go through each of the computers log paths
For Each strComputer In arrComputers
strLogPath = "\\" & strComputer & "\" & Replace(strPathToLogs, ":", "$")
If Right(strLogPath, 1) <> "\" Then strLogPath = strLogPath & "\"
If objFSO.FolderExists(strLogPath) = True Then
dteLatestDate = CDate("01/01/1901")
strLatestFile = ""
For Each objLogFile In objFSO.GetFolder(strLogPath).Files
If objLogFile.DateLastModified > dteLatestDate Then
dteLatestDate = objLogFile.DateLastModified
strLatestFile = strLogPath & objLogFile.Name
End If
Next
If strLatestFile <> "" Then
objFSO.CopyFile strLatestFile, strCopyLogsTo, True
' Now delete all of the log files from that folder, except the latest one.
For Each objLogFile In objFSO.GetFolder(strLogPath).Files
If LCase(objLogFile.Name) <> LCase(Mid(strLatestFile, InStrRev(strLatestFile, "\") + 1)) Then
objFSO.DeleteFile strLogPath & objLogFile.Name, True
End If
Next
End If
Else
MsgBox "Could not find " & strLogPath
End If
Next
' Now compress the log files
Set objShell = CreateObject("WScript.Shell")
strUZip = objFSO.GetFile(strUZip).ShortPath
If objFSO.FileExists(strZipFile) = True Then objFSO.DeleteFile strZipFile, True
strCommand = "cmd /c " & strUZip & " -m -c2 -w """ & strZipFile & """ """ & strCopyLogsTo & "*.*"""
objShell.Run strCommand, 0, True
' Now send the file
SendEmail strServer, strTo, strFrom, strSubject, strBody, strZipFile
MsgBox "Email has been sent."
Else
MsgBox "Could not find " & strCopyLogsTo
End If
Sub SendEmail(strServer, strTo, strFrom, strSubject, strBody, strAttachment)
Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.To = strTo
objMessage.From = strFrom
objMessage.Subject = strSubject
objMessage.TextBody = strBody
objMessage.AddAttachment strAttachment
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
Set objMessage = Nothing
End Sub
ASKER
yes it's great many thanks.
Great. Thanks for the grade.
Regards,
Rob.
Regards,
Rob.
all backup software i've seen has an option to email the backup log to the administrator.