有人知道如何复制SQL Azure数据库到我的开发机器吗?我不想再花钱在云端建立开发数据库,但这是获得生产数据的最佳方式。我将我的生产数据库复制到一个新的开发数据库,但我想在本地拥有相同的数据库。

有什么建议吗?


有多种方法可以做到这一点:

Using SSIS (SQL Server Integration Services). It only imports data in your table. Column properties, constraints, keys, indices, stored procedures, triggers, security settings, users, logons, etc. are not transferred. However it is very simple process and can be done simply by going through wizard in SQL Server Management Studio. Using combination of SSIS and DB creation scripts. This will get you data and all missing metadata that is not transferred by SSIS. This is also very simple. First transfer data using SSIS (see instructions below), then create DB Create script from SQL Azure database, and re-play it on your local database. Finally, you can use Import/Export service in SQL Azure. This transfers data (with a schema objects) to Azure Blob Storage as a BACPAC. You will need an Azure Storage account and do this in Azure web portal. It is as simple as pressing an "Export" button in the Azure web portal when you select the database you want to export. The downside is that it is only manual procedure, I don't know a way to automate this through tools or scripts -- at least the first part that requires a click on the web page.

方法1(使用SSIS)的手动步骤如下:

In Sql Server Management Studio (SSMS) create new empty database on your local SQL instance. Choose Import Data from context menu (right click the database -> Tasks -> Import data...) Type in connection parameters for the source (SQL Azure). Select ".Net Framework Data Provider for SqlServer" as a provider. Choose existing empty local database as destination. Follow the wizard -- you will be able to select tables data you want to copy. You can choose to skip any of the tables you don't need. E.g. if you keep application logs in database, you probably don't need it in your backup.

您可以通过创建SSIS包并在任何您想重新导入数据的时候重新执行它来实现自动化。请注意,您只能使用SSIS导入到一个干净的DB中,如果您已经对本地数据库进行了一次增量更新,则不能再对其进行增量更新。

方法#2 (SSID数据加上模式对象)非常简单。首先执行上述步骤,然后创建数据库创建脚本(右键单击SSMS中的数据库,选择生成脚本->数据库创建)。然后在本地数据库上重新播放此脚本。

方法3在这里的博客中描述:http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-production/。有一个视频剪辑,讲述了将DB内容作为BACPAC传输到Azure Blob存储的过程。之后,您可以在本地复制该文件并将其导入SQL实例。将BACPAC导入到Data-Tier应用程序的流程介绍如下:http://msdn.microsoft.com/en-us/library/hh710052.aspx。


您也可以在Windows Azure管理门户中检查SQL Azure数据同步。它允许您检索和恢复整个数据库,包括SQL Azure和SQL Server之间的模式和数据。


下载Optillect SQL Azure备份-它有15天的试用期,所以它足以移动你的数据库:)


我无法让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”失败”。 这可以通过在映射屏幕中指定允许插入Identity元素来解决。

在此之后,使用SQL导入/导出向导从Azure复制到本地数据库,一切工作正常。

我只有SQL Server 2008 R2附带的SQL导入/导出向导(工作良好)和Visual Studio 2012 Express来创建本地数据库。


您可以使用新的Azure移动服务执行夜间备份导出,从SQL Azure导出到Azure存储托管的.bacpac文件。这个解决方案是100%的云计算,不需要第三方工具,也不需要本地托管的SQL Server实例来下载/复制/备份任何东西。

大约有8个不同的步骤,但都很简单: http://geekswithblogs.net/BenBarreth/archive/2013/04/15/how-to-create-a-nightly-backup-of-your-sql-azure.aspx


我只是想把邓布利多爸爸的回答简化一下,因为这是正确的答案。

将Azure SQL数据库导出到blob存储上的BACPAC文件。 在SQL Management studio中,右键单击数据库,单击“导入数据层应用程序”。 系统将提示您输入信息以获取Azure blob存储上的BACPAC文件。 点击next几次,然后…完成了!


使用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”


对我来说,诀窍是开始在空DB上复制pk /FKs/约束,然后在导入数据时暂时禁用约束(参见https://stackoverflow.com/a/161410)。

更准确地说应该是:

手动创建空目标DB; 右键单击源DB > Tasks >生成脚本; 在空的目标DB上运行脚本文件(现在DB有正确的PKs/FKs/约束,但没有数据); 禁用所有约束; 导入数据(右键单击目标DB > Tasks > Import data); 重新启用约束。

希望这能有所帮助!


现在您可以使用SQL Server Management Studio来完成这项工作。

连接到SQL Azure数据库。 在对象资源管理器中右键单击数据库。 选择“任务”/“部署数据库到SQL Azure”选项。 在名为“部署设置”的步骤中,选择您的本地数据库连接。 "Next" / "Next" / "Finish"…


使用SQL Azure中的导入/导出服务创建.bacpac文件。

然后在另一篇Stack Overflow文章中查看此方法。

Azure SQL数据库Bacpac本地恢复


公认的答案已经过时了。我找到了一个更好的答案:使用导入数据层应用程序

更多详细信息请参阅本文: 恢复Azure SQL数据库到本地服务器


我觉得现在容易多了。

启动SQL管理工作室 右键单击“数据库”,选择“导入数据层应用程序…” 该向导将引导您完成连接到Azure帐户、创建BACPAC文件和创建数据库的过程。

此外,我使用Sql Backup和FTP (https://sqlbackupandftp.com/)每天备份到一个安全的FTP服务器。我只是从那里取出一个最近的BACPAC文件,然后在同一个对话框中导入它,这样创建本地数据库就更快更容易了。


如果有人在导入使用Azure SQL Sync的DB的Bacpac时遇到问题,Sandrino Di Mattia开发了一个非常简单的应用程序来解决这个问题。

导出您的数据库的Bacpac 下载Di Mattia的二进制文件 用这个控制台应用程序修复下载的Bacpac 开展地对地导弹 右键单击“数据库”,选择“导入数据层应用程序” 选择修复后的Bacpac。


这很简单。这对我很管用……在获取Azure SQL数据库到本地机器方面…

打开SQL Management Studio并连接到Azure SQL Server。 选择您想要下载到本地机器上的数据库,然后右键单击…选择“生成脚本”。按照提示…

但是,要注意的是,如果你也想要数据,以及脚本,一定要检查高级选项在开始生成…向下滚动到“脚本的数据类型”,并确保你有“模式和数据”…或者任何适合你的。

它会给你一个漂亮的SQL脚本文件,然后可以在你的本地机器上运行,它会创建数据库,并填充所有的数据。

请记住,在我的情况下,我没有FK或其他约束…而且,数据也不多。

一般来说,我不建议将此作为备份机制……


您可以尝试使用“SQL数据库迁移向导”工具。 这个工具提供了从azure sql导入和导出数据的选项。

详情请点击这里。

https://sqlazuremw.codeplex.com/


在SQL Server 2016 Management Studio中,将azure数据库获取到本地机器的过程已经简化。

右键单击要导入的数据库,单击Tasks > Export data-tier application,然后将数据库导出到本地的.dacpac文件。

在本地目标SQL server实例中,可以右键单击Databases >导入数据层应用程序,一旦它是本地的,就可以执行备份和恢复数据库之类的操作。


如果有人想要一个免费有效的选项(也不介意手动操作)来将数据库备份到本地,那么可以使用最新版本Microsoft Visual Studio 2015社区版(免费)或专业/高级/终极版中内置的模式和数据比较功能。它像魔法一样有效!

我有BizPark帐户与Azure,没有办法直接备份数据库没有支付。我发现这个选项在VS工作。

答案摘自https://stackoverflow.com/a/685073/6796187


嗨,我正在使用SQLAzureMW工具进行SQLAzure DB迁移和管理。非常有用。它是从codeplex下载的,但目前它不可用,codeplex将会关闭,相同的应用程序工具现在在GttHub中可用。下面的链接解释了如何使用这个工具,也可以下载应用程序。

https://github.com/twright-msft/azure-content/blob/master/articles/sql-database/sql-database-migration-wizard.md


将Azure数据库数据复制到本地数据库: 现在你可以使用SQL Server Management Studio来完成如下操作:

连接到SQL Azure数据库。 在对象资源管理器中右键单击数据库。 选择“任务”/“部署数据库到SQL Azure”选项。 在“部署设置”步骤中,连接本地SQL Server并创建新数据库。

"Next" / "Next" / "Finish"


我总是使用导入/导出功能,这似乎是最简单的一个。

步骤1:

从azure实例获取备份,如下所示,选择数据库→右键单击→任务→导出数据层应用程序。

步骤2: 为备份文件指定一个特定的名称,并将其保存在所需的位置

步骤3:您已经将数据库的备份从sql实例备份到本地。让我们将其恢复到本地。将备份的数据库复制到C盘。现在用管理员权限打开PowerShell并导航到C驱动器

步骤4:让我们下载powershell脚本来删除主密钥removemasterkey。ps1将脚本放在同一个驱动器上,在这种情况下是C。

第五步:运行脚本,如下所示。 \ RemoveMasterKey。ps1 -bacpacPath "C:\identity.bacpac"

就是这样,现在您可以在本地环境中的MSSQL 2017上恢复它。

步骤6:连接到本地服务器,然后单击数据库→导入-数据层-应用程序

步骤7:为要恢复的数据库指定一个名称。

现在你会看到所有的东西都变成绿色了!

用图表阅读我的博客。


在SQL Server Management Studio

右键单击要导入的数据库,单击Tasks > Export data-tier application,然后将数据库导出到本地的.dacpac文件。

在本地目标SQL server实例中,可以右键单击Databases >导入数据层应用程序,一旦它是本地的,就可以执行备份和恢复数据库之类的操作。


使用SSMS v18.9+,您可以使用部署数据库到Microsoft Azure SQL数据库。

这不是很直观,但是向导允许您选择一个本地数据库,即使任务的名称是Deploy Database to Microsoft Azure SQL Database。

使用SSMS连接到Azure数据库 右键单击数据库,选择Tasks > Deploy database to Microsoft Azure SQL database。 选择本地SQL server作为目标连接。 按照其他步骤操作。


看来2022年的Management Studio缺少功能了。下面是我如何使用Azure Data Studio:

安装Azure Data Studio Open Azure Data Studio 安装名为Admin Pack for SQL Server的扩展 重启Azure Data Studio 为源数据库(Azure)和目标数据库(本地机器)设置连接 在主数据库的本地DB引擎中执行语句:

sp_configure 'contained database authentication', 1; 
GO  
RECONFIGURE;
GO

右键单击源数据库并选择数据层应用程序向导 选择导出到。bacpac文件[导出bacpac](第四,在我的当前版本的最后一个选项) 完成向导 右键单击目标数据库并选择数据层应用程序 Wizzard 选择Import from .bacpac [Import bacpac](我的版本中的第三个选项) 选择先前创建的.bacpac文件并完成向导

在导入登录名和用户之后,创建了登录名和用户,但是没有设置它们的默认模式。如果需要默认的shcema,则需要手动处理。在这种情况下: 打开到本地副本的管理连接并运行: 使用[imported-db];ALTER USER - import - USER WITH DEFAULT_SCHEMA