The Azure PowerShell AZ module is used to create and manage Azure resources from the command line or in scripts.
Azure Backup backs up on-premises machines and apps, and Azure VMs. This article shows you how to back up an Azure VM with the AZ module. Alternatively, you can back up a VM using the Azure CLI, or in the Azure portal.
This quickstart enables backup on an existing Azure VM. If you need to create a VM, you can create a VM with Azure PowerShell.
This quickstart requires the Azure PowerShell AZ module version 1.0.0 or later. Run Get-Module -ListAvailable Az
to find the version. If you need to install or upgrade, see Install Azure PowerShell module.
Sign in to your Azure subscription with the Connect-AzAccount
command and follow the on-screen directions.
Connect-AzAccount
The first time you use Azure Backup, you must register the Azure Recovery Service provider in your subscription with Register-AzResourceProvider, as follows:
Register-AzResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"
A Recovery Services vault is a logical container that stores backup data for protected resources, such as Azure VMs. When a backup job runs, it creates a recovery point inside the Recovery Services vault. You can then use one of these recovery points to restore data to a given point in time.
When you create the vault:
Now create a vault:
Use the New-AzRecoveryServicesVault to create the vault:
New-AzRecoveryServicesVault `
-ResourceGroupName "myResourceGroup" `
-Name "myRecoveryServicesVault" `
-Location "WestEurope"
Set the vault context with Set-AzRecoveryServicesVaultContext, as follows:
Get-AzRecoveryServicesVault `
-Name "myRecoveryServicesVault" | Set-AzRecoveryServicesVaultContext
Change the storage redundancy configuration (LRS/GRS) of the vault with Set-AzRecoveryServicesBackupProperty, as follows:
Get-AzRecoveryServicesVault `
-Name "myRecoveryServicesVault" | Set-AzRecoveryServicesBackupProperty -BackupStorageRedundancy LocallyRedundant/GeoRedundant
Note
Storage Redundancy can be modified only if there are no backup items protected to the vault.
You enable backup for an Azure VM, and specify a backup policy.
Enable backup as follows:
First, set the default policy with Get-AzRecoveryServicesBackupProtectionPolicy:
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name "DefaultPolicy"
Enable VM backup with Enable-AzRecoveryServicesBackupProtection. Specify the policy, the resource group, and the VM name.
Enable-AzRecoveryServicesBackupProtection `
-ResourceGroupName "myResourceGroup" `
-Name "myVM" `
-Policy $policy
Backups run according to the schedule specified in the backup policy. You can also run an on-demand backup:
To run an on-demand backup, you use the Backup-AzRecoveryServicesBackupItem.
Run an on-demand backup job as follows:
Specify the container, obtain VM information, and run the backup.
$backupcontainer = Get-AzRecoveryServicesBackupContainer `
-ContainerType "AzureVM" `
-FriendlyName "myVM"
$item = Get-AzRecoveryServicesBackupItem `
-Container $backupcontainer `
-WorkloadType "AzureVM"
Backup-AzRecoveryServicesBackupItem -Item $item
You might need to wait up to 20 minutes, since the first backup job creates a full recovery point. Monitor the job as described in the next procedure.
Run Get-AzRecoveryservicesBackupJob to monitor the job status.
Get-AzRecoveryservicesBackupJob
Output is similar to the following example, which shows the job as InProgress:
WorkloadName Operation Status StartTime EndTime JobID
------------ --------- ------ --------- ------- -----
myvm Backup InProgress 9/18/2017 9:38:02 PM 9f9e8f14
myvm ConfigureBackup Completed 9/18/2017 9:33:18 PM 9/18/2017 9:33:51 PM fe79c739
When the job status is Completed, the VM is protected and has a full recovery point stored.
If you want to perform more actions such as change policy, edit policy etc.. refer to the manage VM backups section.
Clean up the deploymentIf you no longer need to back up the VM, you can clean it up.
Disable protection, remove the restore points and vault. Then delete the resource group and associated VM resources, as follows:
Disable-AzRecoveryServicesBackupProtection -Item $item -RemoveRecoveryPoints
$vault = Get-AzRecoveryServicesVault -Name "myRecoveryServicesVault"
Remove-AzRecoveryServicesVault -Vault $vault
Remove-AzResourceGroup -Name "myResourceGroup"
Next steps
In this quickstart, you created a Recovery Services vault, enabled protection on a VM, and created the initial recovery point.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4