我正在使用 New-AzureRmResourceGroupDeployment Powershell cmdlet 部署到使用 Azure 资源模板的资源组。这是一个测试环境,因此我想从 .bacpac 文件恢复数据库,以便为数据库提供真实的数据量。
以下代码段在第一次部署到此资源组时成功部署,因为没有现有数据库,但在任何后续部署中都失败。
{
"name": "[variables('databaseName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[variables('databaseServerName')]",
"[concat('Microsoft.Sql/servers/', variables('databases.ServerName'))]"
],
"tags": {
"displayName": "testDatabase"
},
"properties": {
"collation": "[variables('databaseCollation')]",
"edition": "[variables('databaseEdition')]",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "[variables('databaseServicePlan')]"
},
"resources": [
{
"name": "Import",
"type": "extensions",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[variables('databaseName')]"
],
"properties": {
"storageKeyType": "[variables('databaseBackupStorageKeyType')]",
"storageKey": "[parameters('databaseBackupStorageKey')]",
"storageUri": "[concat(parameters('databaseBackupStorageLocation'), '/', parameters('backupFileName'))]",
"administratorLogin": "[variables('databaseAdminLogin')]",
"administratorLoginPassword": "[variables('databaseAdminPassword')]",
"operationMode": "Import"
}
}
]
}
失败时的错误:
Resource Microsoft.Sql/servers/databases/extensions '[resource-group-name]/[database-name]/Import' failed with message 'The ImportExport operation with Request Id 'b1f54bdd-6c98-4feb-a86f-656a5c6f1cc5' failed due to 'Error encountered during the service operation.
Data cannot be imported into target because it contains one or more user objects. Import should be performed against a new, empty database.
也许我误解了这些模板是如何部署的——我认为 ARM 修补了环境。有谁知道我可以通知 ARM 仅在这些资源的配置发生更改时创建/更新数据库(和子资源)的方法?
或者,如果有更好的方法来使用资源模板恢复数据库,我很想听听。
非常感谢任何帮助或建议!
提前致谢,
抢