有人知道如何复制SQL Azure数据库到我的开发机器吗?我不想再花钱在云端建立开发数据库,但这是获得生产数据的最佳方式。我将我的生产数据库复制到一个新的开发数据库,但我想在本地拥有相同的数据库。
有什么建议吗?
有人知道如何复制SQL Azure数据库到我的开发机器吗?我不想再花钱在云端建立开发数据库,但这是获得生产数据的最佳方式。我将我的生产数据库复制到一个新的开发数据库,但我想在本地拥有相同的数据库。
有什么建议吗?
当前回答
我无法让SSIS导入/导出工作,因为我得到了错误“插入只读列“id”失败”。我也不能让http://sqlazuremw.codeplex.com/工作,上面的链接到SQL Azure数据同步不适合我。
但我发现了一篇关于BACPAC文件的优秀博客文章:http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-production/
在这篇博文的视频中,作者介绍了六个步骤:
Make or go to a storage account in the Azure Management Portal. You'll need the Blob URL and the Primary access key of the storage account. The blog post advises making a new container for the bacpac file and suggests using the Azure Storage Explorer for that. (N.B. you'll need the Blob URL and the Primary access key of the storage account to add it to the Azure Storage Explorer.) In the Azure Management Portal select the database you want to export and click 'Export' in the Import and Export section of the ribbon. The resulting dialogue requires your username and password for the database, the blob URL, and the access key. Don't forget to include the container in the blob URL and to include a filename (e.g. https://testazurestorage.blob.core.windows.net/dbbackups/mytable.bacpac). After you click Finish the database will be exported to the BACPAC file. This can take a while. You may see a zero byte file show up immediately if you check in the Azure Storage Explorer. This is the Import / Export Service checking that it has write access to the blob-store. Once that is done you can use the Azure Storage Explorer to download the BACPAC file and then in the SQL Server Management Studio right-click your local server's database folder and choose Import Data Tier Application that will start the wizard which reads in the BACPAC file to produce the copy of your Azure database. The wizard can also connect directly to the blob-store to obtain the BACPAC file if you would rather not copy it locally first.
最后一步可能只能在SQL Server Management Studio的SQL Server 2012版(我正在运行的版本)中使用。这台机器上没有更早的。在博客文章中,作者使用命令行工具DacImportExportCli.exe进行导入,我相信可以在http://sqldacexamples.codeplex.com/releases上找到
其他回答
我无法让SSIS导入/导出工作,因为我得到了错误“插入只读列“id”失败”。我也不能让http://sqlazuremw.codeplex.com/工作,上面的链接到SQL Azure数据同步不适合我。
但我发现了一篇关于BACPAC文件的优秀博客文章:http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-production/
在这篇博文的视频中,作者介绍了六个步骤:
Make or go to a storage account in the Azure Management Portal. You'll need the Blob URL and the Primary access key of the storage account. The blog post advises making a new container for the bacpac file and suggests using the Azure Storage Explorer for that. (N.B. you'll need the Blob URL and the Primary access key of the storage account to add it to the Azure Storage Explorer.) In the Azure Management Portal select the database you want to export and click 'Export' in the Import and Export section of the ribbon. The resulting dialogue requires your username and password for the database, the blob URL, and the access key. Don't forget to include the container in the blob URL and to include a filename (e.g. https://testazurestorage.blob.core.windows.net/dbbackups/mytable.bacpac). After you click Finish the database will be exported to the BACPAC file. This can take a while. You may see a zero byte file show up immediately if you check in the Azure Storage Explorer. This is the Import / Export Service checking that it has write access to the blob-store. Once that is done you can use the Azure Storage Explorer to download the BACPAC file and then in the SQL Server Management Studio right-click your local server's database folder and choose Import Data Tier Application that will start the wizard which reads in the BACPAC file to produce the copy of your Azure database. The wizard can also connect directly to the blob-store to obtain the BACPAC file if you would rather not copy it locally first.
最后一步可能只能在SQL Server Management Studio的SQL Server 2012版(我正在运行的版本)中使用。这台机器上没有更早的。在博客文章中,作者使用命令行工具DacImportExportCli.exe进行导入,我相信可以在http://sqldacexamples.codeplex.com/releases上找到
我总是使用导入/导出功能,这似乎是最简单的一个。
步骤1:
从azure实例获取备份,如下所示,选择数据库→右键单击→任务→导出数据层应用程序。
步骤2: 为备份文件指定一个特定的名称,并将其保存在所需的位置
步骤3:您已经将数据库的备份从sql实例备份到本地。让我们将其恢复到本地。将备份的数据库复制到C盘。现在用管理员权限打开PowerShell并导航到C驱动器
步骤4:让我们下载powershell脚本来删除主密钥removemasterkey。ps1将脚本放在同一个驱动器上,在这种情况下是C。
第五步:运行脚本,如下所示。 \ RemoveMasterKey。ps1 -bacpacPath "C:\identity.bacpac"
就是这样,现在您可以在本地环境中的MSSQL 2017上恢复它。
步骤6:连接到本地服务器,然后单击数据库→导入-数据层-应用程序
步骤7:为要恢复的数据库指定一个名称。
现在你会看到所有的东西都变成绿色了!
用图表阅读我的博客。
使用msdeploy.exe
注意:msdeploy.exe不能自己创建目标数据库,因此需要先手动创建它。
复制数据库属性页上的连接字符串。调整它,使其包含正确的密码。 获取目标DB的连接字符串。 像这样运行msdeploy.exe: "c:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -dest:dbDacFx="destination_DB_connection_string",dropDestinationDatabase=true -source:dbDacFx="azure_DB_connection_string",includeData=true -verbose
使用SqlPackage.exe
导出azure DB到一个bacpac包。 "c:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /a:Export /ssn:"azure_db_server" /sdn:"azure_db_name" /su:"user_name" /sp:"password" /tf:"file.bacpac" 导入包到本地DB。 “c:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe”/a:Import /SourceFile:"bacpac“/ TargetServerName:”。/ TargetDatabaseName: CopyOfAzureDb \ SQLEXPRESS”
下载Optillect SQL Azure备份-它有15天的试用期,所以它足以移动你的数据库:)
对我来说,诀窍是开始在空DB上复制pk /FKs/约束,然后在导入数据时暂时禁用约束(参见https://stackoverflow.com/a/161410)。
更准确地说应该是:
手动创建空目标DB; 右键单击源DB > Tasks >生成脚本; 在空的目标DB上运行脚本文件(现在DB有正确的PKs/FKs/约束,但没有数据); 禁用所有约束; 导入数据(右键单击目标DB > Tasks > Import data); 重新启用约束。
希望这能有所帮助!