Solved

Email log files from backup windows 2003

Posted on 2010-11-11
9
407 Views
Last Modified: 2012-05-10
I have a windows 2003 server that is using the windows backup utility to backup to an external drive. It does not have the option to email log files. Is there a way to easily grab the newest file from the DIR that contains the files and email them nightly using a script? I do not want to use another piece of software I would prefer a simple script.
0
Comment
Question by:georgopanos
  • 5
  • 4
9 Comments
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 500 total points
ID: 34117540
heres a script that will email a log file that was create the day the script was run

http://www.andrewtaylor.me.uk/wp-content/uploads/emailbackuplog.txt
0
 

Author Comment

by:georgopanos
ID: 34117769
how do I run the script, do i use cscript?
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 34124273
just make sure you have edited the path to the logs, smtp server and the email address,

then yes use cscript, or create a task that will run after the backup finishes.

eg: cscript <filename.vbs>
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:georgopanos
ID: 34124847
So the way it is setup where it asks for a filename put nothing and it will find the newest file in the DIR? Can I use  "*.log"
0
 

Author Comment

by:georgopanos
ID: 34124940
I am sorry to be a pain but is there a way to merge the file into the body of the email?

The script sends with no problems....
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 34125542
uncomment the
'oCDO.AddAttachment BACKUP_LOG_PATH & "\" & logFilePath
to also attach the file.

this should work
Option Explicit

' ***************************************************************
' * Email NT Backup log file
' * © Andrew Taylor 2008 www.andrewtaylor.me.uk
' * Free to use providing this acknowledgement remains in place
' ***************************************************************

' Dim variables
Dim oFSO, oWshNetwork, oCDO, oFolder, oFiles, oFile, objFile
dim strFileName, strComputerName, strContents

' Create Objects
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWshNetwork = WScript.CreateObject("WScript.Network")


' Set constants
Const BACKUP_LOG_PATH = "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"
Const EMAIL_RECIPIENT = "you@yourdomain.com"

' Set variable defaults
strFileName = ""
strComputerName = oWshNetwork.ComputerName

' Start script
Set oFolder = oFSO.GetFolder(BACKUP_LOG_PATH)

Set oFiles = oFolder.Files

For Each oFile in oFiles
	If oFSO.GetExtensionName(oFile.Name) = "log" Then
		If DateValue(oFile.DateLastModified) = Date() Then
			strFileName = oFile.Name
			Exit For
		End If
	End If
Next

If strFileName <> "" Then

	EmailLog(strFileName)

Else

	EmailError

End If

Sub EmailLog(logFilePath)

	Set oCDO = CreateObject("CDO.Message")

	oCDO.Subject = "Backup Log - " & strComputerName
	oCDO.From = strComputerName & "@yourdomain.com"
	oCDO.To = EMAIL_RECIPIENT
	
	Set objFile = objFSO.OpenTextFile(BACKUP_LOG_PATH & "\" & logFilePath, 1)
	strContents = objFile.ReadAll
	objFile.Close

	oCDO.TextBody = "Backup log attached for " & strComputerName & vbCrLf & strContents

	'oCDO.AddAttachment BACKUP_LOG_PATH & "\" & logFilePath

	oCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

	oCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yourdomain.com"

	oCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

	oCDO.Configuration.Fields.Update

	oCDO.Send

	set oCDO = Nothing


End Sub

Sub EmailError

	Set oCDO = CreateObject("CDO.Message")

	oCDO.Subject = "Backup Log Missing - " & strComputerName
	oCDO.From = strComputerName & "@yourdomain.com"
	oCDO.To = EMAIL_RECIPIENT

	oCDO.TextBody = "No backup log found on " & strComputerName & " for today"

	oCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

	oCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yourdomain.com"

	oCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

	oCDO.Configuration.Fields.Update

	oCDO.Send

	set oCDO = Nothing


End Sub

set oFSO = Nothing
Set oWshNetwork = Nothing

Open in new window

0
 

Author Comment

by:georgopanos
ID: 34145937
Thank you for all your help so far......
0
 

Author Comment

by:georgopanos
ID: 34147329
small issue it is not picking up the newest file, might there be something in the code that I need to modify? I looked through the code and cannot find anything!
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 34149930
it will email a log file that was created on the day it was run

eg: backup finishes at 2am on the 17/11/2010
then the script needs to be run on 17/11/2010 after the back is finished

have a look at implementing this function if you want the newest file
found on: http://www.ureader.com/msg/1677440.aspx

Function GetNewestFile(ByVal sPath)

   sNewestFile = Null   ' init value

   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFolder = oFSO.GetFolder(sPath)
   Set oFiles = oFolder.Files

   ' enumerate the files in the folder, finding the newest file
   For Each oFile In oFiles
     On Error Resume Next
     If IsNull(sNewestFile) Then
       sNewestFile = oFile.Path
       dPrevDate = oFile.DateLastModified
     Elseif dPrevDate < oFile.DateLastModified Then
       sNewestFile = oFile.Path
     End If
     On Error Goto 0
   Next

   If IsNull(sNewestFile) Then sNewestFile = ""

   GetNewestFile = sNewestFile

End Function
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
Viewers will learn the different options available in the Backstage view in Excel 2013.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question