Using Azure Resource Manager to Copy Azure SQL Dat

2019-05-12 18:32发布

I am currently creating an Environment Deployment Package using ARM and I want to be able copy an existing Azure SQL Database (schema and data) to another Azure SQL Database in a new Resource Group. I created a .bacpac file from the original SQL Database and uploaded it into a Storage Account. I then added a SQL Database Import Resource to my Template and pointed it at the URI of the .bacpac file I created. When I try to run the Deployment, I get this error.

A project which specifies Microsoft Azure SQL Database v12 as the target platform cannot be published to Microsoft Azure SQL Database

 {
      "name": "[concat(parameters('environment'),'dbagg')]",
      "type": "databases",
      "location": "[resourceGroup().location]",
      "apiVersion": "2014-04-01-preview",
      "dependsOn": [
        "[variables('sqlServerName')]"
      ],
      "tags": {
        "displayName": "AggregationDatabase"
      },
      "properties": {
        "collation": "[parameters('AggregationDatabaseCollation')]",
        "edition": "[parameters('AggregationDatabaseEdition')]",
        "maxSizeBytes": "1073741824",
        "requestedServiceObjectiveName": "[parameters('AggregationDatabaseRequestedServiceObjectiveName')]"
      },
      "resources": [
        {
          "name": "Import",
          "type": "extensions",
          "apiVersion": "2014-04-01-preview",
          "dependsOn": [
            "[concat(parameters('environment'),'dbagg')]"
          ],
          "tags": {
            "displayName": "Copy Azure SQL DB"
          },
          "properties": {
            "storageKeyType": "Primary",
            "storageKey": "key",
            "storageUri": "https://test.blob.core.windows.net/databasefiles/AggregationServerDCT.bacpac",
            "administratorLogin": "[parameters('sqlAdminLogin')]",
            "administratorLoginPassword": "[parameters('sqlAdminLoginPassword')]",
            "operationMode": "Import"
          }
        }
      ]
    }

Any help would be greatly appreciated on this.

2条回答
你好瞎i
2楼-- · 2019-05-12 18:48

You should double check if the version of the target logical server is V12 as well (or same as source). Also, for copy an existing Azure Sql Database you can use database copy API ("createMode": "Copy"): https://msdn.microsoft.com/en-us/library/mt163685.aspx

Thanks,

Mihaela

查看更多
相关推荐>>
3楼-- · 2019-05-12 19:00

The problem is that you are using the wrong value for storageKeyType. You need to use StorageAccessKey.

I use a template like this and that is working correctly, the only difference I see is this key type.

{
  "name": "[concat(variables('sqlServerName'), '/databasename/Import')]",
  "type": "Microsoft.Sql/servers/databases/extensions",
  "apiVersion": "[variables('sqlServerApiVersion')]",
  "tags": {
    "displayName": "Copy Azure SQL DB"
  },
  "properties": {
    "storageKeyType": "StorageAccessKey",
    "storageKey": "[listkeys(variables('storageId'), variables('storageVersion')).key1]",
    "storageUri": "[concat(parameters('_artifactsLocation'), '/database.bacpac')]",
    "administratorLogin": "[parameters('sqlServerAdminLogin')]",
    "administratorLoginPassword": "[parameters('sqlServerAdminLoginPassword')]",
    "operationMode": "Import"
  }
}

See also this documentation about all the properties and possible values: https://msdn.microsoft.com/en-us/library/azure/mt683388.aspx.

查看更多
登录 后发表回答