快速入门:将数据库还原到托管实例Quickstart: Restore a database to a Managed Instance

本快速入门介绍如何使用 SQL Server Management Studio (SSMS) 将某个数据库(Wide World Importers - Standard 备份文件)从 Azure Blob 存储还原到 Azure SQL 数据库托管实例In this quickstart, you'll use SQL Server Management Studio (SSMS) to restore a database (the Wide World Importers - Standard backup file) from Azure Blob storage into an Azure SQL Database Managed Instance.

Note

有关使用 Azure 数据库迁移服务 (DMS) 进行迁移的详细信息,请参阅使用 DMS 进行托管实例迁移For more information on migration using the Azure Database Migration Service (DMS), see Managed Instance migration using DMS. 有关各种迁移方法的详细信息,请参阅将 SQL Server 实例迁移到 Azure SQL 数据库托管实例For more information on various migration methods, see SQL Server instance migration to Azure SQL Database Managed Instance.

先决条件Prerequisites

本快速入门:This quickstart:

Note

有关使用 Azure Blob 存储与共享访问签名 (SAS) 密钥备份和还原 SQL Server 数据库的详细信息,请参阅将 SQL Server 备份到 URLFor more information on backing up and restoring a SQL Server database using Azure Blob storage and a Shared Access Signature (SAS) key, see SQL Server Backup to URL.

从备份文件还原数据库Restore the database from a backup file

在 SSMS 中,遵循以下步骤将 Wide World Importers 数据库还原到托管实例。In SSMS, follow these steps to restore the Wide World Importers database to your Managed Instance. 数据库备份文件存储在预配置的 Azure Blob 存储帐户中。The database backup file is stored in a pre-configured Azure Blob storage account.

  1. 打开 SMSS 并连接到托管实例。Open SMSS and connect to your Managed Instance.

  2. 在左侧菜单中右键单击托管实例,然后选择“新建查询”,打开新的查询窗口。 From the left-hand menu, right-click your Managed Instance and select New Query to open a new query window.

  3. 运行以下 SQL 脚本。该脚本使用预配置的存储帐户和 SAS 密钥在托管实例中创建凭据Run the following SQL script, which uses a pre-configured storage account and SAS key to create a credential in your Managed Instance.

    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. 若要检查凭据,请运行以下脚本。该脚本使用容器 URL 获取备份文件列表。To check your credential, run the following script, which uses a container URL to get a backup file list.

    RESTORE FILELISTONLY FROM URL =
       'https://mitutorials.blob.core.chinacloudapi.cn/databases/WideWorldImporters-Standard.bak'
    

    文件列表

  5. 运行以下脚本,还原 Wide World Importers 数据库。Run the following script to restore the Wide World Importers database.

    RESTORE DATABASE [Wide World Importers] FROM URL =
      'https://mitutorials.blob.core.chinacloudapi.cn/databases/WideWorldImporters-Standard.bak'
    

    还原

  6. 运行以下脚本,跟踪还原的状态。Run the following script to track your restore's status.

    SELECT session_id as SPID, command, a.text AS Query, start_time, percent_complete
       , dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time
    FROM sys.dm_exec_requests r
    CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a
    WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
    
  7. 还原完成后,请在对象资源管理器中查看数据库。When the restore completes, view the database in Object Explorer. 可以使用 sys.dm_operation_status 视图验证是否已完成数据库还原。You can verify that database restore is completed using sys.dm_operation_status view.

Note

数据库还原操作是异步且可重试的。Database restore operation is asynchronous and retriable. 如果连接中断或某些超时过期,SQL Server Management Studio 中可能会显示一些错误。You might get some error is SQL Server Management Studio if connection breaks or some 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 restore using the sys.dm_exec_requests and sys.dm_operation_status views. 在还原过程的某些阶段,系统视图中会显示唯一标识符,而不是实际的数据库名称。In some phases of restore process you will see unique identifier instead of actual database name in the system views. 此处了解 RESTORE 语句行为差异。Learn about RESTORE statement behavior differences here.

后续步骤Next steps