Azure Cosmos DB Backup and Restore
By: Date: 30/09/2024 Categories: azure Tags:

Azure Cosmos DB automatically does a full backup of your data every 4 hours, and the most recent two backups are retained at all times. This is the default setting, and it comes at no additional cost. You can adjust the default backup interval and retention duration during or after creating an Azure Cosmos DB account. After you configure an account’s backup options, they are applied to all containers within that account. You can change these settings via the Azure Portal, Azure PowerShell, or Azure CLI.

Prerequisites

  • An existing Azure Cosmos DB account.

You can modify the backup options for an existing account

To update an existing Azure Cosmos DB account’s default backup options, follow the instructions below.

  1. Go to Azure portal.
  2. Go to your Azure Cosmos Database account. and open the Backup & Restore pane. Update the backup interval and the backup retention period as required.

Backup Interval – It is the interval at which Azure Cosmos DB attempts to backup your data. Backup is time-consuming and may fail in some cases due to downstream dependencies. Azure Cosmos DB makes its utmost to backup at the specified interval; however, it cannot promise that the backup will be completed within that time frame. You can set this value in hours or minutes. Backup intervals must be less than 1 hour or greater than 24 hours. When you alter this interval, the new interval begins from the time the last backup was taken.

Backup Retention – It represents the time duration during which each backup is kept. It can be configured in hours or days. The minimum retention period cannot be less than two times the backup interval (in hours) or more than 720 hours.

Copies of data retained – By default, you will receive two free backup copies of your data. There is an additional price if you require more than two copies.

Backup storage redundancy – Select the required storage redundancy option. For further information, see Backup Storage Redundancy. If the region where the account is being created permits it, your existing periodic backup mode accounts will automatically have geo-redundant storage enabled. Otherwise, the account will fall back to the highest redundancy option available. You can select additional storage options, such as locally redundant storage, to ensure that the backup is not replicated in another region. Any modifications made to an existing account are only applied to subsequent backups. After updating an existing account’s backup storage redundancy, the changes may take up to twice as long to take effect, and you will lose access to earlier backups instantly.

Note: You must have the Azure Azure Cosmos DB Operator role role assigned at the subscription level to configure backup storage redundancy.

Ref: Modify periodic backup interval and retention period in Azure Cosmos DB

Restore an Azure Cosmos DB account

Azure Cosmos DB allows you to isolate and limit the restore rights for a continuous backup account to a single role or principal. These permissions can be applied at the subscription scope or more granularly at the source account scope as shown in the following image:

Ref: Assign roles for restore using the Azure portal