简体   繁体   English

将 azure sql 数据库还原到托管实例

[英]Restore azure sql database to managed instance

I am trying to do a daily restore from azure sql database (elastic pool) into a managed instance.我正在尝试每天从 azure sql 数据库(弹性池)还原到托管实例。 I have tried to export and import the bacpac file but that failed with the following error:我曾尝试导出和导入 bacpac 文件,但由于以下错误而失败:

TITLE: Microsoft SQL Server Management Studio标题:Microsoft SQL Server 管理工作室


Could not import package.无法导入包。
Warning SQL72012: The object [XTP] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.警告 SQL72012:目标 [XTP] 存在于目标中,但即使您选中了“为目标数据库中但不在源中的对象生成删除语句”复选框,它也不会被删除。
Warning SQL72012: The object [XTP] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.警告 SQL72012:目标 [XTP] 存在于目标中,但即使您选中了“为目标数据库中但不在源中的对象生成删除语句”复选框,它也不会被删除。
Warning SQL72012: The object [data_0] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.警告 SQL72012:目标 [data_0] 存在于目标中,但即使您选中了“为目标数据库中但不在源中的对象生成删除语句”复选框,它也不会被删除。
Warning SQL72012: The object [log] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.警告 SQL72012:目标 [log] 存在于目标中,但即使您选中了“为目标数据库中但不在源中的对象生成删除语句”复选框,它也不会被删除。
Error SQL72014: .Net SqlClient Data Provider: Msg 102, Level 16, State 30, Line 1 Incorrect syntax near 'type'.错误 SQL72014:.Net SqlClient 数据提供程序:消息 102,级别 16,状态 30,第 1 行“类型”附近的语法不正确。
Error SQL72045: Script execution error.错误 SQL72045:脚本执行错误。 The executed script:执行的脚本:

 CREATE USER [**************] WITH SID = 0x6B6F4FABE3FFA848BAFB6C956D9A7E9C, TYPE = E;

I have also tried to use the automation accounts to execute powershell but that also didn't seem to support the managed instance.我还尝试使用自动化帐户来执行 powershell,但这似乎也不支持托管实例。

How can I restore these sql databases into the managed instance?如何将这些 sql 数据库还原到托管实例中?

Congratulations you managed to get is work:恭喜你成功获得了工作:

  1. Create a copy of the DB创建数据库的副本
  2. drop all AAD users from the database before exporting在导出之前从数据库中删除所有 AAD 用户

This can be beneficial to other community members.这可能对其他社区成员有益。 Thank you.谢谢你。

Also what you can do is:您还可以做的是:

  1. rename the .bacpac file to .zip and unzip it将 .bacpac 文件重命名为 .zip 并解压

  2. go to model.xml file and find all entries that looks like:转到 model.xml 文件并找到所有类似于以下内容的条目:

     a) <Element Type="SqlRoleMembership"> b) <Element Type="SqlUser" Name=" c) <Element Type="SqlLogin" Name=" d) <Element Type="SqlExternalDataSource"
  3. after that save the model.xml and run this powershell:之后保存model.xml并运行这个powershell:

    $modelXmlPath = Read-Host "PAth to model.xml" $hasher =[System.Security.Cryptography.HashAlgorithm]::Create("System.Security.Cryptography.SHA256CryptoServiceProvider") $fileStream = new-object System.IO.FileStream ` -ArgumentList @($modelXmlPath, [System.IO.FileMode]::Open) $hash = $hasher.ComputeHash($fileStream) $hashString = "" Foreach ($b in $hash) { $hashString += $b.ToString("X2") } $fileStream.Close() $hashString $modelXmlPath = Read-Host“model.xml 的路径” $hasher =[System.Security.Cryptography.HashAlgorithm]::Create("System.Security.Cryptography.SHA256CryptoServiceProvider") $fileStream = new-object System.IO.FileStream ` -ArgumentList @($modelXmlPath, [System.IO.FileMode]::Open) $hash = $hasher.ComputeHash($fileStream) $hashString = "" Foreach ($b in $hash) { $hashString += $b .ToString("X2") } $fileStream.Close() $hashString

  4. take the hash and substitute the actual checksum value at Origin.Xml取散列并替换 Origin.Xml 中的实际校验和值

  5. zip everything again and import anywhere (almost)再次压缩所有内容并在任何地方导入(几乎)

please find reference entry:请找到参考条目:

Error Importing Azure bacpac file to local db error incorrect syntax near EXTERNAL 将 Azure bacpac 文件导入到本地数据库时出错,EXTERNAL 附近的语法不正确

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM