我正在尝试添加功能,以将VM添加到用于部署的现有Azure ARM JSON模板的恢复服务库中。
我已经使用了以下GitHub模板中的代码,并且如果恢复服务库与VM在同一资源组中,但在不同的资源组中却没有,则此方法有效。
https://github.com/Azure/azure-quickstart-templates/tree/master/101-recovery- services-backup-vms
代码如下:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "existingVirtualMachinesResourceGroup": { "type": "string", "metadata": { "description": "Resource group where the virtual machines are located. This can be different than resource group of the vault. " } }, "existingVirtualMachines": { "type": "array", "metadata": { "description": "Array of Azure virtual machines. e.g. [\"vm1\",\"vm2\",\"vm3\"]" } }, "existingRecoveryServicesVault": { "type": "string", "metadata": { "description": "Recovery services vault name where the VMs will be backed up to. " } }, "existingBackupPolicy": { "type": "string", "defaultValue": "DefaultPolicy", "metadata": { "description": "Backup policy to be used to backup VMs. Backup POlicy defines the schedule of the backup and how long to retain backup copies. By default every vault comes with a 'DefaultPolicy' which canbe used here." } } }, "variables": { "backupFabric": "Azure", "v2VmType": "Microsoft.Compute/virtualMachines", "v2VmContainer": "iaasvmcontainer;iaasvmcontainerv2;", "v2Vm": "vm;iaasvmcontainerv2;" }, "resources": [ { "name": "[concat(parameters('existingRecoveryServicesVault'), '/', variables('backupFabric'), '/', variables('v2VmContainer'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')[copyIndex()]), '/', variables('v2Vm'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')[copyIndex()]))]", "apiVersion": "2016-06-01", "location": "[resourceGroup().location]", "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems", "copy": { "name": "v2VmsCopy", "count": "[length(parameters('existingVirtualMachines'))]" }, "properties": { "protectedItemType": "[variables('v2VmType')]", "policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies',parameters('existingRecoveryServicesVault'),parameters('existingBackupPolicy') )]", "sourceResourceId": "[resourceId(subscription().subscriptionId,parameters('existingVirtualMachinesResourceGroup'),'Microsoft.Compute/virtualMachines',parameters('existingVirtualMachines')[copyIndex()])]" } } ]
}
没有变量或参数来定义恢复服务库资源组。
我还查看了以下GitHub模板,该模板还将VM添加到了恢复服务库中,但是同样,它似乎无法使用其他资源组。
https://github.com/Azure/azure-quickstart-templates/tree/master/201-recovery- services-backup-classic-resource-manager-vms
我已经尝试使用Google搜索,但是到目前为止,我还没有找到答案,这有可能吗?
谢谢
如果对其他人有用,我已经找到了答案。如前所述,恢复服务库将使用为模板定义的相同资源组。为了能够为RSV定义不同的模板,需要使用嵌套模板来完成。
我已经使用以下嵌套模板替换了原始帖子中的恢复服务资源,恢复服务库所需的资源组由“ resourceGroup”定义:“ [parameters(’nestedTemplateRecoveryServicesResourceGroup’)]”,
{ "apiVersion": "2017-05-10", "name": "nestedTemplateRecoveryServices", "type": "Microsoft.Resources/deployments", "resourceGroup": "[parameters('nestedTemplateRecoveryServicesResourceGroup')]", "dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"], "properties": { "mode": "Incremental", "template": { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": {}, "variables": {}, "resources": [ { "name": "[concat(parameters('existingRecoveryServicesVault'), '/', variables('backupFabric'), '/', variables('v2VmContainer'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')), '/', variables('v2Vm'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')))]", "apiVersion": "2016-06-01", "location": "[resourceGroup().location]", "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems", "properties": { "protectedItemType": "[variables('v2VmType')]", "policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies',parameters('existingRecoveryServicesVault'),parameters('existingBackupPolicy') )]", "sourceResourceId": "[resourceId(subscription().subscriptionId,parameters('existingVirtualMachinesResourceGroup'),'Microsoft.Compute/virtualMachines',parameters('existingVirtualMachines'))]" } } ] }, "parameters": {}, "outputs": {} } }