Configuring email alerts for Windows Server Backups
Binary Royale is an IT consultancy company based in the East Midlands. We spend all of our time with clients, helping them to make good decisions about their IT. When we come across issues that would be useful to others we “try” to post the answers on our website – www.binaryroyale.com . We cover Derby and Derbyshire, Nottingham and Nottinghamshire mainly, but do also have clients further afield. Please browse our website to see what we offer – thanks, and enjoy the blog
Windows Server backup is a credible backup solution for small environments when backup space is plentiful and an integrated centrally managed solution is not required or not affordable. However one thing that is missing from WSB is any sort of alerting to let you know when your backups have completed or failed. Without this it’s necessary to manually login and check on the backup as they are run – a tedious waste of your time, I’m sure you’ll agree.
However there is a better solution. Using Windows Task Scheduler and a few simple powershell scripts it’s possible to get email alerts sent to you as soon as your backup job completes – or fails.
I’ll assume that you have WSB configured and working on the server in question – there are plenty of on-line resources available to help you get this set up and working.
- Create you alert scripts. You need 3 Powershell scripts – 1 each for a successful backup, a failed backup and another to alert you that the backup disk is full. The content for each is as follows:
$SmtpClient = new-object system.net.mail.smtpClient $SmtpServer = "x.x.x.x" $SmtpClient.host = $SmtpServer $computer = gc env:computername
$From = "email@example.com" $To = "firstname.lastname@example.org" $Title = "Backup Complete on " +$Computer $Body = "Backup Completed Successfully " + $computer $SmtpClient.Send($from,$to,$title,$Body)
The details in red need to be changed to suit your environment, and are the same in all 3 scripts. The details in green are different in each script, and should be changed to suit the script – i.e. “Backup Failed on ” or “Backup drive full on “. I save the scripts as BackupComplete.ps1, BackupFailed.ps1 and BackupFull.ps1.Â I put these in c:usersadministrator, but the location is up to you really.
- You can test the scripts at this point by running them manually in Powershell. You may need to set the script execution policy to remote signed to allow the script to run if this hasn’t already been done on your server. Run
at the powershell prompt for more info. If the script runs, but you don’t receive the emails, check your mail server config to make sure that it will allow the server to send via it without authentication.
- Open Windows Server Manager on the server running the backup, or a management server if the backup is running on a Server Core machine. Expand the Configuration node and the Task Scheduler sub-node. Click on Task Scheduler Library sub node.
- Right click in the Task Scheduler Library middle pane, and select Create New Task. The Create New Task dialog box will appear.
- On the General tab, give the task a name, a description if you like, and change the Security options as below:
- On the Triggers tab, press the “New” button to add a new Trigger. Select “On an Event” from the Begin the task drop-down. Select Microsoft-Windows-Backup/Operational for the Log, Backup for the Source, and specify the correct EventID depending on which task you are creating. The backup completed EventID is 4, the backup failed EventID is 5, and the backup full EventID is 50.
- On the Actions tab, press the “New” button to add a new Action. Select Start a program from the Action dropdown list. Enter powershell for the program, and add the argument that points it to the script that you created earlier. e.g. for the backup completed task, I would set the argument to:
-command “& c:usersadministratorBackupComplete.ps1”
- For the Conditions tab, you can leave the Settings as they are:
- On the Settings tab, adjust the settings as below:
- The History tab will not contain any info at this stage, so you can press OK to save the task. You will be prompted to enter the server administrator password.
- Repeat items 4 – 10 to add the second and third tasks to the task scheduler.
- You should now be able to right click on each task and run it manually, and the corresponding email should duly arrive in the appointed inbox. If not, check that the scripts run properly from the Powershell prompt, and that you have entered the script arguments correctly.
- You should now receive an email after your next scheduled backup cycle, letting you know how that backup went. However, it’s prudent to manually keep an eye on the backups until you’re happy that the emails are reporting the backup status correctly.
Thanks for reading.