有人知道如何复制SQL Azure数据库到我的开发机器吗?我不想再花钱在云端建立开发数据库,但这是获得生产数据的最佳方式。我将我的生产数据库复制到一个新的开发数据库,但我想在本地拥有相同的数据库。
有什么建议吗?
有人知道如何复制SQL Azure数据库到我的开发机器吗?我不想再花钱在云端建立开发数据库,但这是获得生产数据的最佳方式。我将我的生产数据库复制到一个新的开发数据库,但我想在本地拥有相同的数据库。
有什么建议吗?
当前回答
使用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作为目标连接。 按照其他步骤操作。
其他回答
有多种方法可以做到这一点:
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。
嗨,我正在使用SQLAzureMW工具进行SQLAzure DB迁移和管理。非常有用。它是从codeplex下载的,但目前它不可用,codeplex将会关闭,相同的应用程序工具现在在GttHub中可用。下面的链接解释了如何使用这个工具,也可以下载应用程序。
https://github.com/twright-msft/azure-content/blob/master/articles/sql-database/sql-database-migration-wizard.md
对我来说,诀窍是开始在空DB上复制pk /FKs/约束,然后在导入数据时暂时禁用约束(参见https://stackoverflow.com/a/161410)。
更准确地说应该是:
手动创建空目标DB; 右键单击源DB > Tasks >生成脚本; 在空的目标DB上运行脚本文件(现在DB有正确的PKs/FKs/约束,但没有数据); 禁用所有约束; 导入数据(右键单击目标DB > Tasks > Import data); 重新启用约束。
希望这能有所帮助!
如果有人想要一个免费有效的选项(也不介意手动操作)来将数据库备份到本地,那么可以使用最新版本Microsoft Visual Studio 2015社区版(免费)或专业/高级/终极版中内置的模式和数据比较功能。它像魔法一样有效!
我有BizPark帐户与Azure,没有办法直接备份数据库没有支付。我发现这个选项在VS工作。
答案摘自https://stackoverflow.com/a/685073/6796187
看来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