Solved

Email log files from backup windows 2003

Posted on 2010-11-11
9
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

696 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