How to automate On-Demand Azure Backup for Azure Virtual Machines using PowerShell
This guest post is authored by Swathi Dhanwada, Customer Engineer 2, who is frequently seen answering Azure Backup community queries.
Azure Backup supports multiple backups of Azure Virtual Machines per day using Enhanced Policy. For hourly backup, the minimum RPO is 4 hours and the maximum is 24 hours. You can set the backup schedule to 4, 6, 8, 12, and 24 hours respectively. Learn how to back up an Azure VM using Enhanced policy. This feature is only available to unprotected VMs that are new to Azure Backup. VMs that are already protected with existing policy can't be moved to Enhanced policy. To overcome this, you can run an multiple on-demand backup of a VM per day after you set up its protection. Keep these details in mind:
- If the initial backup is pending, on-demand backup creates a full copy of the VM in the Recovery Services vault.
- If the initial backup is complete, an on-demand backup will only send changes from the previous snapshot to the Recovery Services vault. That is, later backups are always incremental.
- You can’t trigger on-demand backups by disabling scheduled backup.
Below are the steps to automate the on-demand backup for azure virtual machines using Azure Automation.
Step1
Create an Automation resource with system managed identity. To assign permissions to managed identities, complete the following steps:
-
Sign in to Azure interactively using the Connect-AzAccount cmdlet and follow the instructions:
- Provide an appropriate value for the following variables and then run the script:
- Use the PowerShell
cmdletNew-AzRoleAssignment to assign a role to the system-assigned managed identity:
Step2
Verify if required modules are imported to the Automation resource. If not, import the following modules from the Modules gallery in the order given below:
Step3
Create PowerShell Runbooks in the Automation Resource. You can create multiple Runbooks based on which set of virtual machines you want to protect.
Step4
Edit the Runbook and write script to choose which virtual machines to take a backup. You can create scripts that suit your requirements.
Script to trigger on demand backup for single vm
- Save the script.
- Test the script using “Test Pane”.
- Publish the Runbook.
Step5
- Schedule the Runbook. While scheduling the Runbook, you can pass on the parameters required for the PowerShell Script.
- The sample script takes the retention as an input. So, if you need to schedule a weekly snapshot and retain for 8 weeks, create a weekly schedule as mentioned below and specify the retention as 56 days (8 weeks). You can create monthly and yearly schedules (run every 12 months) in a similar manner. You can monitor the success/failure of these backups using the “Jobs” tab of Runbooks.
Reference Documents:
Published on:
Learn moreRelated posts
Update on classic storage account retirement and upcoming changes for classic storage customers
We previously announced that support would end for retired Azure classic storage accounts on 31 August 2024. Now that we are past the retireme...
Azure Elastic SAN for Azure VMware Solution: now Generally Available
Have you been looking to expand your storage on Azure VMware Solution (AVS), but do not need the extra compute performance and the associated ...
Accelerate metadata heavy workloads with Metadata Caching preview for Azure Premium Files SMB & REST
Azure Files previously announced the limited preview of Metadata caching highlighting improvements on the metadata latency (up to 55...
Announcing UNLIMITED Public Preview of Metadata Caching for Azure Premium SMB/REST File Shares
Azure Files is excited to announce the Unlimited public preview of Metadata Caching for the premium SMB/REST file share tier. Unlimited ...
Azure Backup-SAP HANA DB Backup Delivers More Value at Lower TCO with Reduced Protected Instance Fee
Azure Backup for SAP HANA Database Delivers More Value at Lower TCO with Reduced Protected Instance Fees starting 1st Sept’2024 At Azur...
Switch to Azure Business Continuity Center for your at scale BCDR management needs
In response to the evolving customer requirements and environments since COVID-19, including the shift towards hybrid work models and the incr...
The Azure Storage product group is heading to the SNIA Developer Conference 2024
The Azure Storage product group is heading to the SNIA Developer Conference (SDC) 2024 in Santa Clara, California, USA from September 16th thr...
Latest advancements in Premium SSD v2 and Ultra Azure Managed Disks
We are excited to share the latest advancements in Premium SSD v2 (Pv2) and Ultra disks, the next generation of Azure disk stor...
Unlocking the Potential of Unstructured Data with Microsoft Copilot and Azure Native Qumulo
It has been a true pleasure to see our friends at Qumulo constantly innovating and delivering a service that adds more value with every releas...
Public Preview: Customer Managed Planned Failover for Azure Storage
We are excited to announce customer managed Planned Failover for Azure Storage is now available in public preview. Over the past few ye...