Automated email notification for Windows backup

email notification

email notification

The native backup utility found on Windows servers is one cool application that has saved many SMBs real cash!  Apart from fulfilling its main functionality, it is found to be very reliable and effective. Problems arise when extra features are required such as, backing up to external storage devices and/or utilizing advanced backup features! One useful feature that is standard in purchasable applications is email notification of backup jobs. The script below gives you that functionality!!!! It’s free and simple to implement!!!!

The implementation steps of the script are as follows:

  1. Create a backup job using Windows backup – Start/All Programs/Accessories/System Tools/Backup and set a job schedule
  2. Open the window Scheduled Tasks – Start/Control Panel/Scheduled Tasks and find the newly created scheduled job.
  3. From the properties window of this job copy the highlighted text from the Run text field
  4. Copy this text in a new batch file called ‘mybackup.bat’ (any name you like without quotes)
  5. Take a note of the batch file location and enter the full path in the Run text field of step 3 ex: c:\documents\mybackup.bat
  6. Close the properties window by clicking OK and enter an admin password if prompted
  7. Add the sample script shown below in the batch file after the text entered in step 4
  8. Edit the script text to reflect your email & path settings

Sample script

Copied text from step 3 goes here

@echo off
set Sender=”source email addess”
set Receiver=”your email address”
set Host=”IP address of source email server”
set Subject=”Backup name/title”

set logdir=”%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data”
REM ex – C:\Documents and Settings\administrator\ for %USERPROFILE%
set result=”%temp%\latestlog.txt”

pushd %logdir%
for /f “tokens=1 delims=” %%I in (‘dir /B /O-D’) do (
 if “%%~xI”==”.log” (
   type “%%~fI” > %result%
   goto :end

c:\windows\system32\blat.exe %result% -f %Sender% -to %Receiver% -server %Host% -subject %Subject%
del /q /f “%result%”




Explanation of the sample script:

==> stores the current directory for use by the POPD command, then change to the specified directory

for /f “tokens=1 delims=” %%I in (‘dir /B /O-D’) do
=> parse each line of the directory listing (log files) and get the name of each file one by one

dir /B /O-D  ==> remove heading info from directory list, and list files by date in reverse order

if “%%~xI”==”.log”
==>if the current file (its extension only) is .log

type “%%~fI” > %result%
==> then copy the contents of the current log file to the variable file latestlog.txt

c:\windows\system32\blat.exe  ==> Blat is a Win32 command line utility that sends eMail using SMTP –

Leave a Reply

Your email address will not be published. Required fields are marked *