If you’ve ever had to configure a server backup using Windows Server Backup (WSB), you may have noticed that WSB is lacking in a few basic features such as email notifications for backup completions or failures forcing you to check event logs to see if backup was successful or not. What follows is my account of how to create such a system and allow as minimal fuss as possible. Please note that this solution utilizes a Gmail email account for sending email to your configured recipients and was pieced together from multiple sources online to accomplish this goal. I will add full credits where due at the end of this post.
WSB is a great tool for it’s price, it’s free, supported by Microsoft out of the box and works surprisingly well to backup a single server to external USB drives or to an iSCSI mounted network file share.
We utilize an iSCSI share on a FreeNAS backup server to backup all our Windows Servers. The backup server is then backed up weekly to USB drives and rotated offsite.
WSB is included in Windows Server versions 2008 through 2012 R2 and will be included in Server 2016 when released. One (currently) missing feature of WSB is the ability to email notifications out to inform users of success or failure. If you’ve used proprietary backup solutions before, you’ve likely utilized this feature.
This is an important feature to have for any backup system as knowing if your backups completed or not can save countless hours when disaster strikes.
Let’s fix this using the Windows Task Scheduler, a free program called sendEmail and a few basic batch scripts to tie it all together.
First off, you’ll want to create your backup schedule using WSB. Configuring this is simple using the following step by step guide but is beyond the scope of this article. Once your backup schedule is created, you can continue with this guide.
Every time Windows Server Backup starts and completes it generates an event in the Windows Event Viewer. The Task Scheduler can detect when specific Event IDs are generated and this leverages that capability.
Next, you will need to download the sendEmail program from http://caspian.dotconf.net/menu/Software/SendEmail. Once downloaded, extract it to your system. I chose to extract it to C:\sendEmail\ and this guide will follow as such.
Next, you will need to create 2 batch scripts: backup-failure.bat and backup-success.bat. A better programmer might make this a single script and provide an argument for success or failure, but for simplicity sake, and as I’m not a great programmer, I chose this method.
NOTE: Modify the following scripts to suit your needs replacing relevant info to fit your environment. Specifically, you will need to modify the following operational switches:
- -f (the from address) firstname.lastname@example.org
- -t (the to address) email@example.com
- -cc (address to carbon copy the message to) firstname.lastname@example.org
- -xu (gmail username) email@example.com
- -xp (your gmail password) your.gmail.password
Additionally, you will want to modify the subject and body fields to include your specific domain and servername info.
- -u (the subject field) DOMAIN\SERVERNAME
- -m (the body field) DOMAIN\SERVERNAME
Here is backup-success.bat
c:\sendEmail\sendEmail.exe -o tls=yes -f firstname.lastname@example.org -t email@example.com -cc firstname.lastname@example.org -s smtp.gmail.com:587 -xu email@example.com -xp your.gmail.password -u Backup on DOMAIN\SERVERNAME Completed Successfully -m The backup on DOMAIN\SERVERNAME completed with an EventID 4 which indicates a successful completion. Please continue backup drive rotation. Have a nice day!
Here is backup-failure.bat
c:\sendEmail\sendEmail.exe -o tls=yes -f firstname.lastname@example.org -t email@example.com -cc firstname.lastname@example.org -s smtp.gmail.com:587 -xu email@example.com -xp your.gmail.password -u Backup on DOMAIN\SERVERNAME has failed -m The backup on DOMAIN\SERVERNAME did not complete successfully. Please see event logs on DOMAIN\SERVERNAME for further details.
You can test each script by launching a command prompt, navigating to the C:\sendEmail\ directory and launching each script manually.
Documentation, support and command line options for sendEmail are available on the software’s website. I have linked the most common command line options below:
Save these files in a location from which they can be executed. In this example, I will be storing them inside the C:\sendEmail\ folder.
Next, you will need to open the Task Scheduler. Click on Create Task… on the right column. On the General tab You will want to give it a descriptive name such as Successful Backup and also a Description. Select to Run whether user is logged on or not.
Under the Triggers tab click to create a new trigger. Begin the task On an event. Under Settings, Log: Microsoft-Windows-Backup/Operational – Source: Backup – Event ID: 4 . At the bottom check that it is Enabled and set it to stop task if ran longer than 30 minutes.
Under the Actions tab you will click New and select the Action to Start a Program. The program can be a batch file and for the argument type -Command “C:\sendEmail\backup-success.bat”
Click OK to save this task.
You will repeat this and create a new task for the instance in which the backup fails. There are multiple Event IDs that can be generated for a failure so you will need to input all of them on the Triggers tab. You will also make sure to set the action to point to the backup-failure.bat script similar to your Success task. On the Triggers you will create them the same way and use Log: Microsoft-Windows-Backup/Operational – Source: Backup. For the Event ID You need to use 5, 7, 8, 9, 17, 22, 49, 50, 52, 100, 517, 518, 521, 527, 544, 545, 546, 561, 564 and 612.
If you have to do this on multiple servers, you can export and import the tasks so you don’t have to repeat this process for each server.
Finally, run a test backup job. Once it completes, you should see your email notifications upon success or failure.
Windows Server Backup – https://technet.microsoft.com/en-us/library/cc770266(v=ws.10).aspx
sendEmail – http://caspian.dotconf.net/menu/Software/SendEmail/
Source Article – http://www.triatechnology.com/email-notifications-with-windows-server-backup/