Azure Backup is a cloud-based service that helps you protect your data and applications by backing them up to Azure. You can use Azure Backup to protect data and applications running in Azure and on-premises. Azure Backup also provides offsite protection for on-premises data and applications.
To use Azure Backup, you need to have an Azure subscription. If you don’t have one, you can sign up for a free trial.
Once you have an Azure subscription, you can follow these steps to create a backup using Azure Backup and CLI commands.
Step 1: Create a Recovery Services vault
- To create a Recovery Services vault, use the following Azure CLI command:
az backup vault create --resource-group <resource-group-name> --name <recovery-services-vault-name> --location <location>
- Replace
<resource-group-name>
with the name of the resource group where you want to create the Recovery Services vault. - Replace
<recovery-services-vault-name>
with the name you want to give to your Recovery Services vault. - Replace
<location>
with the location where you want to create the Recovery Services vault.
Step 2: Create a Backup Policy
- To create a backup policy, use the following Azure CLI command:
az backup policy create --resource-group <resource-group-name> --vault-name <recovery-services-vault-name> --policy <policy-name> --backup-management-type AzureIaasVM --workload-type VM
- Replace
<resource-group-name>
with the name of the resource group where you created the Recovery Services vault. - Replace
<recovery-services-vault-name>
with the name of the Recovery Services vault you created in Step 1. - Replace
<policy-name>
with the name you want to give to your backup policy.
Step 3: Enable backup for a virtual machine
- To enable backup for a virtual machine, use the following Azure CLI command:
az backup protection enable-for-vm --resource-group <resource-group-name> --vault-name <recovery-services-vault-name> --vm <vm-name> --policy-name <policy-name>
- Replace
<resource-group-name>
with the name of the resource group where your virtual machine is located. - Replace
<recovery-services-vault-name>
with the name of the Recovery Services vault you created in Step 1. - Replace
<vm-name>
with the name of the virtual machine you want to back up. - Replace
<policy-name>
with the name of the backup policy you created in Step 2.
Step 4: Trigger a backup
- To trigger a backup, use the following Azure CLI command:
az backup protection backup-now --resource-group <resource-group-name> --vault-name <recovery-services-vault-name> --item-name <vm-name> --container-name <vm-name>
- Replace
<resource-group-name>
with the name of the resource group where your virtual machine is located. - Replace
<recovery-services-vault-name>
with the name of the Recovery Services vault you created in Step 1. - Replace
<vm-name>
with the name of the virtual machine you want to back up.
Step 5: Restore data
- To restore data, use the following Azure CLI command:
az backup restore restore-disks --resource-group <resource-group-name> --vault-name <recovery-services-vault-name> --container-name <vm-name> --item-name <vm-name> --storage-account <storage-account-name> --rp-name <restore-point-name> --target-resource-group <target-resource-group-name> --target-name <restored-vm-name> --overwrite
- Replace `<resource-group-name>` with the name of the resource group where your virtual machine is located.
- Replace
<recovery-services-vault-name>
with the name of the Recovery Services vault you created in Step 1. - Replace
<vm-name>
with the name of the virtual machine you want to restore data for. - Replace
<storage-account-name>
with the name of the storage account you want to use for the restore operation. - Replace
<restore-point-name>
with the name of the restore point you want to use for the restore operation. - Replace
<target-resource-group-name>
with the name of the resource group where you want to restore the virtual machine to. - Replace
<restored-vm-name>
with the name you want to give to the restored virtual machine.
Note: The <restore-point-name>
parameter can be obtained by running the following command: az backup recoverypoint list --resource-group <resource-group-name> --vault-name <recovery-services-vault-name> --container-name <vm-name> --item-name <vm-name> --backup-management-type AzureIaasVM --query '[].name' -o tsv
This will list all the restore points available for the virtual machine, and you can choose the one you want to use for the restore operation.
That’s it! You have now created a backup using Azure Backup and CLI commands, and you know how to restore data if needed. Azure Backup provides a reliable and cost-effective way to protect your data and applications, and using CLI commands can make it even easier to manage your backups.