Created
          July 27, 2020 22:12 
        
      - 
      
- 
        Save matt-FFFFFF/c8f5ca4309834ae471e348d05252a1d1 to your computer and use it in GitHub Desktop. 
    Azure Backup Policy Sample
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "mode": "All", | |
| "policyRule": { | |
| "if": { | |
| "allOf": [ | |
| { | |
| "equals": "Microsoft.Compute/virtualMachines", | |
| "field": "type" | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftWindowsServer", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "WindowsServer", | |
| "field": "Microsoft.Compute/imageOffer" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "in": [ | |
| "2008-R2-SP1", | |
| "2008-R2-SP1-smalldisk", | |
| "2012-Datacenter", | |
| "2012-Datacenter-smalldisk", | |
| "2012-R2-Datacenter", | |
| "2012-R2-Datacenter-smalldisk", | |
| "2016-Datacenter", | |
| "2016-Datacenter-Server-Core", | |
| "2016-Datacenter-Server-Core-smalldisk", | |
| "2016-Datacenter-smalldisk", | |
| "2016-Datacenter-with-Containers", | |
| "2016-Datacenter-with-RDSH", | |
| "2019-Datacenter", | |
| "2019-Datacenter-Core", | |
| "2019-Datacenter-Core-smalldisk", | |
| "2019-Datacenter-Core-with-Containers", | |
| "2019-Datacenter-Core-with-Containers-smalldisk", | |
| "2019-Datacenter-smalldisk", | |
| "2019-Datacenter-with-Containers", | |
| "2019-Datacenter-with-Containers-smalldisk", | |
| "2019-Datacenter-zhcn" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftWindowsServer", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "WindowsServerSemiAnnual", | |
| "field": "Microsoft.Compute/imageOffer" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "in": [ | |
| "Datacenter-Core-1709-smalldisk", | |
| "Datacenter-Core-1709-with-Containers-smalldisk", | |
| "Datacenter-Core-1803-with-Containers-smalldisk" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftWindowsServerHPCPack", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "WindowsServerHPCPack", | |
| "field": "Microsoft.Compute/imageOffer" | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftSQLServer", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "like": "*-WS2016" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "like": "*-WS2016-BYOL" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "like": "*-WS2012R2" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "like": "*-WS2012R2-BYOL" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftRServer", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "MLServer-WS2016", | |
| "field": "Microsoft.Compute/imageOffer" | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftVisualStudio", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "in": [ | |
| "VisualStudio", | |
| "Windows" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftDynamicsAX", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "Dynamics", | |
| "field": "Microsoft.Compute/imageOffer" | |
| }, | |
| { | |
| "equals": "Pre-Req-AX7-Onebox-U8", | |
| "field": "Microsoft.Compute/imageSKU" | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "microsoft-ads", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "windows-data-science-vm", | |
| "field": "Microsoft.Compute/imageOffer" | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "MicrosoftWindowsDesktop", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "Windows-10", | |
| "field": "Microsoft.Compute/imageOffer" | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "RedHat", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "in": [ | |
| "RHEL", | |
| "RHEL-SAP-HANA" | |
| ] | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "6.*" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "7*" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "SUSE", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "in": [ | |
| "SLES", | |
| "SLES-HPC", | |
| "SLES-HPC-Priority", | |
| "SLES-SAP", | |
| "SLES-SAP-BYOS", | |
| "SLES-Priority", | |
| "SLES-BYOS", | |
| "SLES-SAPCAL", | |
| "SLES-Standard" | |
| ] | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "12*" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "Canonical", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "UbuntuServer", | |
| "field": "Microsoft.Compute/imageOffer" | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "14.04*LTS" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "16.04*LTS" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "18.04*LTS" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "Oracle", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "Oracle-Linux", | |
| "field": "Microsoft.Compute/imageOffer" | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "6.*" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "7.*" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "OpenLogic", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageOffer", | |
| "in": [ | |
| "CentOS", | |
| "Centos-LVM", | |
| "CentOS-SRIOV" | |
| ] | |
| }, | |
| { | |
| "anyOf": [ | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "6.*" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "7*" | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "allOf": [ | |
| { | |
| "equals": "cloudera", | |
| "field": "Microsoft.Compute/imagePublisher" | |
| }, | |
| { | |
| "equals": "cloudera-centos-os", | |
| "field": "Microsoft.Compute/imageOffer" | |
| }, | |
| { | |
| "field": "Microsoft.Compute/imageSKU", | |
| "like": "7*" | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| ] | |
| }, | |
| "then": { | |
| "details": { | |
| "deployment": { | |
| "properties": { | |
| "mode": "incremental", | |
| "parameters": { | |
| "location": { | |
| "value": "[field('location')]" | |
| }, | |
| "vmName": { | |
| "value": "[field('name')]" | |
| }, | |
| "vmRgName": { | |
| "value": "[resourceGroup().name]" | |
| } | |
| }, | |
| "template": { | |
| "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", | |
| "contentVersion": "1.0.0.0", | |
| "outputs": { | |
| "status": { | |
| "type": "string", | |
| "value": "[concat('Backup enabled successfully for VM:', ' ', parameters('vmName'))]" | |
| } | |
| }, | |
| "parameters": { | |
| "location": { | |
| "metadata": { | |
| "description": "Location for VM and Backup vault" | |
| }, | |
| "type": "string" | |
| }, | |
| "vmName": { | |
| "metadata": { | |
| "description": "Name of Azure Virtual Machines" | |
| }, | |
| "type": "string" | |
| }, | |
| "vmRgName": { | |
| "metadata": { | |
| "description": "Resource group containing the virtual machines." | |
| }, | |
| "type": "string" | |
| } | |
| }, | |
| "resources": [ | |
| { | |
| "type": "Microsoft.Resources/resourceGroups", | |
| "apiVersion": "2020-06-01", | |
| "name": "[variables('vaultRgName')]", | |
| "location": "[parameters('location')]", | |
| "properties": {} | |
| }, | |
| { | |
| "type": "Microsoft.Resources/deployments", | |
| "apiVersion": "2020-06-01", | |
| "name": "[concat('es-bkp-',subscription().displayName,'-RG-',parameters('vmRgName'),'-vm-',parameters('vmName'))]", | |
| "dependsOn": [ | |
| "[resourceId('Microsoft.Resources/resourceGroups',variables('vaultRgName'))]" | |
| ], | |
| "resourceGroup": "[variables('vaultRgName')]", | |
| "properties": { | |
| "mode": "Incremental", | |
| "template": { | |
| "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
| "contentVersion": "1.0.0.0", | |
| "parameters": {}, | |
| "variables": {}, | |
| "resources": [ | |
| { | |
| "name": "[variables('vaultName')]", | |
| "type": "Microsoft.RecoveryServices/vaults", | |
| "apiVersion": "2020-02-02", | |
| "location": "[parameters('location')]", | |
| "properties": {}, | |
| "sku": { | |
| "name": "Standard" | |
| } | |
| }, | |
| { | |
| "name": "[concat(variables('vaultName'), '/', variables('backupFabric'), '/', variables('v2VmContainer'), concat(parameters('vmRgName'),';',parameters('vmName')), '/', variables('v2Vm'), concat(parameters('vmRgName'),';',parameters('vmName')))]", | |
| "apiVersion": "2020-02-02", | |
| "location": "[parameters('location')]", | |
| "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems", | |
| "properties": { | |
| "protectedItemType": "[variables('v2VmType')]", | |
| "policyId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('vaultRgName'),'/providers/Microsoft.RecoveryServices/vaults/', variables('vaultName'),'/backupPolicies/',variables('backupPolicy'))]", | |
| "sourceResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('vmRgName'), '/providers/Microsoft.Compute/virtualMachines/', parameters('vmName'))]" | |
| }, | |
| "dependsOn": [ | |
| "[variables('vaultName')]" | |
| ] | |
| } | |
| ], | |
| "outputs": {} | |
| } | |
| } | |
| } | |
| ], | |
| "variables": { | |
| "backupFabric": "Azure", | |
| "backupPolicy": "DefaultPolicy", | |
| "v2Vm": "vm;iaasvmcontainerv2;", | |
| "v2VmContainer": "iaasvmcontainer;iaasvmcontainerv2;", | |
| "v2VmType": "Microsoft.Compute/virtualMachines", | |
| "vaultName": "[concat('rsv-',split(subscription().displayName, '-')[1], '-', split(subscription().displayName, '-')[2], '-', parameters('location'))]", | |
| "vaultRgName": "[concat('rg-',split(subscription().displayName, '-')[1], '-', split(subscription().displayName, '-')[2], '-baseinfra-', parameters('location'))]" | |
| } | |
| } | |
| }, | |
| "location": "northeurope" | |
| }, | |
| "existenceCondition": { | |
| "field": "name", | |
| "like": "*" | |
| }, | |
| "resourceGroupName": "[resourceGroup().name]", | |
| "roleDefinitionIds": [ | |
| "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c" | |
| ], | |
| "type": "Microsoft.RecoveryServices/backupprotecteditems", | |
| "deploymentScope": "subscription", | |
| "existenceScope": "resourceGroup" | |
| }, | |
| "effect": "deployIfNotExists" | |
| } | |
| }, | |
| "parameters": {} | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment