|Home > Misc > Emailing The NTBackup Log With VBScript|
While it has its quirks and limitations, NTBackup is a fairly decent backup application for Windows NT4 all the way up to Windows Server 2008 in the home and small business environment. It supports tape and disk based backups, bare metal disaster recovery and if you know the command line switches, can be fairly powerful when combined with the Windows task scheduler.
Of course if you are using the task scheduler to schedule multiple backup jobs, say in the middle of the night, perhaps across many different systems, you need to be vigilant in checking out the log files to make sure those jobs are running. Since NTBackup buries the logs deep in the Application Data directory of the user account under which the job runs, this typically involves either sharing that directory or RDP'ing into the machine and manually checking the log. NTBackup also keeps the log in 10 rolling text files named Backup01.log to Backup10.log. This makes it a little annoying as every time your job runs, the result will be in a different file.
To mitigate this annoyance, I wrote a simple VBScript which will automatically find the most recent NTBackup log file, and email it to a specified address. That way, every morning I have in my inbox all the logs I need to check and it is easy to spot any issues which may require attention.
The simple script is presented below. It relies on the free AspEmail ActiveX component to send mail, and you will need to have an accessible SMTP server.
Option Explicit Dim fso, File, RecentFile, LogFilePath, LogFile, LogFileContents, Mail LogFilePath = "C:\Documents and Settings\(BACKUP USER PROFILE DIRECTORY)\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\" Set fso = CreateObject("Scripting.FileSystemObject") Set RecentFile = Nothing For Each File in fso.GetFolder(LogFilePath).Files If (RecentFile is Nothing) And (fso.GetExtensionName(LogFilePath & File.Name)) = "log" Then Set RecentFile = File ElseIf (File.DateLastModified > RecentFile.DateLastModified) And (fso.GetExtensionName(LogFilePath & File.Name)) = "log" Then Set RecentFile = File End If Next 'note the parameters. First one is forreading, 2nd is to not create the file if it doesn't exist, 3rd is to open as unicode Set LogFile = fso.OpenTextFile (LogFilePath & RecentFile.Name, 1,False,-1) Do Until LogFile.AtEndOfStream LogFileContents = LogFileContents & LogFile.ReadLine & vbCRLF Loop LogFile.Close Set Mail = CreateObject("Persits.MailSender") Mail.Host="(SMTP SERVER)" Mail.Port="25" Mail.From="(SENDER'S ADDRESS)" Mail.FromName="(SENDING SYSTEM) Backup Log" Mail.Subject="(SENDING SYSTEM) Backup" & " " & Now Mail.AddAddress("(RECIPIENT ADDRESS)") Mail.Body=LogFileContents Mail.Send Set Mail=Nothing
Note that most well behaved mail servers these days require SMTP authentication to send messages to outside domains. If you receive errors from AspMail (particularly a "550 Relaying Denied") you may need to modify the script to authenticate to the server with a known user name/password. See the AspEmail security documentation on how to use the Username and Password properties of the control to send authentication info to your server.
NTBackup is not installed by default in Windows XP Home. To install it, follow these instructions: How to install NTBACKUP on Windows XP Home.
While NTBackup is not included with Windows Vista or Windows 2008 Server, it can be installed by following these instructions: How to install NTBackup on Server 2008. Note that you will need to turn on (Vista) or install (Server 2008) the Removable Storage Management service as this is not done by default in these versions of Windows.
Back To Misc Page | Mail Me | Search