To create automated daily backups of Azure storage account blobs we can use Azure Backup Vault resource. It is possible to configure operational backups and vaulted backups for Azure storage blobs with the backup vault backup policies and instances. We need to consider the limitations specified for operational backups and the limitations in vaulted backups, specially the limitation of only 100 blob containers are allowed to be backed up for a given Azure storage account. Another issue with vaulted backups is the newly created containers in an Azure storage will not automatically included in the backups. Therefore, the Azure vaulted backups are working well only when you have predefoined set of blob containers in your implementation, that are configured for vaulted backups.
The expectation is to autmatically backup daily or in given interval (daily is the minimum interval possible) as shown below.
Let's explore step by step full configuration with terraform, to setup backup blobs in hot and cool storages.
Here is the terrafrom for setting up two storage accounts and its predefined blob containers.
With above terraform code we are creating to storage accounts and two blob containers in each storage. then the generic storage data protection policies are also setup here.
Next we can setup a backup vault using below terraform code. Ideally you should enable soft delete by setting soft_delete = "On"
As the next step we need to add role "" to backup vault system managed identity in the scope of both storage accounts.
resource "azurerm_role_assignment" "cool_storage_backup_role" { principal_id = azurerm_data_protection_backup_vault.backup_vault.identity[0].principal_id role_definition_name = "Storage Account Backup Contributor" scope = azurerm_storage_account.instancestoragecool.id } resource "azurerm_role_assignment" "hot_storage_backup_role" { principal_id = azurerm_data_protection_backup_vault.backup_vault.identity[0].principal_id role_definition_name = "Storage Account Backup Contributor" scope = azurerm_storage_account.instancestoragehot.id }
Then we can setup backup policies in the backup vault.
# Backup Policy for Blob Storage resource "azurerm_data_protection_backup_policy_blob_storage" "cool_storage_backup_policy" { name = "${azurerm_storage_account.instancestoragecool.name}-blob-policy" vault_id = azurerm_data_protection_backup_vault.backup_vault.id operational_default_retention_duration = "P7D" vault_default_retention_duration = "P30D" time_zone = "W. Europe Standard Time" backup_repeating_time_intervals = ["R/2025-06-23T19:00:00/P1D"] # take backup every day depends_on = [azurerm_role_assignment.cool_storage_backup_role] } resource "azurerm_data_protection_backup_policy_blob_storage" "hot_storage_backup_policy" { name = "${azurerm_storage_account.instancestoragehot.name}-blob-policy" vault_id = azurerm_data_protection_backup_vault.backup_vault.id operational_default_retention_duration = "P7D" # ISO 8601 Duration: 7 days - operational backup retention days vault_default_retention_duration = "P7D" time_zone = "W. Europe Standard Time" backup_repeating_time_intervals = ["R/2025-06-23T19:00:00/P1D"] # take backup every day depends_on = [azurerm_role_assignment.hot_storage_backup_role] }
# Backup Instance to protect Blob Storage
resource "azurerm_data_protection_backup_instance_blob_storage" "cool_storage_backup_instance" {
name = "${azurerm_storage_account.instancestoragecool.name}-backup-instance"
vault_id = azurerm_data_protection_backup_vault.backup_vault.id
location = azurerm_storage_account.instancestoragecool.location
storage_account_id = azurerm_storage_account.instancestoragecool.id
backup_policy_id = azurerm_data_protection_backup_policy_blob_storage.cool_storage_backup_policy.id
storage_account_container_names = ["images", "videos"]
depends_on = [
azurerm_role_assignment.cool_storage_backup_role,
azurerm_data_protection_backup_policy_blob_storage.cool_storage_backup_policy,
azurerm_storage_container.cool_storage_images,
azurerm_storage_container.cool_storage_videos
]
}
resource "azurerm_data_protection_backup_instance_blob_storage" "hot_storage_backup_instance" {
name = "${azurerm_storage_account.instancestoragehot.name}-backup-instance"
vault_id = azurerm_data_protection_backup_vault.backup_vault.id
location = azurerm_storage_account.instancestoragehot.location
storage_account_id = azurerm_storage_account.instancestoragehot.id
backup_policy_id = azurerm_data_protection_backup_policy_blob_storage.hot_storage_backup_policy.id
storage_account_container_names = ["images", "videos"]
depends_on = [
azurerm_role_assignment.hot_storage_backup_role,
azurerm_data_protection_backup_policy_blob_storage.hot_storage_backup_policy,
azurerm_storage_container.hot_storage_images,
azurerm_storage_container.hot_storage_videos
]
}
If you inspect the storage account data protection tab you can see the backup is configured for the storage.
No comments:
Post a Comment