Search code examples
azurecloudvirtual-machinebackuppolicy

In Azure, is it possible to retrieve a Backup Policy from a VM tag value?


TL;DR

Is it possible to get the name of a backup policy I'll want to apply, from a Virtual Machine tag value ? For example : backup=myBackupPolicyDaily1AM or backup=myBackupPolicyWeekly

Context

In Azure, I have these resources :

What's working now

I've applied the Azure Policy with these parameters :

  • inclusionTagName: backup
  • inclusionTagValue: backupme
  • vaultLocation: West Europe (from dropdown list)
  • backupPolicyId: DefaultPolicy (From dropdown list, after selecting my recovery vault)

Things are working fine so far. After a Remediation, vmtest01 is backed up.

What I want now

Now I want to apply the Backup Policy name I'll have from the backup tag value. For example :

  • VMs having the tag backup=myBackupPolicyDaily1AM will have the myBackupPolicyDaily1AM Backup Policy
  • VMs having the tag backup=myBackupPolicyWeekly will have the myBackupPolicyWeekly Backup Policy

I've search on the interwebs and didn't see any example for that use case. Is it possible ?

Note: All the resources are in the same location.


Solution

  • Have you tried changing the BackupPolicy variable to [parameters('inclusionTagValue')] (~ line 473)? You will first need to duplicate the built-in policy and make it custom. I am testing this now but it will take a little time for Azure policy to evaluate and remediate.

            "variables": {
              "backupFabric": "Azure",
              "backupPolicy": "[parameters('inclusionTagValue')]",
              "v2VmType": "Microsoft.Compute/virtualMachines",
              "v2VmContainer": "iaasvmcontainer;iaasvmcontainerv2;",
              "v2Vm": "vm;iaasvmcontainerv2;",
              "vaultName": "[take(concat('RSVault-', parameters('location'), '-', guid(resourceGroup().id)),50)]"
                }