如何将 SQL Azure 数据库复制到本地开发服务器?
有谁知道如何将 SQL Azure 数据库复制到我的开发计算机上?我想停止付费在云中拥有开发数据库,但这是获取生产数据的最佳方式。我将生产数据库复制到新的开发数据库,但我希望在本地拥有相同的数据库。
有什么建议吗?
Does anyone know how I can copy a SQL Azure database to my development machine? I'd like to stop paying to have a development database in the cloud, but it's the best way to get production data. I copy my production database to a new development database but I'd like to have that same database local.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(25)
将 Azure 数据库数据复制到本地数据库:
现在您可以使用 SQL Server Management Studio 执行以下操作:
下一步 -> 下一步 -> 完成
Copy Azure database data to local database:
Now you can use the SQL Server Management Studio to do this as below:
Next -> Next -> Finish
有多种方法可以做到这一点:
数据
。列属性、约束、键、索引、存储过程、触发器、安全设置、用户、登录名等不会传输。然而,这是一个非常简单的过程,只需通过 SQL Server Management Studio 中的向导即可完成。方法#1(使用 SSIS)的手动过程如下:
您可以通过创建 SSIS 包并在需要重新导入数据时重新执行它来自动化它。请注意,您只能使用 SSIS 导入到干净的数据库,一旦完成一次就无法对本地数据库进行增量更新。
方法#2(SSID 数据加模式对象)非常简单。首先执行上述步骤,然后创建数据库创建脚本(右键单击 SSMS 中的数据库,选择生成脚本 -> 数据库创建)。然后在本地数据库上重新运行此脚本。
方法#3在博客中进行了描述:http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-product/。有一个视频剪辑,介绍了将数据库内容传输到 Azure Blob 存储作为 BACPAC 的过程。之后,您可以在本地复制该文件并将其导入到您的 SQL 实例。将 BACPAC 导入数据层应用程序的过程如下所述:http://msdn。 microsoft.com/en-us/library/hh710052.aspx。
There are multiple ways to do this:
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.Manual procedure for method #1 (using SSIS) is the following:
You can automate it by creating SSIS package and re-executing it any time you like to re-import the data. Note that you can only import using SSIS to a clean DB, you cannot do incremental updates to your local database once you already done it once.
Method #2 (SSID data plus schema objects) is very simple. First go though a steps described above, then create DB Creation script (righ click on database in SSMS, choose Generate Scripts -> Database Create). Then re-play this script on your local database.
Method #3 is described in the Blog here: http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-production/. There is a video clip with the process of transferring DB contents to Azure Blob storage as BACPAC. After that you can copy the file locally and import it to your SQL instance. Process of importing BACPAC to Data-Tier application is described here: http://msdn.microsoft.com/en-us/library/hh710052.aspx.
在 SQL Server 2016 Management Studio 中,将 Azure 数据库获取到本地计算机的过程已得到简化。
右键单击要导入的数据库,单击任务>导出数据层应用程序,并将数据库导出到本地 .dacpac 文件。
在本地目标 SQL Server 实例中,您可以右键单击数据库 >导入数据层应用程序,一旦它是本地的,您就可以执行诸如备份和恢复数据库之类的操作。
In SQL Server 2016 Management Studio, the process for getting an azure database to your local machine has been streamlined.
Right click on the database you want to import, click Tasks > Export data-tier application, and export your database to a local .dacpac file.
In your local target SQL server instance, you can right click Databases > Import data-tier application, and once it's local, you can do things like backup and restore the database.
我只是想添加 dumbledad 的答案 的简化版本,因为它是正确的。
I just wanted to add a simplified version of dumbledad's answer, since it is the correct one.
我认为现在容易多了。
此外,我使用 Sql Backup 和 FTP (https://sqlbackupandftp.com/) 每日备份到安全的 FTP 服务器。我只需从那里提取最近的 BACPAC 文件并将其导入到同一个对话框中,这样可以更快、更轻松地创建本地数据库。
I think it is a lot easier now.
Additionally, I use Sql Backup and FTP (https://sqlbackupandftp.com/) to do daily backups to a secure FTP server. I simply pull a recent BACPAC file from there and it import it in the same dialog, which is faster and easier to create a local database.
您还可以查看 Windows Azure 管理门户中的 SQL Azure 数据同步。它允许您检索和恢复整个数据库,包括 SQL Azure 和 SQL Server 之间的架构和数据。
You can also check out SQL Azure Data Sync in the Windows Azure Management Portal. It allows you to retrieve and restore an entire database, including schema and data between SQL Azure and SQL Server.
使用
msdeploy.exe
警告:
msdeploy.exe
无法自行创建目标数据库,因此您需要先手动创建它。像这样运行
msdeploy.exe
:使用
SqlPackage.exe
将 azure DB 导出到 bacpac 包。
将包导入到本地数据库。
Using
msdeploy.exe
Caveat:
msdeploy.exe
fails to create the destination database on its own, so you need to create it manually first.Run
msdeploy.exe
like this:Using
SqlPackage.exe
Export the azure DB to a bacpac package.
Import the package to a local DB.
这很容易。这对我有用...将 Azure SQL 数据库下载到本地计算机...:
但是,请注意,如果您还需要数据以及脚本,请务必在开始生成之前检查高级选项...向下滚动到“要编写脚本的数据类型”,并确保您有“架构和数据”...或任何适合您的内容。
它会给你一个很好的 SQL 脚本文件,然后可以在你的本地计算机上运行它,它将创建数据库并用所有数据填充它。
请记住,就我而言,我没有 FK 或其他限制......而且,数据也不是很多。
我一般不建议将此作为备份机制......
It's pretty easy. This worked for me...in terms of getting an Azure SQL database down onto your local machine...:
BUT, be careful in that if you ALSO want the DATA, as well as the scripts, be sure to check the Advanced Options before beginning the generating...scroll down to "Types of data to script", and make sure you have "Schema and data"...or whatever is appropriate for you.
It will give you a nice SQL script file which can then be run on your local machine and it will create the database as well as populate it with all the data.
Bare in mind that in my case, I have no FK or other constraints...also, it wasn't a lot of data.
I don't recommend this as a backup mechanism in general...
在 SQL Server Management Studio 中
右键单击要导入的数据库,单击“任务”>“导入”。导出数据层应用程序,并将数据库导出到本地 .dacpac 文件。
在本地目标 SQL Server 实例中,您可以右键单击“数据库”>“数据库”>“数据库”。导入数据层应用程序,一旦它是本地的,您就可以执行诸如备份和恢复数据库之类的操作。
In SQL Server Management Studio
Right click on the database you want to import, click Tasks > Export data-tier application, and export your database to a local .dacpac file.
In your local target SQL server instance, you can right click Databases > Import data-tier application, and once it's local, you can do things like backup and restore the database.
看起来 2022 年 Management Studio 中缺少该功能。以下是我使用 Azure Data Studio 执行此操作的方法:
选择导出到
.bacpac
文件 [导出 bacpac](我当前版本中的第四个选项,最后一个选项).bacpac 导入
[导入 bacpac](我的版本中的第三个选项).bacpac
文件并完成向导导入后,将创建登录名和用户,但未设置其默认架构。如果需要默认模式,则需要手动处理。在这种情况下:
打开与本地副本的管理连接并运行:
Looks like the functionality is missing from Management Studio in 2022. Here is how I do it using Azure Data Studio:
Select Export to
.bacpac
file [Export bacpac] (4th, last option in my current version).bacpac
[Import bacpac] (3rd option in my version).bacpac
file previously created and finish the wizardAfter importing the logins and users are created, but their default schema isn’t set. If default schema is required that needs to be handled manually. In that case:
Open an admin connection to the local copy and run:
使用 SSMS v18.9+,您可以使用
将数据库部署到 Microsoft Azure SQL 数据库
。它并不是很直观,但向导允许您选择本地数据库,即使任务名称是
将数据库部署到 Microsoft Azure SQL 数据库
。Using SSMS v18.9+, you can use the
Deploy Database to Microsoft Azure SQL Database
.It's not really intuitive, but the wizard allow you to select a local db even if the name of the task is
Deploy Database to Microsoft Azure SQL Database
.Tasks > Deploy Database to Microsoft Azure SQL Database
.我总是使用导入/导出功能,这似乎是最简单的功能。
第 1 步:
从 azure 实例获取备份,如下所示,选择数据库 → 右键单击 → 任务 → 导出数据层应用程序。
第 2 步:
为备份文件指定一个特定名称,并将其保存在您所需的位置
步骤 3: 这样您就已经将数据库从 sql 实例备份到本地。让我们将其恢复到本地。将备份的数据库复制到C盘。现在以管理员权限打开 PowerShell 并导航到 C 盘
第 4 步:让我们下载 powershell 脚本来删除主服务器keyRemoveMasterKey.ps1 在同一驱动器上有脚本,在本例中为 C
第 5 步:运行脚本如下,
.\RemoveMasterKey.ps1 -bacpacPath "C:\identity.bacpac"
就是这样,现在您可以在本地环境中的 MSSQL 2017 上恢复它。
第 6 步: 连接到本地服务器,然后单击“数据库”→“导入数据层-应用程序”
第 7 步:为要恢复的数据库指定名称。
现在你会看到一切都是绿色的!
阅读我的博客 带有图表。
I always use Import/Export Feature which seems to be the easiest one among all.
Step 1:
Get the backup from the azure instance as follows, Select the database → Right click → Tasks → Export Data Tier Application.
Step 2:
Give a specific name for the backup file and save it in your desired location
Step 3: That's it you have taken a backup of the database from sql instance to your local. Lets restore it to the local. Copy the backed up database to your C drive. Now open the PowerShell with administrator rights and navigate to C drive
Step 4: Lets download the powershell script to remove the master keyRemoveMasterKey.ps1 have the script on the same drive in this case its C.
Step 5 : Run the script as follows,
.\RemoveMasterKey.ps1 -bacpacPath "C:\identity.bacpac"
That's it, now you can restore it on MSSQL 2017 in your local environment.
Step 6: Connect to your local server, and click Databases → Import-Data-Tier-Application
Step 7 : Give a name for your database to restore.
Now you will see everything in green!
Read my blog with diagrams.
我无法让 SSIS 导入/导出工作,因为我收到错误“插入只读列“id”失败”。我也无法让 http://sqlazuremw.codeplex.com/ 工作,并且上面的链接到 SQL Azure数据同步对我不起作用。
但我发现了一篇关于 BACPAC 文件的优秀博客文章:http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-product/
在帖子中的视频博客文章的作者介绍了六个步骤:
在 Azure 管理门户中创建或转到存储帐户。
您将需要 Blob URL 和存储的主访问密钥
帐户。
该博客文章建议为 bacpac 文件创建一个新容器,并
建议使用 Azure 存储
资源管理器为此。 (注:
您将需要 Blob URL 和存储的主访问密钥
帐户将其添加到 Azure 存储资源管理器。)
在 Azure 管理门户中选择您想要的数据库
导出并单击“导入和导出”部分中的“导出”
丝带。
出现的对话需要您的用户名和密码
数据库、blob URL 和访问密钥。不要忘记包括
blob URL 中的容器并包含文件名(例如
https://testazurestorage.blob.core.windows.net/dbbackups/mytable.bacpac )。
单击“完成”后,数据库将导出到 BACPAC
文件。这可能需要一段时间。您可能会看到出现一个零字节文件
如果您签入 Azure 存储资源管理器,请立即查看。这是
导入/导出服务检查它是否具有对
blob 商店。
完成后,您可以使用 Azure 存储资源管理器下载
BACPAC 文件,然后在 SQL Server Management Studio 中
右键单击本地服务器的数据库文件夹并选择导入
数据层应用程序将启动读取的向导
BACPAC 文件来生成 Azure 数据库的副本。巫师
还可以直接连接到 blob-store 来获取 BACPAC
如果您不想先将其复制到本地,则
最后一步可能仅在 SQL Server Management Studio 的 SQL Server 2012 版本(即我正在运行的版本)中可用。我没有这台机器上的早期版本可供检查。在博客文章中,作者使用命令行工具 DacImportExportCli.exe 进行导入,我相信可以在 http:// sqldacexamples.codeplex.com/releases
I couldn't get the SSIS import / export to work as I got the error 'Failure inserting into the read-only column "id"'. Nor could I get http://sqlazuremw.codeplex.com/ to work, and the links above to SQL Azure Data Sync didn't work for me.
But I found an excellent blog post about BACPAC files: http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-production/
In the video in the post the blog post's author runs through six steps:
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.
The last step may only be available in the SQL Server 2012 edition of the SQL Server Management Studio (that's the version I am running). I do not have earlier ones on this machine to check. In the blog post the author uses the command line tool DacImportExportCli.exe for the import which I believe is available at http://sqldacexamples.codeplex.com/releases
关于“我无法让 SSIS 导入/导出工作,因为我收到错误“插入只读列“id”失败”。
这可以通过在映射屏幕中指定您确实希望允许插入 Identity 元素来解决。
之后,使用 SQL 导入/导出向导从 Azure 复制到本地数据库,一切正常。
我只有 SQL Server 2008 R2 附带的 SQL 导入/导出向导(工作正常)和 Visual Studio 2012 Express 来创建本地数据库。
Regarding the " I couldn't get the SSIS import / export to work as I got the error 'Failure inserting into the read-only column "id"'.
This can be gotten around by specifying in the mapping screen that you do want to allow Identity elements to be inserted.
After that, everything worked fine using SQL Import/Export wizard to copy from Azure to local database.
I only had SQL Import/Export Wizard that comes with SQL Server 2008 R2 (worked fine), and Visual Studio 2012 Express to create local database.
接受的答案已过时。我找到了更好的答案:使用导入数据层应用程序
更详细的信息请参阅这篇文章:
将 Azure SQL 数据库恢复到本地服务器
The accepted answer is out of date. I found a better answer: Use Import Data-tier Application
More detailed information please see this article:
Restoring Azure SQL Database to a Local Server
您可以尝试使用“SQL数据库迁移向导”工具。
该工具提供从 azure sql 导入和导出数据的选项。
请在此处查看更多详细信息。
https://sqlazuremw.codeplex.com/
You can try with the tool "SQL Database Migration Wizard".
This tool provide option to import and export data from azure sql.
Please check more details here.
https://sqlazuremw.codeplex.com/
您可以使用新的 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
You can use the new Azure Mobile Services to do a nightly backup export from SQL Azure to a .bacpac file hosted in Azure Storage. This solution is 100% cloud, doesn't require a 3rd party tool and doesn't require a local hosted SQL Server instance to download/copy/backup anything.
There's about 8 different steps, but they're all easy:
http://geekswithblogs.net/BenBarreth/archive/2013/04/15/how-to-create-a-nightly-backup-of-your-sql-azure.aspx
下载 Optillect SQL Azure Backup - 它有 15 天试用期,所以它将足以移动您的数据库:)
Download Optillect SQL Azure Backup - it has 15-day trial, so it will be enough to move your database :)
对我来说,诀窍是开始在空数据库上复制 PKs/FKs/constraints,然后在导入数据时暂时禁用约束(请参阅 https://stackoverflow.txt)。 com/a/161410)。
更准确地说:
希望这有帮助!
The trick for me was to start replicating PKs/FKs/constraints on empty DB, then temporarily disable constraints while importing data (see https://stackoverflow.com/a/161410).
More precisely:
Hope this helps!
现在您可以使用 SQL Server Management Studio 来执行此操作。
Now you can use the SQL Server Management Studio to do this.
使用 SQL Azure 中的导入/导出服务创建 .bacpac 文件。
然后在另一篇 Stack Overflow 文章中看看这个方法。
Azure SQL 数据库 Bacpac 本地还原
Use the Import/Export service in SQL Azure to create a .bacpac file.
Then take a look at this method in another Stack Overflow article.
Azure SQL Database Bacpac Local Restore
如果有人在导入使用Azure SQL Sync的数据库的 Bacpac 时遇到问题,Sandrino Di Mattia 开发了很棒的简单应用程序来解决这个问题。
If anyone has a problem to import a Bacpac of a DB that uses Azure SQL Sync, Sandrino Di Mattia developed a great simple application to solve this.
如果有人想要一个免费且有效的选项(并且不介意手动执行)将数据库备份到本地,请使用最新版本 Microsoft Visual Studio 2015 Community Edition(免费)或 Professional / Premium / Ultimate 中内置的架构和数据比较功能版。它就像一个魅力!
我有Azure的BizPark帐户,没有办法直接备份数据库而不付费。我在VS中找到了这个选项。
答案取自 https://stackoverflow.com/a/685073/6796187
If anyone wants a free and effective option (and don't mind doing it manually) to backup database to Local then use schema and data comparison functionality built into the latest version Microsoft Visual Studio 2015 Community Edition (Free) or Professional / Premium / Ultimate edition. It works like a charm!
I have BizPark account with Azure and there is no way to backup database directly without paying. I found this option in VS works.
Answer is taken from 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
Hi I'm using the SQLAzureMW tool for SQLAzure DB migration and management. Very useful one. It was downloaded from codeplex, but currently it's not available the codeplex will be going to shutdown, the same application tool is now available in GttHub. This below link is explain how to use this tool and also available the Application for download.
https://github.com/twright-msft/azure-content/blob/master/articles/sql-database/sql-database-migration-wizard.md
1- 获取数据库 bacpac 文件:
2- 在本地计算机上恢复 bacpac 文件:
1- Get your database bacpac file:
2- Restoring the bacpac file on your local machine: