使用AzureRM Powershell导入数据库 [英] Import a database using AzureRM Powershell

查看:60
本文介绍了使用AzureRM Powershell导入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个名为导入BACPAC文件的文档使用PowerShell 创建新的Azure SQL数据库,其中介绍了如何在ASM下将bacpac文件导入SQL Server.

There is a document named Import a BACPAC file to create a new Azure SQL database using PowerShell that covers how to import a bacpac file into SQL server under ASM.

是否可以使用Azure资源管理cmdlet将bacpac文件导入到Azure SQL Server中.

Is there a way to import a bacpac file into an Azure SQL Server using Azure Resource Management cmdlets.

在@juvchan回答之后,我一直在努力使以下内容起作用.

Following on from @juvchan answer I have been trying to get the following to work.

$update = @{
            "operationMode" = "Import"
            "storageKey"= "Key"
            "storageKeyType" = "Primary"
            "administratorLogin"= "adminlogin"
            "administratorLoginPassword"= "adminpassword"
            "storageUri"= "https://example.blob.core.windows.net/sql/exampleIOSQL-2016-1-23-12-26.bacpac"
            }
New-AzureRmResource -ResourceGroupName "resourcegroupname" `
                -ResourceType "Microsoft.Sql/servers" `
                -Name "sqldbsvr" `
                -PropertyObject $update `
                -ApiVersion 2015-08-01 `
                -Force -Location "westeurope" 

不幸的是,除了这个非常有用的错误消息,我什么也没得到-

Unfortunately I can't get anything but this very helpful error message -

New-AzureRmResource:{代码":",消息":处理此请求时发生错误.",目标":null,详细信息":[],"innererror":[]}

New-AzureRmResource : {"code":"","message":"An error occurred while processing this request.","target":null,"details":[],"innererror":[]}

推荐答案

当前,最新的 Microsoft Azure PowerShell - January 2016 (version 1.1) 的Azure RM模块没有没有任何cmdlet哪个 可以支持Azure SQL数据库导入,例如Azure Service Management的cmdlet,即Start-AzureSqlDatabaseImport

At current time, the latest Microsoft Azure PowerShell - January 2016 (version 1.1)'s Azure RM module does not have any cmdlets which can support Azure SQL database import like the Azure Service Management's cmdlet i.e. Start-AzureSqlDatabaseImport

但是,有一种解决方法可以在Azure资源管理器(ARM)上下文中实现此目标.

However, there is a workaround which can achieve this in the Azure Resource Manager (ARM) context.

解决方法是使用用户定义的ARM模板进行 Azure资源组模板部署,该模板包括数据库导入资源类型.

The workaround is to do a Azure Resource Group template deployment with a user-defined ARM template which include the database import resource type.

建议的解决方法由示例PowerShell脚本,示例ARM模板json和示例ARM模板参数json组成,如下所示:

The proposed workaround consist of a sample PowerShell script, a sample ARM template json and a sample ARM Template parameters json as shown below:

PowerShell示例代码如下:

The PowerShell sample code is as below:

Login-AzureRmAccount

$tenantId = "your_tenant_id"
$subscriptionId = "your_subscription_id"

$rgName = "your_rg_name"
$location = "your_location"
$templateFile = "YourARMTemplate.json"
$templateParamFile = "YourARMTemplate.Parameters.json"

Set-AzureRmContext -SubscriptionId $subscriptionId -TenantId $tenantId

New-AzureRmResourceGroup -Location $location -Name $rgName -Force

$deployment = New-AzureRmResourceGroupDeployment -ResourceGroupName $rgName -TemplateFile $templateFile -TemplateParameterFile $templateParamFile -Mode Incremental -Force

用于Azure SQL数据库导入的示例ARM模板json如下:

The sample ARM template json for Azure SQL database import is as below:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "dbApiVersion": "2014-04-01-preview",
    "resourceGroupLocation": "[resourceGroup().location]",
    "dbServerNameTidy": "[toLower(trim(parameters('dbServerName')))]",
    "masterDbNameTidy": "[toLower(trim(parameters('masterDbName')))]"
  },
  "parameters": {
    "dbServerName": {
      "type": "string"
    },
    "dbLogin": {
      "type": "string"
    },
    "dbPassword": {
      "type": "string"
    },
    "dbServerVersion": {
      "type": "string",
      "defaultValue": "12.0"
    },
    "dbCollation": {
      "type": "string",
      "defaultValue": "SQL_Latin1_General_CP1_CI_AS"
    },
    "dbEdition": {
      "type": "string",
      "defaultValue": "Standard"
    },
    "dbMaxSize": {
      "type": "string",
      "defaultValue": "10737418240"
    },
    "dbServiceObjectiveLevel": {
      "type": "string",
      "defaultValue": "455330E1-00CD-488B-B5FA-177C226F28B7"
    },
    "bacpacStorageKey": {
      "type": "string"
    },
    "masterDbName": {
      "type": "string"
    },
    "masterBacpacUrl": {
      "type": "string"
    },
  },
  "resources": [
    {
      "type": "Microsoft.Sql/servers",
      "apiVersion": "[variables('dbApiVersion')]",
      "properties": {
        "administratorLogin": "[parameters('dbLogin')]",
        "administratorLoginPassword": "[parameters('dbPassword')]",
        "version": "[parameters('dbServerVersion')]"
      },
      "name": "[variables('dbServerNameTidy')]",
      "location": "[variables('resourceGroupLocation')]",
      "resources": [
        {
          "type": "firewallrules",
          "apiVersion": "[variables('dbApiVersion')]",
          "properties": {
            "endIpAddress": "0.0.0.0",
            "startIpAddress": "0.0.0.0"
          },
          "name": "AllowAllWindowsAzureIps",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('dbServerNameTidy'))]"
          ]
        },
        {
          "type": "databases",
          "apiVersion": "[variables('dbApiVersion')]",
          "properties": {
            "edition": "[parameters('dbEdition')]",
            "collation": "[parameters('dbCollation')]",
            "maxSizeBytes": "[parameters('dbMaxSize')]",
            "requestedServiceObjectiveId": "[parameters('dbServiceObjectiveLevel')]"
          },
          "name": "[variables('webDbNameTidy')]",
          "location": "[variables('resourceGroupLocation')]",
          "dependsOn": [
            "[resourceId('Microsoft.Sql/servers', variables('dbServerNameTidy'))]"
          ],
          "resources": [
            {
              "type": "extensions",
              "apiVersion": "[variables('dbApiVersion')]",
              "properties": {
                "operationMode": "Import",
                "storageKey": "[parameters('bacpacStorageKey')]",
                "storageKeyType": "Primary",
                "administratorLogin": "[parameters('dbLogin')]",
                "administratorLoginPassword": "[parameters('dbPassword')]",
                "storageUri": "[parameters('masterBacpacUrl')]"
              },
              "name": "Import",
              "dependsOn": [
                "[resourceId('Microsoft.Sql/servers/databases', variables('dbServerNameTidy'), variables('masterDbNameTidy'))]"
              ]
            }
          ]
        }
      ]
    }
  ]
}

用于Azure SQL数据库导入的示例ARM模板参数json如下:

The sample ARM template parameters json for Azure SQL database import is as below:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "dbServerName": {
            "value": "<your DB Server Name>"
        },
        "dbLogin": {
            "value": "<Your DB server login name>"
        },
        "dbPassword": {
            "value": "<Your DB server login password>"
        },
        "bacpacStorageKey": {
            "value": "<Your Azure Storage Account Primary key which stores the bacpac blob>"
        },
        "masterDbName": {
            "value": "<your Azure Sql Db name>"
        },
        "masterBacpacUrl": {
            "value": "<Your Azure storage account Bacpac blob file full Url>"
        }
    }
}

希望这会有所帮助和澄清.

Hope this helps and clarifies.

这篇关于使用AzureRM Powershell导入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆