Step by Step – Windows Server Backup on Windows Server 2012 R2 with Email Alerts

Setting up Windows Server Backup with email alert notifications

For Active Directory Backup and Recovery Microsoft's preferred tool is Windows Server Backup (WSB). WSB got improved a lot in the latest versions of Windows Server. It comes as a built-in feature that can be activated using Server Manager.

Aims of this guide

We will install the WSB using Server Manager, configure basic (Full Server) backup job schedule and set up a scheduled task to send out email notifications every time backup succeeds or fails. For email notifications we will use Powershell script.

Step 1. Install Windows Server Backup

We will install the WSB using Server Manager's  Add Roles and Features wizard.

Install WSB

Step 2. Start Windows Server Backup

We start WSB from Server Manager's  Tools menu.

Start WSB

Step 3. Schedule first backup job

We run backup scheduling wizard from Actions pane. For backup type select Full server. Choose your required backup frequency and time. For Destination Type choose Backup to a volume and add the local volume dedicated for backups. When WSB prompts you to exclude the backup destination volume from the backup job click OK and complete the Backup Schedule Wizard.

Scheduling first backup job

Step 4. Prepare email notification Powershell scripts

Here is a sample script for Backup Success Email Task. You can change values in red to your own ones. Call it email-success.ps1 and copy it to C:\Windows\System32 folder.
#Send Backup Success Email
$secpasswd = ConvertTo-SecureString “PASSWORD” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“YOUR@EMAIL.COM”, $secpasswd)

Send-MailMessage -from "YOUR@EMAIL.COM" `
 -To "FIRST@EMAIL.COM","SECOND@EMAIL.COM" `
 -Subject "Success - Windows Server backup" `
 -SmtpServer "YOUR.SMTP.SERVER" `
 -Credential $mycreds `
 -UseSsl `
 -Port "587" `
 -Body "YOUR COMPANY Windows Server Backup is successful"
This is a sample script for Backup Failure Email Task. You can change values in red to your own ones. Call it email-failure.ps1 and copy it to C:\Windows\System32 folder.
#Send Backup Failure Email
$secpasswd = ConvertTo-SecureString “PASSWORD” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“YOUR@EMAIL.COM”, $secpasswd)

Send-MailMessage -from "YOUR@EMAIL.COM" `
-To "FIRST@EMAIL.COM","SECOND@EMAIL.COM" `
-Subject "Failure - Windows Server backup" `
-SmtpServer "YOUR.SMTP.SERVER" `
-Credential $mycreds `
-UseSsl `
-Port "587" `
-Body "YOUR COMPANY Windows Server backup failed"
 

Step 5. Launch Task Scheduler

Launch Task Scheduler from Server Manager's Tools menu

Launch Task Scheduler

Step 6. Create the first task for 'Backup Success' email alerts

On Create Task wizard's General tab give the task a name (eg Backup Success Email Task). Give it a meaningful description (eg Notifies of scheduled backup successful completion). Under Security options section select Run whether user is logged on or not.

Create Task

Step 7. Add a trigger for the task

For Begin the task select On an event. In Settings section leave Basic checked and under Log: choose Microsoft-Windows-Backup/Operational. For Event ID enter number 4. In Advanced settings section tick Stop task if it runs longer than: and choose 1 hour. Also make sure option Enabled is ticked.

Add a trigger for the task

Step 8. Add an action for the task

In Actions tab click on New... In Edit Action window for Action select Start a program. In Program/script box type in Powershell.exe and in Add arguments box type in -EP Bypass c:\Windows\System32\email-success.ps1. Click OK to confirm the action.

Add an action for the task

Step 9. Finalise the task

In Settings tab set Stop the task if it runs longer than: to 1 hour. Click OK and on credentials prompt enter the credentials required for running the task.

Finalise the task

Step 10. Create the task for 'Backup Failure' email alerts

For Backup Failure Email Task follow the steps 6 to 9, except with the following differences. In General tab give it a different name and description. On Triggers tab create individual triggers for Events 5, 8, 9, 17, 18,19, 20, 21, 22, 49, 50, 561. For Actions tab specify the email-falure.ps1 script instead.

Create Email failure task

Now just wait for the Backup job to run in your scheduled time or start a Backup Once job using scheduled job options to see immediate results.
UPDATE: If you prefer HTML/CSS email reports like below try the script by Andrea Gallazzi in the above scheduled tasks.

Better looking HTML report

Leave a comment

Your email address will not be published. Required fields are marked *