Native database backup in Azure SQL Managed Instance
Published Mar 23 2019 06:31 PM 26.2K Views
Microsoft

First published on MSDN on Oct 16, 2017
Azure SQL Managed Instance is a new fully managed PaaS offering in Azure cloud that will be publicly available in the near future. It will expose entire SQL Server Instance, support almost all features available in SQL Server 2017 and combine this with instant scaling and intelligence that is available in Azure PaaS service. Managed Instance will support native BACKUP like SQL Server. In the beginning, only backup to URL/Azure Blob Storage will be supported. In this post you will see how to backup database to Azure Blob Storage using Managed Instance.


Access to Azure Blob Storage


First, you would need to store credentials that would be used to access Azure Blob Storage:

CREATE CREDENTIAL [https://myacc.blob.core.windows.net/testcontainer] 
WITH IDENTITY='SHARED ACCESS SIGNATURE' 
, SECRET = 'sv=2014-02-14&sr=c&sig=GV0T9y%2B9%2F9%2FLEIipmuVee3jvYj4WpvBblo%3D&se=2019-06-01T00%2A%3AZ&sp=rwdl'; 


The name of the credential should be the same as URL of target Azure Blob Storage container. In this case, this is myacc account and testcontainer container stored on the URL: https://myacc.blob.core.windows.net/testcontainer

COPY_ONLY Backup


Once you create a credential, you can backup any database using standard BACKUP T-SQL command:

BACKUP DATABASE tpcc2501 
TO URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501.bak' 
WITH COPY_ONLY 


The only mandatory property is COPY_ONLY. Azure SQL Managed Instance owns the backup chain. This means that you cannot perform database backup that breaks the backup chain. Azure SQL Managed Instance allows you to perform only COPY_ONLY backups.

Stripping backup


Azure Blob Storage block blobs have 200GB size limitation. If your database is bigger than 200GB, you should use stripped backup by providing several URL locations where parts of the backup will be placed:

BACKUP DATABASE tpcc2501 
TO URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-1.bak', 
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-2.bak', 
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-3.bak', 
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-4.bak' 
WITH COPY_ONLY 

This way, every stripe will contain a part of the backup and you will not reach the 200GB limit. You can divide the size of your database with 200GB to find out how many stripes you would need.

MAXTRANSFERSIZE


If you have a big database, it would be good to specify MAXTRANSFERSIZE=4194304 option:

BACKUP DATABASE tpcc2501 
TO URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-1.bak', 
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-2.bak', 
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-3.bak', 
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-4.bak' 
WITH COPY_ONLY, MAXTRANSFERSIZE = 4194304, COMPRESSION 


Dimitri Furman explained why is this option important to backup very large databases .

Also, a good idea would be to use COMPRESSION option to decrease bandwidth between Managed Instance and Azure Blob storage.

You also can specify additional options in the WITH clause such as CHECKSUM or STATS = <number>. Backups can be performed across Azure regions, but it would be good to check are the database and storage account placed within the same region to speedup the backup.

7 Comments
Copper Contributor

Currently this is not supported with TDE encrypted databases, unless you use the BYOK feature. Are there any plans to support COPY_ONLY backups for TDE databases in the future?

 

At the moment we do not have a long-term storage option, as BYOK is still in preview & is easy to break at the moment. 

Microsoft

Stripping backup should be changed to Striping Backup, same with stripped backup should be striped backup

Copper Contributor

How can i restore to managed instance from backup stored in stripped blocks ?

 

Thank you.

Copper Contributor

It is my understanding that these backups can only be RESTOREd into Azure Managed Instance, not (for example) downloaded and restored into an on-prem MSSQL instance or even to an MSSQL server installed in an Azure VM.  That was unexpected based on available documentation.  It would be appropriate to clarify This takes Managed Instance off the table for many of our hybrid requirements. 

Copper Contributor

Yes it would be nice to restore on premises

Microsoft

Just to add, restore is fairly simple.

You need to create public blob storage credential protected with SAS on master database just like above.

Run RESTORE FILELISTONLY statement and check if Managed Instance returns a list of the files in the backup.

And then you can finally restore the database using sample command like below:

 

RESTORE DATABASE tpcc2502

FROM URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-1.bak',
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-2.bak',
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-3.bak',
URL = 'https://myacc.blob.core.windows.net/testcontainer/tpcc2501-4-4.bak'

 

Also regarding restoring on-premises, here is the blog - Lesson Learned #146: Restoring a backup from Azure SQL Managed Instance to OnPremises - Microsoft Te...

Microsoft

Copy-only backup of a database hosted on Azure SQL Managed Instance now can be restored to instance of SQL Server 2022. 

 

https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/restore-database-to-sql-server

Version history
Last update:
‎Nov 09 2020 09:44 AM
Updated by: