Azure Cosmos DB Periodic Backup

By:   |   Updated: 2022-03-22   |   Comments   |   Related: > Azure Cosmos DB


Problem

Backups are essential for any database to recover from any accidental issues or other problems that may arise and this holds true for Azure Cosmos DB. In this this tutorial we will answer these questions:

  • What are the backup options for Azure Cosmos DB?
  • How do we configure backups, and what is the default mechanism?
Solution

Periodic Backups in Azure Cosmos DB

Azure Cosmos DB takes backups of your data automatically at regular intervals. It stores these backups in a storage service and replicates them globally to safeguard against regional disasters. Therefore, the data and the database backups are also highly redundant and provide resiliency from regional disasters.

  • Full database backups of Azure Cosmos DB – Every 4 hours (240 minutes)
  • Default Backup retention: Latest two backups (8 hours)

It allows you to change the default periodic backups configurations as below:

  • Backup Frequency
    • Minimum: 1 hour
    • Maximum 24 hours
  • Backup retention:
    • Minimum: 8 hours
    • Maximum: 720 hours

Azure Cosmos DB stores the backup snapshot in the Azure Cosmos DB writer region. If you have a multi-region writer configuration, it uses one of the write regions for storing the backup snapshots. It further replicates the backup snapshot to another region using geo-redundant storage (GRS). You can refer to Azure cross-region replication pairings for all geographies for a list of geo-redundant pairs in the Azure region.

Note: Users cannot access the backup copies directly. If required, you can raise a support request for restoring the required backup.

In the image below, we can see that Azure Cosmos Container has three primary partitions:

  • East US: Read Region
  • West US: Write region
  • East US 2: Read region
Azure Cosmos Containers

Image source: Microsoft docs

Azure takes backups from the current write region, i.e., West US, and replicates it to the secondary paired Azure region.

azure regions with secondary pairs

Azure Cosmos DB does not affect the performance or availability of the database or application. It runs the backup in the background without consuming the provisioned throughput (RU's).

Modify the Azure Cosmos DB backup interval and retention period

Navigate to your Azure Cosmos DB account in the Azure portal and click on Backup and Restore. It shows the default backup interval, retention, and backup storage redundancy.

Azure Cosmos DB backup interval and retention period

Backup Interval: You can modify the backup interval to backup Azure Cosmos DB at a specified interval. Azure tries the backup database at configured intervals; however, it might fail due to downstream dependencies. If we modify the backup interval, it takes effect from the last backup.

Backup retention: Azure Cosmos DB retains two backup copies with a minimum 8 hours interval. Therefore, if you change the backup interval to 1 hour, it retains 8 copies of backups.

Azure Cosmos DB backup interval and retention period

Note: If you configure Azure Cosmos DB to retain more than 2 copies, you will be charged additional storage. It charges you for the additional copies billed as total GB of data in the Azure paired regions.

Once you configure the backup interval and backup retention, click on Save, and it updates the periodic backup configuration.

Azure Cosmos DB backup interval and retention period

Azure Cosmos DB Backup Storage Redundancy

The storage redundancy ensures multiple backup copies to protect you from planned, unplanned events, transient hardware failures, power outages, or natural disasters.

As stated earlier, Azure Cosmos DB uses geo-redundant storage to replicate data to the paired region. However, you can choose the backup storage redundancy as follows.

Geo-redundant backup storage

The geo-redundant backup copies backups to a paired region asynchronously.

Geo-redundant backup storage

Image source: Microsoft docs

Zone-redundant backup storage

It synchronously copies data across three availability zones in the primary region.

Zone-redundant backup storage

Image source: Microsoft docs

Locally-redundant backup storage

The locally redundant storage copies data synchronously three times within a single primary location of the primary region.

Locally-redundant backup storage

Image source: Microsoft docs

You can choose the required backup storage redundancy for the Azure Cosmos DB account. Once you choose the required storage redundancy, it is applied to future backups. The configuration might take up to twice the interval for changes to take effect. Therefore, you should plan the change in backup storage redundancy carefully.

Below, you can see that I changed my backup storage redundancy to Locally-redundant backup storage.

azure cosmos db backup storage redundancy

How to request Azure Cosmos DB data restore from a backup

Azure does not allow access to the Azure Cosmos DB periodic backups. If you need to restore data, you have two options:

Note: Azure support is available for the Standard, Developer, or the higher plans. You can explore Azure support plans for more details.

Keep the following details handy before asking for the Cosmos DB's restoration.

  • Azure subscription ID
  • If you require to restore the entire Azure Cosmos DB account, you need to provide the account name.
  • To restore one or more databases in the Azure Cosmos DB account, provide the old and new database names. Similarly, if you want to restore one or more containers, provide the Cosmos DB account name, container, and database name.
  • We already specified that Azure Cosmos DB has a default 8 hrs. backup retention period. Therefore, you should contact the support teams within 8 hours so that the Azure team can help you with the restore. You should also increase the backup retention period to at least seven days so that support teams have enough time for restoration.
  • You might work in a different time zone, so when requesting a backup restore, always specify the time in Coordinated Universal Time (UTC).

The following screenshot refers to a typical new support request for restoring the Azure Cosmos DB account backups.

azure cosmos db support ticket form

Note: The support team creates a new Azure Cosmos account for the restored data. If you do not specify the account name, it uses the default format – Azure_Cosmos_account_original_name-restored1. The last digit in the name refers to the number of restore attempts. We cannot restore data to an Azure Cosmos DB account created before restoration. Therefore, if you accidentally delete the Cosmos account, do not create it with the same name. Otherwise, the support team won't restore it, and it would be challenging to discover the proper account. The restored Azure Cosmos account uses the same region, provisioned throughput, indexing policy, subscription admin as the original account.

Once the data is restored into the new Cosmos DB account, you can use the following techniques to copy data into the original account:

  • Azure Cosmos DB data migration tool
  • Change feed in the Cosmos DB
  • Azure Data Factory
  • Custom scripts
Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Rajendra Gupta Rajendra Gupta is a Consultant DBA with 14+ years of extensive experience in database administration including large critical OLAP, OLTP, Reporting and SharePoint databases.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips


Article Last Updated: 2022-03-22

Comments For This Article

















get free sql tips
agree to terms