Gallery › Backup › Azure built-in policies
[Preview]: Configure backup for Azure Files Shares with a given tag to an existing recovery services vault in the same location
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 2.0.0-preview Preview
Enforce backup for all Azure Files by backing them up to an existing central Recovery Services vault in the same region as the storage account. The vault can be in the same or a different subscription. This is useful when a central team manages backups across subscriptions. You can optionally include Azure Files in storage accounts with a specified tag to control the scope of the policy assignment.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"properties": {
"displayName": "[Preview]: Configure backup for Azure Files Shares with a given tag to an existing recovery services vault in the same location",
"policyType": "BuiltIn",
"mode": "All",
"description": "Enforce backup for all Azure Files by backing them up to an existing central Recovery Services vault in the same region as the storage account. The vault can be in the same or a different subscription. This is useful when a central team manages backups across subscriptions. You can optionally include Azure Files in storage accounts with a specified tag to control the scope of the policy assignment.",
"metadata": {
"version": "2.0.0-preview",
"preview": true,
"category": "Backup"
},
"version": "2.0.0-preview",
"parameters": {
"registerStorageAccount": {
"type": "Boolean",
"metadata": {
"displayName": "Register Storage Account",
"description": "Set to true if the existing Storage Account has to be registered to the Recovery Services Vault; set to false otherwise."
},
"defaultValue": false
},
"vaultLocation": {
"type": "String",
"metadata": {
"displayName": "Location (Specify the location of the FileShares that you want to protect)",
"description": "Location of the FileShares. The FileShares should be in the same location as the vault."
}
},
"backupPolicyId": {
"type": "String",
"metadata": {
"displayName": "Backup Policy Id (of type Azure FileShare from a vault in the location chosen above)",
"description": "Specify the Id of the Azure Backup policy to configure backup of the file shares. The selected Azure Backup policy should be of type Azure File Share. This policy needs to be in a Recovery Services Vault that is present in the location chosen above. For example - /subscriptions/<SubscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.RecoveryServices/vaults/<VaultName>/backupPolicies/<BackupPolicyName>"
}
},
"inclusionTagName": {
"type": "String",
"metadata": {
"displayName": "Inclusion Tag Name",
"description": "Name of the tag to use for including FileShares in the scope of this policy. This should be used along with the Inclusion Tag Value parameter."
},
"defaultValue": ""
},
"inclusionTagValues": {
"type": "Array",
"metadata": {
"displayName": "Inclusion Tag Values",
"description": "Value of the tag to use for including FileShares in the scope of this policy (in case of multiple values, use a comma-separated list). This should be used along with the Inclusion Tag Name parameter."
},
"defaultValue": []
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"AuditIfNotExists",
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts/fileServices/shares"
},
{
"field": "location",
"equals": "[parameters('vaultLocation')]"
},
{
"anyOf": [
{
"field": "[concat('tags[', parameters('inclusionTagName'), ']')]",
"in": "[parameters('inclusionTagValues')]"
},
{
"value": "[empty(parameters('inclusionTagValues'))]",
"equals": "true"
},
{
"value": "[empty(parameters('inclusionTagName'))]",
"equals": "true"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.RecoveryServices/backupprotecteditems",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab",
"/providers/Microsoft.Authorization/roleDefinitions/5e467623-bb1f-42f4-a55d-6e525e11384b"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registerStorageAccount": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Set to true if the existing Storage Account needs to be registered to the Recovery Services Vault; set to false otherwise."
}
},
"existingStorageAccountArmId": {
"type": "string",
"metadata": {
"description": "Existing Storage Account ARM Id."
}
},
"existingResourceGroupName": {
"type": "string",
"metadata": {
"description": "Existing Resource Group Name."
}
},
"existingFileShareName": {
"type": "string",
"metadata": {
"description": "Existing File Share Name."
}
},
"backupPolicyId": {
"type": "string",
"metadata": {
"description": "Backup Policy Id."
}
},
"existingStorageAccountName": {
"type": "string",
"metadata": {
"description": "ResourceId of the Storage Account."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"existingStorageAccountArmId": "[parameters('existingStorageAccountArmId')]",
"existingStorageAccountName": "[parameters('existingStorageAccountName')]",
"existingResourceGroupName": "[parameters('existingResourceGroupName')]",
"existingFileShareName": "[parameters('existingFileShareName')]",
"backupPolicyName": "[first(skip(split(parameters('backupPolicyId'), '/'), 10))]",
"vaultName": "[first(skip(split(parameters('backupPolicyId'), '/'), 8))]",
"vaultResourceGroup": "[first(skip(split(parameters('backupPolicyId'), '/'), 4))]",
"vaultSubscriptionId": "[first(skip(split(parameters('backupPolicyId'), '/'), 2))]",
"backupFabric": "Azure",
"backupManagementType": "AzureStorage"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"resourceGroup": "[variables('vaultResourceGroup')]",
"subscriptionId": "[variables('vaultSubscriptionId')]",
"name": "[concat('DeployProtection-', uniqueString(concat(variables('existingStorageAccountName'), variables('existingFileShareName'))))]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"resources": [
{
"condition": "[parameters('registerStorageAccount')]",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers",
"apiVersion": "2021-12-01",
"name": "[format('{0}/{1}/storagecontainer;Storage;{2};{3}', variables('vaultName'), variables('backupFabric'), parameters('existingResourceGroupName'), parameters('existingStorageAccountName'))]",
"properties": {
"backupManagementType": "[variables('backupManagementType')]",
"containerType": "StorageContainer",
"sourceResourceId": "[parameters('existingStorageAccountArmId')]"
}
},
{
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
"apiVersion": "2021-12-01",
"name": "[format('{0}/{1}/{2}/{3}', split(format('{0}/{1}/storagecontainer;Storage;{2};{3}', variables('vaultName'), variables('backupFabric'), parameters('existingResourceGroupName'), parameters('existingStorageAccountName')), '/')[0], split(format('{0}/{1}/storagecontainer;Storage;{2};{3}', variables('vaultName'), variables('backupFabric'), parameters('existingResourceGroupName'), parameters('existingStorageAccountName')), '/')[1], split(format('{0}/{1}/storagecontainer;Storage;{2};{3}', variables('vaultName'), variables('backupFabric'), parameters('existingResourceGroupName'), parameters('existingStorageAccountName')), '/')[2], format('AzureFileShare;{0}', parameters('existingFileShareName')))]",
"properties": {
"protectedItemType": "AzureFileShareProtectedItem",
"sourceResourceId": "[parameters('existingStorageAccountArmId')]",
"policyId": "[parameters('backupPolicyId')]",
"isInlineInquiry": true
},
"dependsOn": [
"[resourceId(variables('vaultSubscriptionId'), variables('vaultResourceGroup'),'Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers', variables('vaultName'), variables('backupFabric'), format('storagecontainer;Storage;{0};{1}', parameters('existingResourceGroupName'), parameters('existingStorageAccountName')))]"
]
}
]
}
}
}
]
},
"parameters": {
"existingStorageAccountArmId": {
"value": "[concat('/subscriptions/', split(field('id'), '/')[2],'/resourceGroups/', split(field('id'), '/')[4],'/providers/Microsoft.Storage/storageAccounts/', split(field('id'), '/')[8])]"
},
"existingStorageAccountName": {
"value": "[first(skip(split(field('id'), '/'), 8))]"
},
"existingFileShareName": {
"value": "[field('name')]"
},
"existingResourceGroupName": {
"value": "[resourceGroup().name]"
},
"registerStorageAccount": {
"value": "[parameters('registerStorageAccount')]"
},
"backupPolicyId": {
"value": "[parameters('backupPolicyId')]"
},
"location": {
"value": "[field('location')]"
}
}
}
}
}
}
},
"versions": [
"2.0.0-PREVIEW",
"1.0.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/d8659d5a-a3bd-444d-98ea-570bceb568cf",
"name": "d8659d5a-a3bd-444d-98ea-570bceb568cf"
}# Converted from FileShare_EnableAzureBackupWithTag_DINE.json by ConvertTo-Bylaw.
Policy 'd8659d5a-a3bd-444d-98ea-570bceb568cf' {
Properties @{
DisplayName = '[Preview]: Configure backup for Azure Files Shares with a given tag to an existing recovery services vault in the same location'
Description = 'Enforce backup for all Azure Files by backing them up to an existing central Recovery Services vault in the same region as the storage account. The vault can be in the same or a different subscription. This is useful when a central team manages backups across subscriptions. You can optionally include Azure Files in storage accounts with a specified tag to control the scope of the policy assignment.'
Version = '2.0.0-preview'
Preview = $true
Category = 'Backup'
PolicyVersion = '2.0.0-preview'
Mode = 'All'
}
Parameter RegisterStorageAccount @{
Type = 'Boolean'
Default = $false
DisplayName = 'Register Storage Account'
Description = 'Set to true if the existing Storage Account has to be registered to the Recovery Services Vault; set to false otherwise.'
}
Parameter VaultLocation @{
Type = 'String'
DisplayName = 'Location (Specify the location of the FileShares that you want to protect)'
Description = 'Location of the FileShares. The FileShares should be in the same location as the vault.'
}
Parameter BackupPolicyId @{
Type = 'String'
DisplayName = 'Backup Policy Id (of type Azure FileShare from a vault in the location chosen above)'
Description = 'Specify the Id of the Azure Backup policy to configure backup of the file shares. The selected Azure Backup policy should be of type Azure File Share. This policy needs to be in a Recovery Services Vault that is present in the location chosen above. For example - /subscriptions/<SubscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.RecoveryServices/vaults/<VaultName>/backupPolicies/<BackupPolicyName>'
}
Parameter InclusionTagName @{
Default = ''
DisplayName = 'Inclusion Tag Name'
Description = 'Name of the tag to use for including FileShares in the scope of this policy. This should be used along with the Inclusion Tag Value parameter.'
}
Parameter InclusionTagValues @{
Type = 'Array'
Default = @()
DisplayName = 'Inclusion Tag Values'
Description = 'Value of the tag to use for including FileShares in the scope of this policy (in case of multiple values, use a comma-separated list). This should be used along with the Inclusion Tag Name parameter.'
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.Storage/storageAccounts/fileServices/shares' {
When {
Field location | Must -Be (Param VaultLocation)
}
Require 'tag (Param InclusionTagName) is not one of the InclusionTagValues parameter' {
Tag (Param InclusionTagName) | Must -Not -BeIn (Param InclusionTagValues) -IfPresent
}
Require 'Requirement 2' {
Arm '[empty(parameters(''inclusionTagValues''))]' | Must -Not -Be 'true'
}
Require 'Requirement 3' {
Arm '[empty(parameters(''inclusionTagName''))]' | Must -Not -Be 'true'
}
}
DeployIfNotExists 'Microsoft.RecoveryServices/backupprotecteditems' -Role 'Storage Account Contributor', 'Backup Contributor' -Effect (Param Effect) {
Deployment -TemplateFile './templates/d8659d5a-a3bd-444d-98ea-570bceb568cf.json' -Parameters ([ordered]@{
existingStorageAccountArmId = (Arm '[concat(''/subscriptions/'', split(field(''id''), ''/'')[2],''/resourceGroups/'', split(field(''id''), ''/'')[4],''/providers/Microsoft.Storage/storageAccounts/'', split(field(''id''), ''/'')[8])]')
existingStorageAccountName = (Arm '[first(skip(split(field(''id''), ''/''), 8))]')
existingFileShareName = (Arm '[field(''name'')]')
existingResourceGroupName = (Arm '[resourceGroup().name]')
registerStorageAccount = (Param RegisterStorageAccount)
backupPolicyId = (Param BackupPolicyId)
location = (Arm '[field(''location'')]')
})
}
}Its deployment templates are written beside it:
templates/d8659d5a-a3bd-444d-98ea-570bceb568cf.json
Source: built-in-policies/policyDefinitions/Backup/FileShare_EnableAzureBackupWithTag_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw