Migrate to Innovate Summit:
Learn how migrating and modernizing to Azure can boost your business's performance, resilience, and security, enabling you to fully embrace AI.Register now
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
You can use point-in-time restore to create a database that's a copy of a database at a specific, earlier point in time. This article describes how to do a point-in-time restore of a database in Azure SQL Managed Instance.
Point-in-time restore is useful in recovery scenarios, like for an incident that's caused by error or failure, when data doesn't load correctly, or if crucial data is deleted. You can also use it simply to test and audit your database deployment. Azure backup files are kept for 7 to 35 days depending on your database settings.
You can use point-in-time restore to restore a database in these scenarios:
From an existing database
From a deleted database
To the same managed instance or to a different managed instance
To a managed instance in the same subscription or to a managed instance in a different subscription
The following table shows point-in-time restore scenarios for SQL Managed Instance:
Scenario
Azure portal
Azure CLI
PowerShell
Restore an existing database to the same managed instance
Yes
Yes
Yes
Restore an existing database to a different managed instance
Yes
Yes
Yes
Restore a deleted database to the same managed instance
Yes
Yes
Yes
Restore a deleted database to a different managed instance
Yes
Yes
Yes
Restore an existing database to a managed instance in another subscription
Yes
Yes
Yes
Restore a deleted database to a managed instance in another subscription
Yes
Yes
Yes
Permissions
To recover a database, you must be either:
A member of the SQL Server Contributor role or SQL Managed Instance Contributor role (depending on the recovery destination) in the subscription
The subscription owner
To restore database to a different target subscription, if you're not in the SQL Managed Instance Contributor role you should also have the following permissions:
Microsoft.Sql/managedInstances/databases/readBackups/action on the source SQL managed instance.
Microsoft.Sql/managedInstances/crossSubscriptionPITR/action on the target SQL managed instance.
These limitations apply to point-in-time restore in SQL Managed Instance:
You can't use point-in-time restore to recover an entire SQL Managed Instance deployment. Use point-in-time restore only to make a copy of a database that's hosted on SQL Managed Instance.
Limitations in point-in-time restore depend on whether you're restoring your database to a managed instance in the same subscription or to a managed instance in a different subscription.
When service endpoint policies are enabled on Azure SQL Managed Instance, placing a service endpoint policy on a subnet prevents point-in-time restores from instances in different subnets.
Warning
Be aware of the storage size of your managed instance. Depending on the size of the data to be restored, you might run out of storage for your managed instance. If you don't have enough storage space in your managed instance for the restored data, use a different approach.
Restore to the same subscription
If you restore from one managed instance to another managed instance in the same Azure subscription, both managed instances must be in the same region. Currently, cross-region restore isn't supported.
Restore to a different subscription
Restoring a point-in-time restore backup across subscriptions has the following limitations:
Both subscriptions must be in the same region.
Both subscriptions must be in the same tenant.
The subscription type must be either Enterprise Agreement, Cloud Solution Provider, Microsoft Certified Partner, or pay-as-you-go.
You can use the restore action only on the primary instance.
You can only restore a backup from the primary region. Restoring a database from the geo-replicated secondary region is not supported for cross-subscription point-in-time restore.
The user who takes the restore action must either have the SQL Managed Instance Contributor role assignment or have these explicit permissions:
Microsoft.Sql/managedInstances/databases/readBackups/action on the source SQL managed instance.
Microsoft.Sql/managedInstances/crossSubscriptionPITR/action on the target SQL managed instance.
If you bring your own key (BYOK), the key must be present in both subscriptions.
Restore an existing database
You can restore an existing database in the same subscription by using the Azure portal, PowerShell, or the Azure CLI. If you restore to a different instance in the same subscription by using PowerShell or the Azure CLI, be sure to specify the properties for the target SQL Managed Instance resource. The database is restored to the same instance by default.
If you restore to a different subscription, the Create or Update v5.0.2022 API call that underlies the restore action must contain restorePointInTime, crossSubscriptionTargetManagedInstanceId, and either crossSubscriptionSourceDatabaseId or crossSubscriptionRestorableDroppedDatabaseId.
Go to the target SQL Managed Instance where you plan to restore your database to.
On the Overview page, choose + New database to open the Create Azure SQL Managed Database page.
On the Basics tab of the Create Azure SQL Managed Database page, provide subscription and resource group details under Project details. Then, under Database details provide the new name of the database you plan to restore. Confirm the correct managed instance is listed in the drop down. Then select Next: Data source >
On the Data source tab, choose Point-in-time restore under Use existing data. Provide the subscription, resource group and managed instance that contains the source database. From the Managed database drop-down, choose the database you want to restore, and then choose the point in time you want to restore the database from. The source and target instance can be the same, or two different instances. Select Next : Additional settings >
On the Additional settings tab, you can check the box to inherit the retention policy from the source database, or, alternatively, you can select Configure retention to open the Configure policies page, and set your desired retention policies for your restored database. When finished, select Review + create.
On Review + create, when validation is successful, select Create to restore your database.
This action starts the restore process, which creates a new database and populates it with data from the original database at the specified point in time. For more information about the recovery process, see Recovery time.
Run one of the following code options with your values substituted for the parameters.
To restore the database to the same managed instance:
PowerShell
$subscriptionId = "<subscription ID>"$resourceGroupName = "<resource group name>"$managedInstanceName = "<managed instance name>"$databaseName = "<source database>"$pointInTime = "2018-06-27T08:51:39.3882806Z"$targetDatabase = "<name of the new database to create>"Get-AzSubscription -SubscriptionId$subscriptionIdSelect-AzSubscription -SubscriptionId$subscriptionIdRestore-AzSqlInstanceDatabase -FromPointInTimeBackup `
-ResourceGroupName$resourceGroupName `
-InstanceName$managedInstanceName `
-Name$databaseName `
-PointInTime$pointInTime `
-TargetInstanceDatabaseName$targetDatabase `
To restore the database to another managed instance, also specify the names of the target resource group and the target managed instance:
PowerShell
$targetResourceGroupName = "<resource group of the target managed instance>"$targetInstanceName = "<name of the target managed instance>"Restore-AzSqlInstanceDatabase -FromPointInTimeBackup `
-ResourceGroupName$resourceGroupName `
-InstanceName$managedInstanceName `
-Name$databaseName `
-PointInTime$pointInTime `
-TargetInstanceDatabaseName$targetDatabase `
-TargetResourceGroupName$targetResourceGroupName `
-TargetInstanceName$targetInstanceName
To restore the database to another subscription, set the context to the target subscription (Set-AzContext) and be sure to provide a value for the required parameter -TargetSubscriptionID:
To restore the database to another subscription, set the context to the target subscription (Set-AzContext) and be sure to provide values for the required parameters -TargetSubscriptionID, and -DeleteDate:
To restore a deleted database to another subscription, be sure to set the context (az account set) to the target subscription and specify the -s parameter for the az sql midb restore command to identify the source subscription:
To overwrite an existing database, you must do the following:
Drop the original database that you want to overwrite.
Rename the database restored from the point-in-time to the name of the database you dropped.
Drop the original database
You can drop the database by using the Azure portal, PowerShell, or the Azure CLI.
Another option to drop the database is to connect to your managed instance directly in SQL Server Management Studio (SSMS), and then use the DROP Transact-SQL (T-SQL) command:
SQL
DROPDATABASE WorldWideImporters;
Use one of the following methods to connect to the database in your managed instance:
To delete an existing database from your managed instance, run the following Azure CLI code with your values substituted for the parameters:
Azure CLI
az sql midb delete -g mygroupname --mi myinstancename -n mymanageddbname
Change the new database name to match the original database name
Use SQL Server Management Studio (SSMS) to connect directly to your managed instance. Then run the following T-SQL query. The query changes the name of the restored database to the name of the dropped database you intend to overwrite.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Change point-in-time restore and backup redundancy options for automatic backups in Azure SQL Managed Instance by using the Azure portal, the Azure CLI, Azure PowerShell, and the REST API.
Change point-in-time restore and backup redundancy options for automatic backups in Azure SQL Database by using the Azure portal, the Azure CLI, Azure PowerShell, and the REST API.