迁移指南:将 SQL Server 到 Azure SQL 托管实例Migration guide: SQL Server to Azure SQL Managed Instance

适用于: Azure SQL 托管实例

本指南帮助你将 SQL Server 实例迁移至 Azure SQL 托管实例。This guide helps you migrate your SQL Server instance to Azure SQL Managed Instance.

你可以迁移在本地或以下位置运行的 SQL Server:You can migrate SQL Server running on-premises or on:

  • 虚拟机上的 SQL ServerSQL Server on Virtual Machines
  • Amazon Web Services (AWS) EC2Amazon Web Services (AWS) EC2
  • Amazon 关系数据库服务 (AWS RDS)Amazon Relational Database Service (AWS RDS)
  • 计算引擎 (Google Cloud Platform - GCP)Compute Engine (Google Cloud Platform - GCP)
  • Cloud SQL for SQL Server (Google Cloud Platform - GCP)Cloud SQL for SQL Server (Google Cloud Platform – GCP)

如需更多迁移信息,请参阅迁移概述For more migration information, see the migration overview. 有关其他迁移指南,请参阅数据库迁移For other migration guides, see Database Migration.

迁移流程

先决条件Prerequisites

若要将 SQL Server 迁移至 Azure SQL 托管实例,请确保已执行以下操作:To migrate your SQL Server to Azure SQL Managed Instance, make sure you have:

迁移前Pre-migration

验证你的源环境是否受支持后,开始预迁移阶段。After you've verified that your source environment is supported, start with the pre-migration stage. 发现所有现有数据源,评估迁移可行性,确定可能会妨碍迁移的任何阻碍性问题。Discover all of the existing data sources, assess migration feasibility, and identify any blocking issues that might prevent your migration.

发现Discover

在“发现”阶段,扫描网络以查明你的组织使用的所有 SQL Server 实例和功能。In the Discover phase, scan the network to identify all SQL Server instances and features used by your organization.

你可以使用  Microsoft 评估和规划工具包(“MAP 工具包”)来评估你当前的 IT 基础结构。You can use the Microsoft Assessment and Planning Toolkit (the "MAP Toolkit") to assess your current IT infrastructure. 该工具包提供了功能强大的清单、评估和报告工具,可以简化迁移规划过程。The toolkit provides a powerful inventory, assessment, and reporting tool to simplify the migration planning process.

若要详细了解可用于“发现”阶段的工具,请参阅可用于数据迁移方案的服务和工具For more information about tools available to use for the Discover phase, see Services and tools available for data migration scenarios.

评估Assess

发现数据源后,评估可迁移到 Azure SQL 托管实例的任何本地 SQL Server 实例,以确定迁移阻碍或兼容性问题。After data sources have been discovered, assess any on-premises SQL Server instance(s) that can be migrated to Azure SQL Managed Instance to identify migration blockers or compatibility issues.

你可以使用数据迁移助手(版本 4.1 及更高版本)来评估要获取的数据库:You can use the Data Migration Assistant (version 4.1 and later) to assess databases to get:

若要使用“数据库迁移评估”来评估你的环境,请执行以下步骤:To assess your environment using the Database Migration Assessment, follow these steps:

  1. 打开数据迁移助手 (DMA)Open the Data Migration Assistant (DMA).
  2. 选择“文件”,然后选择“新建评估” 。Select File and then choose New assessment.
  3. 指定一个项目名称,选择“SQL Server”作为源服务器类型,然后选择“Azure SQL 托管实例”作为目标服务器类型。Specify a project name, select SQL Server as the source server type, and then select Azure SQL Managed Instance as the target server type.
  4. 选择要生成的评估报告的类型,Select the type(s) of assessment reports that you want to generate. 例如,数据库兼容性和功能奇偶一致性。For example, database compatibility and feature parity. 根据评估类型,源 SQL Server 上所需的权限可能有所不同。Based on the type of assessment, the permissions required on the source SQL Server can be different. 在运行评估之前,DMA 会突出显示所选顾问所需的权限。DMA will highlight the permissions required for the chosen advisor before running the assessment.
    • “功能奇偶一致性”类别提供了一套全面的建议、Azure 中可用的替代项以及缓解步骤来帮助你计划迁移项目The feature parity category provides a comprehensive set of recommendations, alternatives available in Azure, and mitigating steps to help you plan your migration project. (需要 sysadmin 权限)。(sysadmin permissions required)
    • “兼容性问题”类别标识了可能会阻止迁移的“部分支持或完全不支持”功能兼容性问题,以及用于解决这些问题的建议(需要 CONNECT SQLVIEW SERVER STATEVIEW ANY DEFINITION 权限)。The compatibility issues category identifies partially supported or unsupported feature compatibility issues that might block migration as well as recommendations to address them (CONNECT SQL, VIEW SERVER STATE, and VIEW ANY DEFINITION permissions required).
  5. 指定 SQL Server 的源连接详细信息并连接到源数据库。Specify the source connection details for your SQL Server and connect to the source database.
  6. 选择“开始评估”。Select Start assessment.
  7. 完成此过程时后,选择并查看针对迁移阻止和功能奇偶一致性问题的评估报告。When the process is complete, select and review the assessment reports for migration blocking and feature parity issues. 还可以将评估报告导出到文件,以便与组织中的其他团队或人员共享。The assessment report can also be exported to a file that can be shared with other teams or personnel in your organization.
  8. 确定可以最大程度地减少迁移后工作的数据库兼容性级别。Determine the database compatibility level that minimizes post-migration efforts.
  9. 确定最适合本地工作负载的 Azure SQL 托管实例 SKU。Identify the best Azure SQL Managed Instance SKU for your on-premises workload.

若要了解详细信息,请参阅使用数据迁移助手进行 SQL Server 迁移评估To learn more, see Perform a SQL Server migration assessment with Data Migration Assistant.

如果 SQL 托管实例不适合你的工作负载,则 Azure VM 上的 SQL Server 可能是适用于你的业务的可行替代目标。If SQL Managed Instance is not a suitable target for your workload, SQL Server on Azure VMs might be a viable alternative target for your business.

规模化评估和分析Scaled Assessments and Analysis

数据迁移助手支持执行规模化评估以及对评估报告进行合并以进行分析。Data Migration Assistant supports performing scaled assessments and consolidation of the assessment reports for analysis. 如果你有多个服务器和数据库需要进行规模化评估和分析以提供更广泛的数据资产视图,请单击以下链接来了解详细信息。If you have multiple servers and databases that need to be assessed and analyzed at scale to provide a wider view of the data estate, click on the following links to learn more.

创建性能基线Create a performance baseline

如果需要将 SQL 托管实例上工作负载的性能与 SQL Server 上运行的原始工作负载的性能进行比较,请创建用于比较的性能基线。If you need to compare the performance of your workload on a SQL Managed Instance with your original workload running on SQL Server, create a performance baseline to use for comparison. 请参阅性能基线以了解详细信息。See performance baseline to learn more.

创建 SQL 托管实例Create SQL Managed Instance

根据发现和评估阶段中的信息,创建适当大小的目标 SQL 托管实例。Based on the information in the discover and assess phase, create an appropriately-sized target SQL Managed Instance. 为此,你可以使用 Azure 门户PowerShellAzure 资源管理器 (ARM) 模板You can do so by using the Azure portal, PowerShell, or an Azure Resource Manager (ARM) Template.

迁移Migrate

完成与预迁移阶段相关的任务后,便可以执行架构和数据迁移。After you have completed tasks associated with the Pre-migration stage, you are ready to perform the schema and data migration.

使用所选的迁移方法迁移你的数据。Migrate your data using your chosen migration method.

本指南介绍了两个最常用的选项 - Azure 数据库迁移服务 (DMS) 以及本机备份和还原。This guide describe the two most popular options - Azure Database Migration Service (DMS) and native backup and restore.

数据库迁移服务Database Migration Service

若要使用 DMS 进行迁移,请执行以下步骤:To perform migrations using DMS, follow the steps below:

  1. 如果是第一次执行此操作,请在订阅中注册 Microsoft.DataMigration 资源提供程序。Register the Microsoft.DataMigration resource provider in your subscription if you are performing this for the first time.
  2. 在你选择的所需位置(最好与目标 Azure SQL 托管实例位于同一区域)创建 Azure 数据库迁移服务实例,并选择一个现有虚拟网络或创建新的虚拟网络来托管 DMS 实例。Create an Azure Database Migration Service Instance in a desired location of your choice (preferably in the same region as your target Azure SQL Managed Instance) and select an existing virtual network or create a new one to host your DMS instance.
  3. 创建 DMS 实例后,创建一个新的迁移项目,将源服务器类型指定为“SQL Server”,并将目标服务器类型指定为“Azure SQL 数据库托管实例”。After creating your DMS instance, create a new migration project and specify the source server type as SQL Server and the target server type as Azure SQL Database Managed Instance. 在项目创建边栏选项卡中选择活动类型 - 在线或离线数据迁移。Choose the type of activity in the project creation blade - online or offline data migration.
  4. 在“迁移源”详细信息页上指定源 SQL Server 详细信息,在“迁移目标”详细信息页上指定目标 Azure SQL 托管实例详细信息 。Specify the source SQL Server details on the Migration source details page and the target Azure SQL Managed Instance details on the Migration target details page. 选择“下一页”。Select Next.
  5. 选择要迁移的数据库。Choose the database you want to migrate.
  6. 提供配置设置以指定包含数据库备份文件的 SMB 网络共享。Provide configuration settings to specify the SMB Network Share that contains your database backup files. 将 Windows 用户凭据用于可访问网络共享的 DMS。Use Windows User credentials with DMS that can access the network share. 提供 Azure 存储帐户详细信息。Provide your Azure Storage account details.
  7. 查看迁移摘要,然后选择“运行迁移”。Review the migration summary, and choose Run migration. 然后,你可以监视迁移活动,并检查数据库迁移进度。You can then monitor the migration activity and check the progress of your database migration.
  8. 还原数据库后,选择“启动直接转换”。After database is restored, choose Start cutover. 若在 SMB 网络共享中提供了结尾日志备份并将其还原到目标位置,迁移过程就会复制该结尾日志备份。The migration process copies the tail-log backup once you make it available in the SMB network share and restore it on the target.
  9. 停止进入源数据库的所有传入流量,并将连接字符串更新为新的 Azure SQL 托管实例数据库。Stop all incoming traffic to your source database and update the connection string to the new Azure SQL Managed Instance database.

有关此迁移选项的详细分步教程,请参阅使用 DMS 在线将 SQL Server 迁移到 Azure SQL 托管实例For a detailed step-by-step tutorial of this migration option, see Migrate SQL Server to an Azure SQL Managed Instance online using DMS.

备份和还原Backup and restore

可让 Azure SQL 托管实例实现快速轻松的数据库迁移的关键功能之一是对存储在 Azure 存储上的数据库备份 (.bak) 文件进行本机还原。One of the key capabilities of Azure SQL Managed Instance to enable quick and easy database migration is the native restore of database backup (.bak) files stored on on Azure Storage. 备份和还原是基于数据库大小的异步操作。Backup and restore is an asynchronous operation based on the size of your database.

下图高度概括了该过程:The following diagram provides a high-level overview of the process:

此图显示了 SQL Server 使用标记为“备份/上传到 URL”箭头指向 Azure 存储,以及标记为“从 URL 还原”的第二个箭头从 Azure 存储指向 SQL 的托管实例。

备注

进行备份、将其上传到 Azure 存储以及对 Azure SQL 托管实例执行本机还原操作所花的时间取决于数据库的大小。The time to take the backup, upload it to Azure storage, and perform a native restore operation to Azure SQL Managed Instance is based on the size of the database. 请为针对大数据库的操作预留足够的停机时间。Factor a sufficient downtime to accommodate the operation for large databases.

要使用备份和还原进行迁移,请执行以下步骤:To migrate using backup and restore, follow these steps:

  1. 将数据库备份到 Azure blob 存储。Back up your database to Azure blob storage. 例如,在 SQL Server Management Studio 中使用备份到 URLFor example, use backup to url in SQL Server Management Studio. 使用 Microsoft Azure Tools 支持早于 SQL Server 2012 SP1 CU2 的数据库。Use the Microsoft Azure Tool to support databases earlier than SQL Server 2012 SP1 CU2.

  2. 使用 SQL Server Management Studio 连接到 Azure SQL 托管实例。Connect to your Azure SQL Managed Instance using SQL Server Management Studio.

  3. 使用共享访问签名创建凭据,以通过数据库备份访问 Azure Blob 存储帐户。Create a credential using a Shared Access Signature to access your Azure Blob storage account with your database backups. 例如:For example:

    CREATE CREDENTIAL [https://mitutorials.blob.core.chinacloudapi.cn/databases]
    WITH IDENTITY = 'SHARED ACCESS SIGNATURE'
    , SECRET = 'sv=2017-11-09&ss=bfqt&srt=sco&sp=rwdlacup&se=2028-09-06T02:52:55Z&st=2018-09-04T18:52:55Z&spr=https&sig=WOTiM%2FS4GVF%2FEEs9DGQR9Im0W%2BwndxW2CQ7%2B5fHd7Is%3D'
    
  4. 从 Azure 存储 blob 容器还原备份。Restore the backup from the Azure storage blob container. 例如:For example:

    RESTORE DATABASE [TargetDatabaseName] FROM URL =
     'https://mitutorials.blob.core.chinacloudapi.cn/databases/WideWorldImporters-Standard.bak'
    
  5. 还原完成后,请在 SQL Server Management Studio 的“对象资源管理器”中查看数据库。Once restore completes, view the database in Object Explorer within SQL Server Management Studio.

若要详细了解此迁移选项,请参阅使用 SSMS 将数据库还原到 Azure SQL 托管实例To learn more about this migration option, see Restore a database to Azure SQL Managed Instance with SSMS.

备注

数据库还原操作是异步且可重试的。A database restore operation is asynchronous and retryable. 如果连接中断或某些超时过期,SQL Server Management Studio 中可能会显示错误。You might get an error in SQL Server Management Studio if the connection breaks or a time-out expires. Azure SQL 数据库将在后台继续尝试还原数据库,可以使用 sys.dm_exec_requestssys.dm_operation_status 视图来跟踪还原进度。Azure SQL Database will keep trying to restore database in the background, and you can track the progress of the restore using the sys.dm_exec_requests and sys.dm_operation_status views.

数据同步和直接转换Data sync and cutover

当使用将数据更改持续从源复制/同步到目标的迁移选项时,源数据和架构可能会变化并偏离目标。When using migration options that continuously replicate / sync data changes from source to the target, the source data and schema can change and drift from the target. 在数据同步过程中,请确保在迁移过程中捕获对源的所有更改并将其应用到目标。During data sync, ensure that all changes on the source are captured and applied to the target during the migration process.

验证源和目标上的数据是否相同后,可以从源环境直接转换到目标环境。After you verify that data is the same on both source and target, you can cutover from the source to the target environment. 请务必与业务/应用程序团队一起规划直接转换过程,以确保在直接转换过程中的最小中断不会影响业务连续性。It is important to plan the cutover process with business / application teams to ensure minimal interruption during cutover does not affect business continuity.

重要

有关与使用 DMS 进行迁移时执行直接转换相关的特定步骤的详细信息,请参阅执行直接转换迁移For details on the specific steps associated with performing a cutover as part of migrations using DMS, see Performing migration cutover.

迁移后Post-migration

成功完成迁移阶段后,执行一系列的迁移后任务,确保一切顺利高效地运行。After you have successfully completed the migration stage, go through a series of post-migration tasks to ensure that everything is functioning smoothly and efficiently.

迁移后阶段对于协调任何数据准确性问题、验证完整性以及解决工作负载的性能问题至关重要。The post-migration phase is crucial for reconciling any data accuracy issues and verifying completeness, as well as addressing performance issues with the workload.

修正应用程序Remediate applications

将数据迁移到目标环境后,以前使用源的所有应用程序都需要开始使用目标。After the data is migrated to the target environment, all the applications that formerly consumed the source need to start consuming the target. 在某些情况下,实现这一点需要对应用程序进行更改。Accomplishing this will, in some cases, require changes to the applications.

执行测试Perform tests

数据库迁移的测试方法包括以下活动:The test approach for database migration consists of the following activities:

  1. 开发验证测试:要测试数据库迁移,需要使用 SQL 查询。Develop validation tests: To test database migration, you need to use SQL queries. 必须创建针对源数据库和目标数据库运行的验证查询。You must create the validation queries to run against both the source and the target databases. 验证查询应涵盖已定义的范围。Your validation queries should cover the scope you have defined.
  2. 设置测试环境:测试环境应包含源数据库和目标数据库的副本。Set up test environment: The test environment should contain a copy of the source database and the target database. 请确保隔离测试环境。Be sure to isolate the test environment.
  3. 运行验证测试:针对源和目标运行验证测试,然后分析结果。Run validation tests: Run the validation tests against the source and the target, and then analyze the results.
  4. 运行性能测试:针对源和目标运行性能测试,然后分析和比较结果。Run performance tests: Run performance test against the source and the target, and then analyze and compare the results.

利用高级功能Leverage advanced features

请确保充分利用 SQL 托管实例提供的基于云的高级功能,例如内置高可用性威胁检测以及监视和优化工作负载Be sure to take advantage of the advanced cloud-based features offered by SQL Managed Instance, such as built-in high availability, threat detection, and monitoring and tuning your workload.

只有将数据库兼容性级别更改为最新的兼容性级别 (150) 后,某些 SQL Server 功能才可用。Some SQL Server features are only available once the database compatibility level is changed to the latest compatibility level (150).

后续步骤Next steps