This article will talk about the periodic backup policy of the Azure Cosmos DB service offered by Azure cloud. I have already explained the backup options available for Cosmos DB in my last article. I would recommend you read it by accessing the attached link “Understanding Azure Cosmos DB backups” to understand the backup policies of Azure Cosmos DB. Today, I am going to explain one of the backup options Periodic backup, and steps about how to configure it for a cosmos DB account.
Azure Cosmos DB is a fully managed, highly secure, and globally distributed database service that is designed for new-age application development. It offers two backup modes which can be used to keep its databases safe from accidental deletes, and natural or man-made disasters. Periodic backup mode is one of them and the default option for cosmos DB. This backup automatically configures if you will not make any changes specifically for backups during cosmos DB account creation.
Backup executes based on the value set for Backup Interval configuration and by default, it runs every 4 hours interval which can be adjusted as per our requirement. Its backup copies are saved on a separate Azure storage service which can be replicated to other regions to ensure its resiliency. Periodic backup does not allow users to perform data recovery or restore operations. You must raise a support ticket on the Azure portal in case you have to restore or recover any data.
Let’s understand how to configure this backup for a new Azure Cosmos DB account while provisioning it through the Azure portal.
Configure Periodic backup for a new Azure Cosmos DB account
Here, I will provision an Azure Cosmos DB account and will show you how to configure the backup policy settings which will be used for that cosmos DB account.
Log in to the Azure portal. Open Cosmos DB dashboard page. Click on the + Create option to open a new account creation form as it is shown in the below image. Enter the details like subscription, resource group, account name, and location. You can keep the rest of the other settings as it is if you are doing it for learning purposes. If you are provisioning this account for business purposes, then ensure to apply discounts and choose the appropriate capacity mode from the below screen.
Click on Next: Global Distribution button is given at the bottom of this screen or you can directly click on this tab showing near the Basics tab.
Here, I left all settings as it is and decided to go with default configurations. If you want to enable global distribution to replicate data to other regions, then you can do it using this tab. You just need to select the radio button given for option Enable.
Once you have chosen your desired options from the Global Distribution tab then click on the Next button or click on the third tab which is Networking.
Here, I left this setting also as default. You must choose as per your requirement from the below options. Click at the Next: Backup Policy button or directly jump to the Backup Policy tab option.
Now, here we will choose the target backup policy for the Azure Cosmos DB account. We must be ready with a few options which will be needed to configure backups.
- Backup policy – There are 2 options available in this option. As we have to configure a periodic backup option so we will ensure that this backup policy is selected
- Backup interval – Here you need to enter the interval at which the backup will be running. This value cannot be configured as less than 1 hour and greater than 24 hours. If we change its value, then the configured value will be considered since its last backup run to execute the next backup
- Backup retention – This is the period till the backup will be retained. We can configure it in hours or days
- Copies of data retainer – This value will not be manually configured but you can control it by making changes in the backup interval and its retention values
- Backup storage redundancy – Here you can choose the appropriate backup storage resiliency by selecting from any of the 3 options given in the below image
Geo-redundant backup storage
Zone-redundant backup storage
Locally-redundant backup storage
If you don’t want to replicate your backup data to other regions, then you should not choose geo-redundant backup storage and must go with the remaining two options which store backup copies in the same regions. The below image is showing the default values for all the above parameters. You can see backup interval is set as 4 hours and backup retention is showing as 8 hours which makes it to save only 2 copies of backup which is also free of cost. If you require to save more backup copies or to keep backup retention different than the given one, then you must change it from the below image.
Click on the Next: Encryption button to jump to the Encryption tab. Here we will configure encryption to protect the data at rest. I left this with the default option i.e. service managed key
Next, you can create tags suitable to your business requirement by accessing the next tab Tags. Once you have filled all details in all tabs the final step is to validate the details before creating the Azure cosmos DB account. You can hit the Review + create button. The validation process will be initiated and once it will be successful you will get the below screen mentioning validation process is successful. Finally, you can hit the Create button given at bottom of this page to initiate the deployment process.
Once an account will be created, you will get this notified through the Azure portal or notification bar tab. You can click on the Go to resource tab to jump on this cosmos DB account dashboard page. Here, you can click on the Backup & Restore option given under the Settings tab to verify your periodic backup configurations as shown in the below image for this newly created Azure Cosmos DB account. As we had created this account with default settings so we can see backup interval as 4 hours retaining 2 backup copies of data with backup storage redundancy as geo-redundant backup storage.
Modify the Periodic backup configuration of an existing Azure Cosmos DB account
This section will help you understand modifying the periodic backup configuration of the existing Azure Cosmos DB account. You must log in to the Azure portal and jump to the cosmos DB account dashboard page. Here, you can click on the Backup & Restore option given under the Settings tab as I did in the above step to verify the backup configuration details.
I have made changes in the Backup Interval setting of the above screens from 240 minutes to 720 minutes i.e. from 4 hours to 12 hours, it means I have configured to run backups every 12 hours in place of 4 hours which was previously set. Once we change the backup interval, we might need to adjust the backup retention settings as well which is in line with the backup interval setting. We can see 8 hours was set as backup retention considering 4 hours backup retention but when I changed 12 hours as the backup interval then there is an error popup that appeared on the screen which is also shown in the below image. It means, you always need to keep backup retention twice the value of backup interval minimally and not less than that. We have changed the backup interval to 12 hours so backup retention must be minimum of 24 hours.
Now, just to analyze whether the number of backup copies value is depended on backup retention or not I have changed its previous value from 8 hours to 8 days as shown in the below image. Note, I have already changed the backup interval from 4 hours to 12 hours so we can see now, that the number of copies of data retained is 16 with having a backup interval of 12 hours and backup retention of 8 days.
If you don’t want to save that many copies of data then you can adjust the values in the backup interval or retention. I have modified it back to 2 days and now we can see a total of 4 copies of data will be retained for this Azure Cosmos DB account.
Once you made the changes, you can click on submit button to apply the updates. You will get a progress note mentioning “Updating backup policy for this account” text as shown in the below image.
Once changes have been updated successfully, you will get notified on the same screen as shown in the below image. Your new changes have been applied to the desired Azure Cosmos DB account.
You can also modify backup configurations using PowerShell or Azure CLI tools. You need to pass the values for backup interval and backup retention along with the Azure Cosmos DB account name in the below PowerShell and Azure CLI commands. Below is the PowerShell command which you can use and modify details for your account and execute them to modify the periodic backup configuration. You need to change all values which are highlighted in bold letters. You should replace resourceGroupName with your resource group name under which the cosmos DB account is provisioned, accountName is the name of the cosmos DB account name followed by the backup interval and retention values as per your requirement.
Update–AzCosmosDBAccount –ResourceGroupName “resourceGroupName” `
–Name “accountName” `
–BackupIntervalInMinutes 720 `
You can also run the below Azure CLI command to modify these values. You just need to replace the same values which I have suggested in the above command.
az cosmosdb update —resource–group “resourceGroupName” \
—name “accountName” \
—backup–interval 720 \
Today, I have explained how to configure and modify periodic backup for an Azure Cosmos DB account. The periodic backup is the default option for cosmos DB accounts. Modifying backup configurations for periodic backup are done at the cosmos DB account level and not at the database or container level. You should be careful while modifying the backup configuration as it will cost you an additional amount in case you are choosing to retain more than 2 copies of backup data for any cosmos DB account.