Rediger

Del via


Quickstart: Restore a database to Azure SQL Managed Instance with SSMS

Applies to: Azure SQL Managed Instance

In this quickstart, you'll use SQL Server Management Studio (SSMS) to restore a database from Azure Blob Storage to Azure SQL Managed Instance. The quickstart restores the Wide World Importers sample database from a publicly available backup file using a SAS.

Note

Prerequisites

This quickstart:

Note

For more information on backing up and restoring a SQL Server database by using Blob Storage and a shared access signature key, see SQL Server Backup to URL.

Use the restore wizard to restore from a backup file

In SSMS, take the steps in the following sections to restore the Wide World Importers database to SQL Managed Instance by using the restore wizard. The database backup file is stored in a preconfigured Blob Storage account.

Open the restore wizard

  1. Open SSMS and connect to your SQL managed instance.

  2. In Object Explorer, right-click the Databases folder of your SQL managed instance, and then select Restore Database to open the restore wizard.

    Screenshot of Object Explorer in SSMS. The Databases folder is selected. In its shortcut menu, Restore Database is selected.

Select the backup source

  1. In the restore wizard, select the ellipsis (...) to select the source of the backup set to restore.

    Screenshot of a page in the restore wizard. In the Source section, Device is selected, and the ellipsis is called out.

  2. In Select backup devices, select Add. In Backup media type, URL is the only option that's available because it's the only source type supported. Select OK.

    Screenshot of the Select backup devices dialog. The Add and OK buttons are called out.

  3. In Select a Backup File Location, choose from one of three options to provide information about the location of your backup files:

    • Select a preregistered storage container from the Azure storage container list.
    • Enter a new storage container and a shared access signature. A new SQL credential will be registered for you.
    • Select Add to browse more storage containers from your Azure subscription.

    Screenshot of the Select a Backup File Location dialog. In the Azure storage container section, Add is selected.

    If you select Add, proceed to the next section, Browse Azure subscription storage containers. If you use a different method to provide the location of the backup files, skip to Restore the database.

    To restore the Wide World Importers sample database from publicly accessible read-only storage, provide the value https://mitutorials.blob.core.windows.net/examples/ and for the Shared Access Signature field, provide any value, such as SAS.

    Screenshot of the Select a Backup File Location dialog. The sample WideWorldImporters folder location is specified. Select is boxed in red.

Browse Azure subscription storage containers

Note

These steps aren't necessary to restore the WideWorldImporters sample database from the publicly-accessible read-only Azure blob storage, but are necessary to restore databases from your own Azure blob storage.

  1. In Connect to a Microsoft Subscription, select Sign in to sign in to your Azure subscription.

    Screenshot of the Connect to a Microsoft Subscription dialog. The Sign In button is called out.

  2. Sign in to your Microsoft Account to initiate the session in Azure.

    Screenshot of the Sign in to your account dialog. The Microsoft logo, a sign-in box, and other UI elements are visible.

  3. Select the subscription of the storage account that contains the backup files.

    Screenshot of the Connect to a Microsoft Subscription dialog. Under Select a subscription to use, the down arrow on the list box is called out.

  4. Select the storage account that contains the backup files.

    Screenshot of the Connect to a Microsoft Subscription dialog. The down arrow on the Select Storage Account list box is called out.

  5. Select the blob container that contains the backup files.

    Screenshot of the Connect to a Microsoft Subscription dialog. The down arrow on the Select Blob Container list box is called out.

  6. Enter the expiration date of the shared access policy and select Create Credential. A shared access signature with the correct permissions is created. Select OK.

    Screenshot of the Connect to a Microsoft Subscription dialog. Create Credential, OK, and the Shared Access Policy Expiration box are called out.

Restore the database

Now that you've selected a storage container, you should see the Locate Backup File in Microsoft Azure dialog.

  1. In the left pane, expand the folder structure to show the folder that contains the backup files. In the right pane, select all the backup files that are related to the backup set that you're restoring, and then select OK. For example, the following screenshot shows the publicly accessible read-only blob storage containing the WideWorldImporters sample database.

    Screenshot of the Locate Backup File in Microsoft Azure dialog. The WideWorldImporters-Standard.bak backup file is selected, and the OK button is boxed in red.

    SSMS validates the backup set. This process takes at most a few seconds. The duration depends on the size of the backup set.

  2. If the backup is validated, you need to specify a name for the database that's being restored. By default, under Destination, the Database box contains the name of the backup set database. To change the name, enter a new name for Database. Select OK.

    Screenshot of a page in the restore wizard. In the Destination section, the Database box is called out. The OK button is also called out.

    The restore process starts. The duration depends on the size of the backup set.

    Screenshot of a page in the restore wizard. A progress indicator is called out.

  3. When the restore process finishes, a dialog shows that it was successful. Select OK.

    Screenshot of a dialog over a page in the restore wizard. A message in the dialog indicates that the database was successfully restored.

  4. In Object Explorer, check for the restored database by selecting Refresh.

    Screenshot of Object Explorer. The restored database is called out.

Use T-SQL to restore from a backup file

As an alternative to the restore wizard, you can use T-SQL statements to restore a database. In SSMS, follow these steps to restore the Wide World Importers database to SQL Managed Instance by using T-SQL. The database backup file is stored in a preconfigured Blob Storage account.

  1. Open SSMS and connect to your SQL managed instance.

  2. In Object Explorer, right-click your SQL managed instance and select New Query to open a new query window.

  3. Run the following T-SQL statement, which uses publicly available preconfigured storage container and a shared access signature key to create a credential in your SQL managed instance.

    Important

    • CREDENTIAL must match the container path, begin with https, and can't contain a trailing forward slash.
    • IDENTITY must be SHARED ACCESS SIGNATURE.
    • SECRET must be the shared access signature token and can't contain a leading ?.
    • In this example, SECRET is omitted because the storage account is publicly available. If you use a storage account that isn't publicly available, you must provide a shared access signature token.
    CREATE CREDENTIAL [https://mitutorials.blob.core.windows.net/examples/WideWorldImporters-Standard.bak]
    WITH IDENTITY = 'SHARED ACCESS SIGNATURE';
    

    Screenshot that shows the SSMS Query Editor. The CREATE CREDENTIAL statement is visible, and a message indicates that the query ran successfully.

    The credential path in the previous example provides access to a single file. You can also create a shared access signature token to a folder path, for example:

    CREATE CREDENTIAL [https://<your storage>.blob.core.windows.net/databases/backups/]
    WITH IDENTITY = 'SHARED ACCESS SIGNATURE'
    , SECRET = '<your shared access signature>'; -- omit the leading ?
    
  4. To check your credential is working properly, run the following statement, which uses a URL to get a backup file list.

    RESTORE FILELISTONLY FROM URL = 'https://mitutorials.blob.core.windows.net/examples/WideWorldImporters-Standard.bak';
    

    Screenshot that shows the SSMS Query Editor. The RESTORE FILELISTONLY statement is visible, and the Results tab lists three files.

  5. Run the following statement to restore the example Wide World Importers database.

    RESTORE DATABASE [WideWorldImportersExample] FROM URL =
      'https://mitutorials.blob.core.windows.net/examples/WideWorldImporters-Standard.bak';
    

    Screenshot that shows the SSMS Query Editor. The RESTORE DATABASE statement is visible, and a message indicates that the query ran successfully.

    Tip

    If you receive Error: 3201 or Operating system error 86(The specified network password is not correct.), it is likely because your SAS credential (created in previous steps) is incorrectly created. DROP CREDENTIAL and recreate, review the credential name, identity, and secret.

  6. Run the following statement to track the status of your restore process.

    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 process finishes, view the database in Object Explorer. You can verify that the database is restored by using the sys.dm_operation_status view.

Note

A database restore operation is asynchronous and retryable. You might get an error in SSMS if the connection fails or a time-out expires. SQL Managed Instance keeps trying to restore the database in the background, and you can track the progress of the restore process by using the sys.dm_exec_requests and sys.dm_operation_status views.

In some phases of the restore process, you see a unique identifier instead of the actual database name in the system views. To learn about RESTORE statement behavior differences, see T-SQL differences between SQL Server & Azure SQL Managed Instance.