Wednesday, July 4, 2018

Configure Azure Backup - using PowerShell

If you are configuring this for the first time then you need to register your Recovery Service provider with your subscription. For that you can run the below command.

Register-AzureRmResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"


You can verify that the Providers registered successfully, using the following commands

Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"


Create a recovery services vault

The Recovery Services vault is a Resource Manager resource, so you need to place it within a resource group. You can use an existing resource group, or create a resource group with the New-AzureRmResourceGroup cmdlet. When creating a resource group, specify the name and location for the resource group.


By default, the vault is set for Geo-Redundant storage. To further protect your data, this storage redundancy level ensures that your backup data is replicated to a secondary Azure region which is far away from the primary region.

To use this vault with the remaining steps, set the vault context with


Rather than creating the services one by one, you can copy paste the below mentioned Script into the PowerShell and run to create the Backup job. The details are mentioned below.

1. NameResourceGroup - Give the resource group name. you can give an existing resource group name or else create a ResourceGroup first.

2. Location - Give the correct Location name where you going to host your services. E.g. Australia East, UK South

3. VmName - Server Names .This is case Sensitive and make sure to give the VM name which you want to enable the protection.

4. NameRecoveryServicesVault – Give name for the Recovery service Vault

5. NamePolocy - Give a name for the Backup Policy

6. FriendlyName - Friendly name for the backup Container

Rest of the variables you can keep as it is and if there is any requirement to change the backup schedule you can edit that by go into the Backup policy.

You can copy paste the below scrip into the PowerShell and run to create the backup job.

PowerShell Script


#Variables for common values

$NameResourceGroup = "AAA-Production"

$NameRecoveryServicesVault = "A123RecoveryServicesVault"

$location = "WestUS2"

$NamePolocy = "DefaultPolicy"

$vmName = "AAA-Prod-SVR1"

$FriendlyName = "AAAProdSVR1"

#Create a recovery services vaults

New-AzureRmRecoveryServicesVault `

-ResourceGroupName $NameResourceGroup `

-Name $NameResourceGroup `

-Location $location

#Create a recovery services vaults

Get-AzureRmRecoveryServicesVault `

-Name $NameRecoveryServicesVault | Set-AzureRmRecoveryServicesVaultContext

# Enable backup for an Azure VM

$policy = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name $NamePolocy

Enable-AzureRmRecoveryServicesBackupProtection `

-ResourceGroupName $NameResourceGroup `

-Name $vmName `

-Policy $policy

# Start a backup job

$backupcontainer = Get-AzureRmRecoveryServicesBackupContainer `

-ContainerType "AzureVM" `

-FriendlyName $FriendlyName

$item = Get-AzureRmRecoveryServicesBackupItem -Container $backupcontainer

-WorkloadType "AzureVM"

Backup-AzureRmRecoveryServicesBackupItem -Item $item


Once this is completed, you can run Get-AzureRmRecoveryservicesBackupJob Command to check the status of the backup job.


Ps1 file can be download from here

No comments: