Restore a deleted container or database to the same Azure Cosmos DB account (preview)
Article
APPLIES TO:
NoSQL
MongoDB
Gremlin
Table
The Azure Cosmos DB point-in-time same-account restore feature helps you recover from an accidental deletion of a container or database. This feature restores the deleted database or container to the same, existing account in any region in which backups exist. Continuous backup mode allows you to restore to any point of time within the last 30 days.
Prerequisites
An Azure subscription. If you don't have an Azure subscription, create a free Azure account before you begin.
An Azure Cosmos DB account. You can choose one of the following options for an Azure Cosmos DB account:
Use the Azure portal, the Azure CLI, Azure PowerShell, or an Azure Resource Manager template to restore a deleted container or database in the same, existing account.
Go to your Azure Cosmos DB account, and then go to the Point In Time Restore page.
Note
The restore page in Azure portal is populated only if you have the Microsoft.DocumentDB/locations/restorableDatabaseAccounts/*/read permission. To learn more about this permission, see Backup and restore permissions.
Select the Restore to same account tab.
For Database, enter a search query to filter the event feed for relevant deletion events for a container or a database.
Next, specify Start and End values to create a time window to use to filter deletion events.
Note
The Start filter is limited to at most 30 days before the present date.
Select Refresh to update the list of events for different resource types with your filters applied.
Verify the time, and then select Restore to start restoration of the selected resource that was previously deleted.
Important
No more than three restore operations can be active at any time on the same account. Deleting the source account while a restore operation is in progress might result in the failure of the restore operation.
Note
The event feed displays resources as Not restorable. The feed provides more information about why the resource can't be restored. In most cases, you must restore the parent database before you can restore any of the database's child containers.
After you initiate a restore operation, track the operation by using the notifications area of the Azure portal. The notification provides the status of the resource that's being restored. While restore is in progress, the status of the container is Creating. After the restore operation completes, the status changes to Online.
Use the Azure CLI to restore a deleted container or database. Child containers are also restored.
Important
The cosmosdb-preview extension for Azure CLI version 0.24.0 or later is required to access the in-account restore command. If you do not have the preview version installed, run az extension add --name cosmosdb-preview --version 0.24.0.
az cosmosdb sql restorable-database list \
--instance-id <instance-id-of-account> \
--location <location>
Note
Listing all the restorable database deletion events allows you to choose the right database in a scenario in which the actual time of existence is unknown. If the event feed contains the Delete operation type in its response, then it’s a deleted database, and it can be restored within the same account. The restore time stamp can be set to any time stamp before the deletion time stamp and within the retention window.
az cosmosdb sql restorable-container list \
--instance-id <instance-id-of-account> \
--database-rid <owner-resource-id-of-database> \
--location <location>
Note
Listing all the restorable database deletion events allows you to choose the right container in a scenario in which the actual time of existence is unknown. If the event feed contains the Delete operation type in its response, then it’s a deleted container, and it can be restored within the same account. The restore time stamp can be set to any time stamp before the deletion time stamp and within the retention window.
Use Azure PowerShell to restore a deleted container or database. Child containers and databases are also restored.
Important
The Az.CosmosDB module for Azure PowerShell version 2.0.5-preview or later is required to access the in-account restore cmdlets. If you do not have the preview version installed, run Install-Module -Name Az.CosmosDB -RequiredVersion 2.0.5-preview -AllowPrerelease.
Id : /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/westus/restorableDatabaseAccounts/abcd1234-d1c0-4645-a699-abcd1234
DatabaseAccountInstanceId : abcd1234-d1c0-4645-a699-abcd1234
Location : West US
DatabaseAccountName : deleted-account-1
CreationTime : 8/2/2020 10:23:00 PM
DeletionTime : 8/2/2020 10:26:13 PM
ApiType : Sql
RestorableLocations : {West US, East US}
Note
The account has CreationTime or DeletionTime fields. These fields also exist for regions. These times allow you to choose the correct region and a valid time range to use when you restore a resource.
Listing all the restorable database deletion events allows you to choose the right database in a scenario where the actual time of existence is unknown. If the event feed contains the Delete operation type in its response, then it’s a deleted database and it can be restored within the same account. The restore timestamp can be set to any timestamp before the deletion timestamp and within the retention window.
Listing all the restorable database deletion events allows you allows you to choose the right container in a scenario where the actual time of existence is unknown. If the event feed contains the Delete operation type in its response, then it’s a deleted container and it can be restored within the same account. The restore timestamp can be set to any timestamp before the deletion timestamp and within the retention window.
Initiate a restore operation for a deleted database by using the Restore-AzCosmosDBSqlDatabase cmdlet:
Id : /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/westus/restorableDatabaseAccounts/abcd1234-d1c0-4645-a699-abcd1234
DatabaseAccountInstanceId : abcd1234-d1c0-4645-a699-abcd1234
Location : West US
DatabaseAccountName : deleted-account-1
CreationTime : 8/2/2020 10:23:00 PM
DeletionTime : 8/2/2020 10:26:13 PM
ApiType : Sql
RestorableLocations : {West US, East US}
Note
The account has CreationTime or DeletionTime fields. These fields also exist for regions. These times allow you to choose the correct region and a valid time range to use when you restore a resource.
Id : /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/westus/restorableDatabaseAccounts/abcd1234-d1c0-4645-a699-abcd1234
DatabaseAccountInstanceId : abcd1234-d1c0-4645-a699-abcd1234
Location : West US
DatabaseAccountName : deleted-account-1
CreationTime : 8/2/2020 10:23:00 PM
DeletionTime : 8/2/2020 10:26:13 PM
ApiType : Sql
RestorableLocations : {West US, East US}
Note
The account has CreationTime or DeletionTime fields. These fields also exist for regions. These times allow you to choose the correct region and a valid time range to use when you restore a resource.
Id : /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/westus/restorableDatabaseAccounts/abcd1234-d1c0-4645-a699-abcd1234
DatabaseAccountInstanceId : abcd1234-d1c0-4645-a699-abcd1234
Location : West US
DatabaseAccountName : deleted-account-1
CreationTime : 8/2/2020 10:23:00 PM
DeletionTime : 8/2/2020 10:26:13 PM
ApiType : Sql
RestorableLocations : {West US, East US}
Note
The account has CreationTime or DeletionTime fields. These fields also exist for regions. These times allow you to choose the correct region and a valid time range to use when you restore a resource.
az deployment group create \
--resource-group <resource-group-name> \
--template-file <template-filename>
Track the status of a restore operation
When a point-in-time restore is initiated for a deleted container or database, the operation is identified as an InAccount restore operation on the resource.
To get a list of restore operations for a specific resource, filter the activity log of the account by using the InAccount Restore Deleted search filter and a time filter. The list that's returns includes the UserPrincipalName field, which identifies the user who initiated the restore operation. For more information about how to access activity logs, see Audit point-in-time restore actions.
Currently, to get the activity log of the account, you must use the Azure portal. Use the InAccount Restore Deleted search filter and a time filter.
Currently, to get the activity log of the account, you must use the Azure portal. Use the InAccount Restore Deleted search filter and a time filter.
Currently, to get the activity log of the account, you must use the Azure portal. Use the InAccount Restore Deleted search filter and a time filter.