Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

Email log files from backup windows 2003

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
georgopanos
Asked:
georgopanos
  • 5
  • 4
1 Solution
 
brendanmeyerCommented:
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
 
georgopanosAuthor Commented:
how do I run the script, do i use cscript?
0
 
brendanmeyerCommented:
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
georgopanosAuthor Commented:
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
 
georgopanosAuthor Commented:
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
 
brendanmeyerCommented:
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
 
georgopanosAuthor Commented:
Thank you for all your help so far......
0
 
georgopanosAuthor Commented:
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
 
brendanmeyerCommented:
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now