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 database from a backup file. You'll see two ways to restore the database in SSMS:
- A restore wizard
- T-SQL statements
Note
- For more information on migration using Azure Database Migration Service, see Tutorial: Migrate SQL Server to an Azure SQL Managed Instance using Database Migration Service.
- For more information on various migration methods, see SQL Server to Azure SQL Managed Instance Guide.
Prerequisites
This quickstart:
- Uses resources from the Create a managed instance quickstart.
- Requires the latest version of SSMS installed.
- Requires SSMS to connect to SQL Managed Instance. See these quickstarts on how to connect:
- Enable a public endpoint on SQL Managed Instance. This approach is recommended for this quickstart.
- Connect to SQL Managed Instance from an Azure VM.
- Configure a point-to-site connection to SQL Managed Instance from on-premises.
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 pre-configured Blob Storage account.
Open the restore wizard
Open SSMS and connect to your managed instance.
In Object Explorer, right-click the Databases folder of your managed instance, and then select Restore Database to open the restore wizard.
Select the backup source
In the restore wizard, select the ellipsis (...) to select the source of the backup set to restore.
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 that's supported. Select OK.
In Select a Backup File Location, choose from one of three options to provide information about the location of your backup files:
- Select a pre-registered 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.
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.
Browse Azure subscription storage containers
In Connect to a Microsoft Subscription, select Sign in to sign in to your Azure subscription.
Sign in to your Microsoft Account to initiate the session in Azure.
Select the subscription of the storage account that contains the backup files.
Select the storage account that contains the backup files.
Select the blob container that contains the backup files.
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.
Restore the database
Now that you've selected a storage container, you should see the Locate Backup File in Microsoft Azure dialog.
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.
SSMS validates the backup set. This process takes at most a few seconds. The duration depends on the size of the backup set.
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.
The restore process starts. The duration depends on the size of the backup set.
When the restore process finishes, a dialog shows that it was successful. Select OK.
In Object Explorer, check the restored database.
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 pre-configured Blob Storage account.
Open SSMS and connect to your managed instance.
In Object Explorer, right-click your managed instance and select New Query to open a new query window.
Run the following T-SQL statement, which uses a pre-configured storage account and a shared access signature key to create a credential in your managed instance.
Important
CREDENTIAL
must match the container path, begin withhttps
, and can't contain a trailing forward slash.IDENTITY
must beSHARED ACCESS SIGNATURE
.SECRET
must be the shared access signature token and can't contain a leading?
.
CREATE CREDENTIAL [https://mitutorials.blob.core.windows.net/databases] WITH IDENTITY = 'SHARED ACCESS SIGNATURE' , SECRET = 'sv=...'
To check your credential, run the following statement, which uses a container URL to get a backup file list.
RESTORE FILELISTONLY FROM URL = 'https://mitutorials.blob.core.windows.net/databases/WideWorldImporters-Standard.bak'
Run the following statement to restore the Wide World Importers database.
RESTORE DATABASE [Wide World Importers] FROM URL = 'https://mitutorials.blob.core.windows.net/databases/WideWorldImporters-Standard.bak'
If the restore process is terminated with the message ID 22003, create a new backup file that contains backup checksums, and start the restore process again. See Enable or disable backup checksums during backup or restore.
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')
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.
Next steps
- For information about troubleshooting a backup to a URL, see SQL Server Backup to URL best practices and troubleshooting.
- For an overview of app connection options, see Connect your applications to SQL Managed Instance.
- To query by using your favorite tools or languages, see Quickstarts: Azure SQL Database connect and query.
Feedback
Submit and view feedback for