To check the outcome of Microsoft Azure Backup execution we can take advantage of the fact that, if the backup fails, some events are generated.
Prepare script to send email
Copy and paste the following code in a new file and modify it with your data (mail server, user, password, messages).
$SMTPServer = "YOUR SMTP SERVER" $SMTPPort = "25" $Username = "USERNAME TO ACCESS SERVER" $Password = "PASSWORD" $to = "Email recipient" # $cc = "cc email recipient" $subject = "Error Backup MyServer" $body = "backup failed" # $attachment = "" $message = New-Object System.Net.Mail.MailMessage $message.subject = $subject $message.body = $body $message.to.add($to) # $message.cc.add($cc) $message.from = $username # $message.attachments.add($attachment) $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort); $smtp.EnableSSL = $true $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password); $smtp.send($message) write-host "Mail Sent"
Save it as file with extension .ps1
Creating a new Task
- Open the Task Scheduler : Control Panel -> Administrative Tools -> Task Scheduler
- Right-click the “Task Scheduler Library” branch, and select the New Folder option.
- Type a name for the folder. For example, MyTasks.
- Expand the “Task Scheduler Library” branch, and select the MyTasks folder.
- Click the Action menu.
- Select the Create Task option.
Task to check Azure Backup
- In the Name field you can write something like “Check Micrososft Agent Backup”.
- Click the Triggers tab.
- Click the New button.
- Use the “Begin the task” drop-down menu to select “On a Event”
- Click custom option under the Settings section.
- Click the Edit Event Filter… button.
- Go the XML tab and at the bottom of the menu press the edit query manually button.
- Copy and paste the below XML and OK the changes.
<QueryList> <Query Id="0" Path="CloudBackup"> <Select Path="CloudBackup">*[System[(Level=1 or Level=2) and (EventID=5 or EventID=10 or EventID=11 or EventID=12 or EventID=13 or EventID=14 or EventID=16 or EventID=18)]]</Select> </Query> </QueryList>
- Click the Actions tab.
- Click the New button.
- Browse on the previous powershel script
- Clicck OK to save the task
From now on, an email should be sent to you when the backup fails.