Windows Server Backup is a nice, built in solution for small companies wanting to ensure their local data is safe from hardware failure and corruption. The backup itself is built into Windows (no special license required) and will run to locally attached drives (USB, iSCSI, VHDX, etc.).
With all backups though, you are only as safe as your last good backup. There are many horror stories of companies setting up a backup routine and for any number of reasons that backup routine fails, and no one notices for 6 months until a restore is actually needed.
Although not built into the backup program natively, adding alert notifications to Windows Backup is a simple process. It takes about 15 minutes and adds a layer of protection to your backup routine that you may not think you need, until you actually do.
To get started, we need a way for the server being backed up to be able to send automated email notifications. For this, we will use a little command line tool called Blat.
Download the Blat binary files to the server you are backing up. I tend to put automation components inside a “C:\local” directory on the server but that is completely up to your personal preference.
In this example I have copied the Blat files to “C:\local\bin” and will create a notification batch file in “C:\local\script”.
Next, we need to create the actual notification script.
This can be a very simple batch file to send the email. Blat has many options available and a very nicely written help file you can get with the –h switch, or you can see online here.
In my case, I have set up a blat profile with the mail server settings. In the event you don’t have a local mail server, or something you can connect to easily you can install the SMTP service on your Windows server, and then use it to call a smart host, or whatever method you use to send/receive email from your location. If you do that, don’t forget:
- You may need to update your SPF record to include the sending IP.
- By default the Windows SMTP service installs in “Manual Startup” mode. You will want to switch the service to Start Automatically and it’s a good idea to put monitors on the server, at least to ensure the SMTP banner is available. It would be a shame to set this all up and then not receive your backup failure notification 🙁
Now we can create the simple notification script. The contents of my C:\local\script\Backup_Notification.bat file are:
REM Backup Failure Notification
SET CUSTOMER=Customer_Name
C:\local\bin\blat -p Notify -f noreply@systemlifeline.com -to support@systemlifeline.com -subject "%CUSTOMER% - Backup Failure Notification - %COMPUTERNAME%" -body "%CUSTOMER% backup task failed for %computername% on %date% at %time%. Manual review required."
Assuming we have Blat set up correctly we should be able to send a test email from a command prompt.
With our script in place and email flowing, the last thing we need to do is set up a Windows Scheduled Task that fires on an event.
Here I have created a new task called “Backup Failure Notification”.
On our “Triggers” tab, we add a new Trigger and select:
- Begin the task = On an event
- Settings = custom
Click the “New Event Filter” button.
Make the following selections:
- Logged = Anytime
- Event level = Error
- By Source
- Event Sources = Backup
With the trigger saved, go to the Actions tab and set it up to run your script:
Save your scheduled task and you now have your own backup alerts in place.
Since Windows Server 2008 Microsoft has set up Event Viewer to place backup events all in 1 location under “Event Viewer / Applications and Services / Microsoft / Windows / Backup / Operational”.
In some cases (maybe a customer has a local person changing out the USB backup drives once a week), you can have the event log trigger other actions from Scheduled Tasks. A successful backup is Event ID 4, or a completion event is ID 14.