快速入门:使用 SSMS 将数据库还原到 Azure SQL 托管实例Quickstart: Restore a database to Azure SQL Managed Instance with SSMS

适用于:是Azure SQL 托管实例 APPLIES TO: yesAzure SQL 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 to Azure SQL Managed Instance.

备注

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

先决条件Prerequisites

本快速入门:This quickstart:

备注

有关使用 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 from a backup file

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

  1. 打开 SSMS 并连接到托管实例。Open SSMS and connect to your managed instance.

  2. 在“对象资源管理器”中,右键单击托管实例,并选择“新建查询”以打开新的查询窗口 。In Object Explorer, 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 the status of your restore.

    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 the sys.dm_operation_status view.

备注

数据库还原操作是异步且可重试的。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. 在还原过程的某些阶段,系统视图中会显示唯一标识符,而不是实际的数据库名称。In some phases of the restore process, you will see a unique identifier instead of the actual database name in the system views. 此处了解 RESTORE 语句行为差异。Learn about RESTORE statement behavior differences here.

后续步骤Next steps