我尝试使用 ARM 模板部署配置 Azure 文件共享备份。下面是我正在尝试部署的模板。首先,我创建备份策略,然后尝试配置文件共享的备份。
问题是,我必须向模板传递以下格式的受保护项目。(azurefileshare;someUniqueID)(我必须传递唯一的受保护项目 ID,而不是文件共享名称)。但只有在配置备份后才能检索此 ID。
如果这里有人对此有任何想法的话请告诉我。
> "protectedItems": {
> "value": [
> "azurefileshare;xxxx1f5e4535076cxxxxxxxxxxxb9ff558024ff8xxxxxxcefce6"
> ]
>
模板.json
> {
> "$schema":"http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
> "contentVersion": "1.0.0.0",
> "parameters": {
> "vaultName": {
> "type": "String"
> },
> "vaultRG": {
> "type": "String"
> },
> "vaultSubID": {
> "type": "String"
> },
> "policyName": {
> "type": "String"
> },
> "schedule": {
> "type": "Object"
> },
> "retention": {
> "type": "Object"
> },
> "timeZone": {
> "type": "String"
> },
> "fabricName": {
> "type": "String"
> },
> "protectionContainers": {
> "type": "Array"
> },
> "protectedItems": {
> "type": "Array"
> },
> "sourceResourceIds": {
> "type": "Array"
> } }, "resources": [
> {
> "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
> "apiVersion": "2016-06-01",
> "name": "[concat(parameters('vaultName'), '/', parameters('policyName'))]",
> "properties": {
> "backupManagementType": "AzureStorage",
> "WorkloadType": "AzureFileShare",
> "schedulePolicy": "[parameters('schedule')]",
> "retentionPolicy": "[parameters('retention')]",
> "TimeZone": "[parameters('timeZone')]"
> }
> },
> {
> "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
> "apiVersion": "2016-06-01",
> "name": "[concat(parameters('vaultName'), '/', parameters('fabricName'),
> '/',parameters('protectionContainers')[copyIndex()], '/',
> parameters('protectedItems')[copyIndex()])]",
> "dependsOn": [
> "[concat('Microsoft.RecoveryServices/vaults', '/', parameters('vaultName'), '/backupPolicies/',
> parameters('policyName'))]"
> ],
> "properties": {
> "backupManagementType": "AzureStorage",
> "workloadType": "AzureFileShare",
> "friendlyName": "afs",
> "protectedItemType": "AzureFileShareProtectedItem",
> "policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies',
> parameters('vaultName'), parameters('policyName'))]",
> "sourceResourceId": "[parameters('sourceResourceIds')[copyIndex()]]"
> },
> "copy": {
> "name": "protectedItemsCopy",
> "count": "[length(parameters('protectedItems'))]"
> }
> } ] }
答案1
这里的行为相同。似乎属性格式姓名在这种情况下是强制性的并且没有记录。
我已成功对长字符串“661bd40fac4e36949e3e814039158f0b6c27ee8a497452559176d00f0cf257cb6”进行硬编码
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaultName": { "value": "blablabla" },
"vaultRG": { "value": "rg-blablabla" },
"policyName": { "value": "DailyPolicy" },
"fabricName": { "value": "Azure" },
"protectionContainers": {
"value": [
"storagecontainer;storage;rg-blablabla;storage002"
]
},
"protectedItems": {
"value": [
"azurefileshare;661bd40fac4e36949e3e814039158f0b6c27ee8a497452559176d00f0cf257cb6"
]
},
"sourceResourceIds": {
"value": [
"/subscriptions/ blabla bla /resourceGroups/rg-blablabla/providers/Microsoft.Storage/storageAccounts/storage002"
]
}
}
}
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaultName": { "type": "string" },
"vaultRG": { "type": "string" },
"vaultSubID": { "type": "string" },
"policyName": { "type": "string" },
"fabricName": { "type": "string" },
"protectionContainers": { "type": "array" },
"protectedItems": { "type": "array" },
"sourceResourceIds": { "type": "array" }
},
"resources": [
{
"name": "[concat(parameters('vaultName'), '/', parameters('fabricName'), '/',parameters('protectionContainers')[copyIndex()], '/', parameters('protectedItems')[copyIndex()])]",
"apiVersion": "2020-02-02",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
"properties": {
"backupManagementType": "AzureStorage",
"workloadType": "AzureFileShare",
"friendlyName": "afs",
"protectedItemType": "AzureFileShareProtectedItem",
"policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies', parameters('vaultName'), parameters('policyName'))]",
"sourceResourceId": "[parameters('sourceResourceIds')[copyIndex()]]"
},
"copy": {
"name": "protectedItemsCopy",
"count": "[length(parameters('protectedItems'))]"
}
}
]
}
它的功能并不完整,但是可以工作
答案2
这篇文章似乎回答了你的问题;https://docs.microsoft.com/en-us/azure/backup/backup-azure-file-share-rest-api
在文章中,他们描述了你可以使用name
来自获取备份可保护项目API。在他们的示例中,他们将名称显示为azurefiles;<name of your fileshare>
,但这实际上是azurefiles;<some random ID>
。正如他们自己所说;
始终采用响应的名称属性并将其填充到此请求中。不要硬编码或创建容器名称格式或受保护项名称格式。如果您创建或硬编码它,如果容器名称格式或受保护项名称格式将来发生变化,API 调用将失败。