Azure backup is a fantastic tool for the enterprise but if you have a small set of servers that you are backing up daily there is no easy way to get visibility of backup status. Of course you could log into each server and check but that is time consuming and we generally have better things to do with our time. So with a bit of PowerShell and good old task manager we can get some simple reporting.
The basic concept is to have a couple of tasks that are triggered by events and a couple of PowerShell scripts to send emails. Of course in the pre-Server 2012 days you could send email from Task Scheduler but that’s not an options anymore…..that’s progress I guess!
For this to work you will need to have a SMTP server available that can relay the messages out. Of course if you have a Azure VM you could set up a SMTP using IIS but that is out of scope of this post.
So lets start. I am of course assuming you’ve installed Azure Backup Agent onto the server and it’s configured.
Failed Backups
First off you’ll need to fire up Task Scheduler and create a task. Make sure it’s set to run under a service account with local admin access and can be run if the user isn’t logged in.
Next we need to create a trigger for our task
Here change the trigger type to “On an event”
Select the “Custom” button
Set “Logged” to “Any Time”
Select “Critical”, “Warning” and “Error” Event level
In the “Event Logs” select the “CloudBackup” tree
And now the magic, in the “Include/Exclude Event IDs” add the following: 5,10,11,12,13,14,16,18
The rest of the dialogue box can be left and you can click “OK”
Now move to the “Actions” tab and click “New”
Here we’ll add the PS1 file that we want to execute (don’t worry we’ve not created this file yet).
Set the “Action” to “Start a program”
Enter “powershell.exe” into the “Program/Script” box
Finally in the “Add agruments” box add:
-file “drive:\folder\filename.ps1”
Click “OK” and your failed backup task is complete. Now we need to make the PowerShell file that this task executes.
Create a file i.e. “BackupEmailFailure.ps1” and add that following text (of course you’ll need to edit this to suit your environment)
send-mailmessage -from “ServerName <ServerName@acompany.com>” -to “Backup Monitoring <backupmonitor@acompany.com>” -subject “ServerName – Backup FAILED” -body “Backup of ServerName has Failed or has an error” -smtpServer smtp.accompany.com
Successful Backups
Ok, lets go back to Task Scheduler and create a new task. Make sure it’s set to run under a service account with local admin access and can be run if the user isn’t logged in.
Next we go off to the trigger tab
Set the “Begin the task” to “On an event”
Select “Basic”
Select the “CloudBackup” log
Set the source to “CloudBackup”
And finally set the “Event ID” to “3”
Click “OK”
Now move to the “Actions” tab and click “New”
Here we’ll add the PS1 file that we want to execute (don’t worry we’ve not created this file yet).
Set the “Action” to “Start a program”
Enter “powershell.exe” into the “Program/Script” box
Finally in the “Add agruments” box add:
-file “drive:\folder\filename.ps1”
Click “OK” and your failed backup task is complete. Now we need to make the PowerShell file that this task executes.
Create a file i.e. “BackupEmailFailure.ps1” and add that following text (of course you’ll need to edit this to suit your environment)
send-mailmessage -from “ServerName <ServerName@acompany.com>” -to “Backup Monitoring <backupmonitor@acompany.com>” -subject “ServerName – Backup Successful” -body “Backup of ServerName has been successful” -smtpServer smtp.accompany.com
You should now have some simple email alerts for your Azure Backup Agents on your servers.
All done!
Additional Information: Useful link to a table showing the event ID’s for Cloud Backup here
Hi Rob
Thank you for sharing this. Exactly what I need without any fuss and just works (well in testing anyway) Will be good to hopefully get an email alert overnight as to what my Azure backup is up to. Much appreciated.
Cheers
Justin
One quick question on this powershell script…how do you get it to work when using Azure Backup to backup VMs hosted in Azure? You don’t install the Azure Backup Agent to those machines, so the CloudBackup/Operational logs and CloudBackup Source are not available in the Task Scheduler.
Hi Kevin
You are correct the AzureVM backup is performed without an agent installed on the OS. So for this kind of backup this email alert won’t work. I am sure there would be a way to alert on this but I’ve not had the chance to look into this. Maybe Operational Insights might be an alternative?
Hi,
Here is an article with a script that will generate a complete mail-report of the Azure Backups.
It specifies name, status (completed/failed/aborted), start time, stop time, uploaded data and total backup data.
http://blog.jocha.se/tech/azure-backup-mail-report-script
Hey, thanks for sharing very useful information about Azure Backup. Glad to see your other blogs about Azure Backup service.