有人知道如何复制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。

其他回答

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

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

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

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

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

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

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

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

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

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

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

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。

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

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