将本地SQL Server数据库迁移到Azure SQL数据库
In this article, we will discuss and understand a method to migrate an on-premises SQL Server database to the Azure SQL database.
在本文中,我们将讨论和理解将本地SQL Server数据库迁移到Azure SQL数据库的方法。
This article will look at ways to modernize and transform applications and infrastructure by taking advantage of the agility and flexibility of the cloud.
本文将探讨通过利用云的敏捷性和灵活性来现代化和转换应用程序和基础架构的方法。
Azure SQL Database currently resides in ~50 data centers around the world, with more data centers coming online regularly, enabling you to run your database in a data center near you. With so many on-premises implementations at customer sites, how do you migrate from the traditional on-premises SQL Server implementation to modern Azure SQL Database technologies and benefit from what cloud database services can offer?
Azure SQL数据库当前位于全球约50个数据中心中,越来越多的数据中心定期上线,使您可以在附近的数据中心中运行数据库。 在客户站点上有如此众多的本地实施,您如何从传统的本地SQL Server实施迁移到现代Azure SQL数据库技术,并从可提供的云数据库服务中受益?
This article will guide you through the process and steps required to migrate your database workloads from on-premises to Azure-based cloud services.
本文将指导您完成将数据库工作负载从本地迁移到基于Azure的云服务所需的过程和步骤。
介绍 (Introduction)
Digital transformation plays a key role in every organization’s future. Dependencies on legacy systems and siloed processes act as major roadblocks to efforts towards digital transformation.
数字化转型在每个组织的未来中都扮演着关键角色。 对遗留系统和孤立过程的依赖成为实现数字化转型的主要障碍。
For many organizations, the upcoming Microsoft end of support (EOS) for Windows Server and SQL Server 2008 and SQL Server 2008 R2 brings in challenges in terms of innovation, cost, security, and regulatory compliance. Many traditional organizations are under tremendous pressure to upgrade their systems to the more recent versions of Windows and SQL Server.
对于许多组织而言,即将到来的Microsoft对Windows Server和SQL Server 2008和SQL Server 2008 R2的支持终止(EOS)带来了创新,成本,安全性和法规遵从性方面的挑战。 许多传统组织承受着巨大的压力,要求将其系统升级到Windows和SQL Server的最新版本。
If you look at the brighter side, though, this is a great opportunity for organizations to make up for the missed opportunities of the past to migrate, modernize and redefine their core to enhance performance, improve customer experience and drive a competitive edge. One of the options also available is to modernize by migrating their legacy estates to Azure SQL Database.
但是,如果您从好的方面看,这对于组织来说是一个很好的机会,可以弥补过去错过的迁移,现代化和重新定义其核心的机会,以增强性能,改善客户体验并提高竞争优势。 还可以使用的选项之一是通过将其旧版资产迁移到Azure SQL数据库来进行现代化。
为什么我们可能必须将本地SQL Server数据库迁移到Azure SQL数据库(PaaS-平台即服务)? (Why we may have to migrate on-premises SQL Server database to Azure SQL Database (PaaS—Platform as a Service)?)
Microsoft’s enabling functions and cloud offerings have many advantages with Azure SQL Database that runs as a PaaS. On a high level, for instance, there is no need for you to create VMs or install the Windows Server operating system or SQL Server. They are all simply available to use. All you have to do is log into the Azure portal and pick the size and configuration that fits your needs.
Microsoft的支持功能和云产品通过作为PaaS运行的Azure SQL数据库具有许多优势。 例如,在较高级别,不需要创建VM或安装Windows Server操作系统或SQL Server。 它们都可以简单地使用。 您要做的就是登录Azure门户,然后选择适合您需要的大小和配置。
-
Note: The PaaS offering from Microsoft provides you with everything required to support database services. Microsoft owns more than half of the administration overhead, which includes patching, software updates, system maintenance, etc. However, it is important to understand the underlying database service implications of this model. Azure SQL Database doesn’t in-house full feature parity when compared to the on-premise database versions of SQL Server like SQL Server 2014, SQL Server 2016, and SQL server 2017
Some of the major notable omissions that include Database Mail, FILESTREAM data type, and CLR integration with SQL Server. You can refer to the Microsoft documentation for more about the features that are supported and not supported by SQL PaaS offering
注意 :Microsoft的PaaS产品为您提供支持数据库服务所需的一切。 Microsoft拥有一半以上的管理开销,其中包括补丁,软件更新,系统维护等。但是,了解此模型对底层数据库服务的意义很重要。 与SQL Server的本地数据库版本(例如SQL Server 2014,SQL Server 2016和SQL Server 2017)相比,Azure SQL Database没有内部完整功能奇偶校验
一些主要的显着遗漏包括数据库邮件 , FILESTREAM数据类型以及与SQL Server的CLR集成。 您可以参考Microsoft文档以获取有关SQL PaaS产品支持和不支持的功能的更多信息。
如何验证数据库是否与Azure SQL数据库兼容? (How can you validate whether your database is compatible with Azure SQL Database?)
This can be validated in multiple ways:
这可以通过多种方式进行验证:
- Create a BACPAC file: If you can create the BACPAC file from your database that means your database can be migrated to Azure SQL Database 创建BACPAC文件 :如果可以从数据库中创建BACPAC文件,则意味着可以将数据库迁移到Azure SQL数据库
- Use a script: Generate a schema of the on-premises databases and create the same in the Azure SQL environment 使用脚本 :生成本地数据库的架构,并在Azure SQL环境中创建该架构
数据迁移有哪些方式? (What are some ways that data be migrated?)
There are several ways to migrate the data. The following are some of the methods that can be used for data migration:
有几种迁移数据的方法。 以下是一些可用于数据迁移的方法:
- Create BACPAC files and export them 创建BACPAC文件并将其导出
- Use SQL Server Management Studio; generate scripts and use the import/export data methods 使用SQL Server Management Studio; 生成脚本并使用导入/导出数据方法
- Use the Data Migration Assistant Wizard 使用数据迁移助手向导
- Leverage Transactional Replication to port the data over to the cloud 利用事务复制将数据移植到云中
- Use PowerShell and SQLPackage.exe, an SSDT tool 使用PowerShell和SQLPackage.exe(SSDT工具)
- Note: You would need to study your situation and adopt any of the above-mentioned methods based on your requirements and the current environment. It is hard to say which of these methods would be better for you until you understand the migration process. In most cases, Data Migration Assistance and/or Replication is best-suited for data migration 注意 :您将需要研究您的情况并根据您的要求和当前环境采用上述任何方法。 在您了解迁移过程之前,很难说出哪种方法对您更好。 在大多数情况下,数据迁移协助和/或复制最适合数据迁移
In this guide, I will discuss the first method to migrate the database to Azure SQL Database.
在本指南中,我将讨论将数据库迁移到Azure SQL数据库的第一种方法。
使用导出数据层应用程序导出数据库 (Exporting database using export data-tier application)
To migrate on-premises SQL Server database to Azure SQL Database Using Export Data-Tier Application:
使用导出数据层应用程序将本地SQL Server数据库迁移到Azure SQL数据库:
使用Management Studio创建BACPAC文件 (Create BACPAC files using Management Studio)
-
Verify that you have the latest version of SQL Server Management Studio. New versions of Management Studio are updated monthly to remain in sync with updates to the Azure portal
Note: It is recommended that you always use the latest version of Management Studio to remain synchronized with updates to Microsoft Azure and SQL Database.Update SQL Server Management Studio
验证您具有最新版本SQL Server Management Studio。 新版本的Management Studio每月更新一次,以与Azure门户的更新保持同步
注意 :建议始终使用最新版本的Management Studio与Microsoft Azure和SQL数据库的更新保持同步。 更新SQL Server Management Studio
- Open SQL Server Management Studio (SSMS) and connect to the source database in Object Explorer. In this case, the source database is AdventureWorks2016 打开SQL Server Management Studio(SSMS),然后在对象资源管理器中连接到源数据库。 在这种情况下,源数据库为AdventureWorks2016
-
Right-click AdventureWorks2016 database in Object Explorer, point to Tasks, and click Export Data-Tier Application…
右键单击“ 对象资源管理器”中的 AdventureWorks2016数据库,指向“ 任务” ,然后单击“ 导出数据层应用程序”。
- In the export wizard, click Next to bypass the default setting page 在导出向导中,单击“ 下一步”以跳过默认设置页面
-
In the Export Settings tab, configure the export to save the BACPAC file to either a local disk or to Azure blob storage and click Next
-
Note: A BACPAC file will only be saved if you have no database compatibility issues. If there are compatibility issues, then the error message will be displayed on the console
在“ 导出设置”选项卡中,配置导出以将BACPAC文件保存到本地磁盘或Azure blob存储,然后单击“ 下一步”。
注意 :仅当您没有数据库兼容性问题时,才会保存BACPAC文件。 如果存在兼容性问题,那么错误消息将显示在控制台上
-
- In this case, let us follow the default settings 在这种情况下,让我们遵循默认设置
- Click the Advanced tab and clear the Select All checkbox to skip exporting the data. Our goal at this point is only to test for compatibility 单击高级选项卡,然后清除全选复选框以跳过导出数据。 我们目前的目标只是测试兼容性
- Select the Save to Microsoft Azure option to save the bacpac file to Azure Blob storage 选择保存到Microsoft Azure选项以将bacpac文件保存到Azure Blob存储
-
Next, go to the Azure portal to get the storage account details. In this case, dbmigratestg is the storage account created for this exercise
接下来,转到Azure门户以获取存储帐户详细信息。 在这种情况下, dbmigratestg是为此练习创建的存储帐户
-
Select the storage account and copy the access key. Paste the key in SQL Server Management Studio and click Connect
选择存储帐户并复制访问**。 将**粘贴到SQL Server Management Studio中,然后单击“ 连接”
-
Now, you can access the Azure Blob storage
现在,您可以访问Azure Blob存储
-
Click Advanced. In this pane, you can select the intended objects that are going to be part of the migration
单击高级 。 在此窗格中,您可以选择将要包含在迁移中的预期对象
-
Before you click the Finish button, let us validate the summary in detail
在单击“ 完成”按钮之前,让我们详细验证摘要
- Click Next and then click Finish 单击下一步 ,然后单击完成
-
The Export wizard performs the database compatibility checks. If any issues are found, they will appear after the wizard validates the schema
导出向导执行数据库兼容性检查。 如果发现任何问题,它们将在向导验证架构后出现
- If no errors appear, the database is compatible and it is ready to migrate. If you encounter errors then you will need to fix them before proceeding further. To see the errors, click Error for Validating schema 如果没有错误出现,则表明数据库兼容并且可以迁移。 如果遇到错误,则需要在继续操作之前对其进行修复。 要查看错误,请单击“ 验证模式 错误” 。
- Finally, the preparation phase to migrate on-premises SQL Server database to Azure SQL Database completed 最后,将本地SQL Server数据库迁移到Azure SQL数据库的准备阶段已完成
使用导入数据库选项导入文件 (Importing file using Import database option )
In the process of migrating on-premises SQL Server database to Azure SQL Database, now we do the import of .bacpac file.
现在,在将本地SQL Server数据库迁移到Azure SQL数据库的过程中,我们将导入.bacpac文件。
将BACPAC文件导入到Azure (Importing the BACPAC file to Azure )
Now that we have the BACPAC file ready, we can now use the same to migrate the data over to Azure. This BACPAC file could be stored locally, or on Azure Blob storage (standard).
现在我们已经准备好BACPAC文件,现在我们可以使用该文件将数据迁移到Azure。 此BACPAC文件可以存储在本地,也可以存储在Azure Blob存储(标准)上。
For now, the Azure portal will allow you to only create a single database in Azure SQL Database, and this can be done only from a BACPAC file. Follow the steps below to import the BACPAC file you saved.
目前,Azure门户仅允许您在Azure SQL数据库中创建一个数据库,而这只能通过BACPAC文件来完成。 请按照以下步骤导入您保存的BACPAC文件。
- Connect to Azure portal and open the SQL database page. Navigate into your resource group and create a new instance of an Azure Database (this is out of the scope of this article). The Assumption is that Azure PaaS SQL Database is available 连接到Azure门户并打开SQL数据库页面。 导航到您的资源组并创建一个Azure数据库的新实例(这不在本文的讨论范围之内)。 假设Azure PaaS SQL数据库可用
-
Next, select the Import database on the toolbar
接下来,在工具栏上选择“ 导入数据库 ”
-
Next, locate the Blob storage account and its respective container for the BACPAC file
接下来,找到Blob存储帐户及其BACPAC文件的相应容器
-
Type in the new database name, size, and the SQL admin credentials
输入新的数据库名称,大小和SQL管理员凭据
- Clicking OK will begin the process of importing the BACPAC file into the new Azure Database, and you should be good to go 单击“ 确定”将开始将BACPAC文件导入新的Azure数据库的过程,您应该一切顺利
- Note: I recommend going for a higher DTU; higher DTU results in a higher speed of operation. Once you are set up with Azure Database, scaling the database to a higher service tier is rather simple. After the import is complete, you could even scale down to a lower tier to suit your needs 注意: 我建议使用更高的DTU。 DTU越高,操作速度就越高。 一旦设置了Azure数据库,就可以将数据库扩展到更高的服务层。 导入完成后,您甚至可以缩小到较低的级别以满足您的需求
That’s all for now…
目前为止就这样了…
摘要 (Summary)
In this post, we saw one of the ways to migrate an on-premises SQL Server database to the Azure SQL Database. We discussed one of the methods – migration using a BACPAC file in detail. I will discuss more other options in my upcoming articles. Stay tuned for more updates. Please leave your feedback and questions in the comments section below.
在本文中,我们看到了一种将本地SQL Server数据库迁移到Azure SQL数据库的方法。 我们讨论了一种方法-详细介绍了如何使用BACPAC文件进行迁移。 我将在我的后续文章中讨论更多其他选项。 敬请期待更多的更新。 请在下面的评论部分中留下您的反馈和问题。
翻译自: https://www.sqlshack.com/migrate-an-on-premises-sql-server-database-to-the-azure-sql-database/