Azure Cosmos DB Continuous Backups Step By Step
The previous tip, Azure Cosmos DB Periodic backup, covers the default backup mechanism for the Azure Cosmos DB. It takes backups every four hours and retains two recent backups by default. Users do not get access to restore databases with periodic backups. You need to log a support request with restoration details.
In many cases, you cannot afford any data loss. Therefore, some critical applications require continuous data backups for point-in-time recovery. Similarly, you do not want to go to Azure support to request data restoration.
This tip explores how do the continuous backups.
You might require a point-in-time database restore for dealing with issues such as accidental deletion, update, or recovery of the deleted Cosmos DB account, container, or database. Azure Cosmos DB takes continuous backups in every region where the account exists.
In the following image, we have a globally distributed database with write and read regions as below:
- Write region: West US
- Read Regions: East US & East US 2
Image reference: Microsoft docs
Azure stores backups in the locally redundant storage account in every region. If the Azure region has availability zones enabled, the backup gets stored in zone redundant storage accounts.
You can do point-in-time restore within the retention period. The retention period is the lower of the following values:
- Resource creation time
- 30 days in the past from now
Migrate existing Cosmos DB from Periodic to Continuous backups
By default, Azure Cosmos DB uses periodic backup configurations. You can migrate from periodic backups to continuous backups using the Azure portal, CLI, or PowerShell.
Open the Azure Cosmos DB account in the Azure portal and click on features. As shown below, the continuous back is in disabled mode.
Click on the continuous backup and Enable it.
It starts the backup migration. During the migration, the status is changed to Pending. The migration time depends on the data size in the Cosmos account.
As shown below, continuous backup is enabled for my Cosmos DB account.
- The periodic to continuous backup migration can be done at the Cosmos DB account level.
- You cannot switch back to periodic backup because Azure does not allow the reversible operation. It does not roll backup changes even in a failure scenario. Even if you started the migration process and failed, you need to reinitiate it to make it successful.
- During the migration process, you cannot perform the following
- Add or remove regions
- Change backup policy
- Change in throughput
- The migration does not impact the client requests. However, it might have a slight performance impact in a heavy load situation. Therefore, you should plan migration to continuous backup in off-hours.
Create an Azure Cosmos DB account with Continuous backup
We modified the Azure Cosmos DB account earlier and migrated it from periodic to continuous backup. However, we can set this configuration while deploying a new cosmos DB account.
In the Azure portal, go to the Azure Cosmos DB service. It lists the existing accounts as shown below.
Click on the create for a new Cosmos DB account and choose Core (SQL) – Recommended API.
On the basic page, fill in details such as subscription, resource group, Cosmos DB account name, region, and capacity mode. We can use provisioned or serverless throughput mode for continuous backup.
In the next step, we can configure the global database distribution configurations. We can enable the geo-redundancy setting for data to be highly available and durable. However, we cannot use the multi-writer region for the continuous backup.
The networking setting page has a default configuration – All networks suitable for our demo environment. However, it is recommended to use the private endpoint for a production environment.
The next page allows you to configure backup policy from options – Periodic or Continuous. As shown below, the default backup policy mode is Periodic. You may note that you get a few options to configure with the periodic backup policy.
- Backup interval
- Backup retention
- Backup storage redundancy
Let's change the backup policy to Continuous as per our requirement. You cannot choose the backup storage redundancy for continuous backups.
Choose the default service-managed key as a data encryption mechanism on the next page. We cannot use the customer-managed key if we use continuous backups.
Finally, review the configurations for the Azure Cosmos DB account and verify that it uses a continuous backup policy.
Click on the create button to deploy a new Azure Cosmos DB account with the continuous backup policy. As stated earlier, we cannot revert to a periodic backup policy once you create or migrate the Cosmos DB account to continuous backups.
Pricing for the Continuous backups
Azure Cosmos DB charges monthly for storing the backup and restore of your data. The restore cost is incurred every time you initiate a restore. Therefore, if you do not perform any data restore, Azure won't charge you for the restore operations.
You can look at the Azure Cosmos DB pricing calculator to get continuous backup cost per GB. For example, let's say our Azure Cosmos DB account is enabled for continuous data backup in the East US region.
Azure continuous backup runs locally on each region (read or write regions). Therefore, the cost gets multiplied by the number of regions. Therefore the monthly price calculation will be done with the following formula:
- $0.20/GB * Data size(GB's) in Cosmos account * Number of regions
Similarly, the point-in-time data restore from the continuous backup is billed per the primary write region. For the East US write region, the calculation formula is as below:
- $0.15/GB * Data size in GB.
The per GB cost varies as per the Azure region. For example, in Central India, the cost per GB is $0.23 and $0.18 for continuous backup data and point-in-time restore, respectively, as shown below.
Let's say your Cosmos DB account data size is 2 TB with two regions. The monthly cost will be as follows:
- Continuous backup data: 0.23 * 2000 * 2 = $920 per month
- Restore cost: 2000* 0.18= $360 per restore request
Limitations of Azure Cosmos DB continuous backups
- It supports only API for SQL and MongoDB. You cannot use it for Cassandra, Table, or Gremlin APIs.
- It does not support a globally distributed database with multi-region writes.
- You can only restore the account in the source account region. It does not support database restore to an existing account as well.
- You cannot extend the restore window beyond 30 days.
- The Cosmos DB accounts should not use customer-managed keys.
About the author
View all my tips
Article Last Updated: 2022-04-12