Change backup policy in Azure RSV for Azure SQL databases

Chetan Jain 71 Reputation points
2022-05-26T07:23:52.077+00:00

How to change backup policy for Azure SQL Database backup configured in RSV. I know one way but with that, policy has been changed on each database level..
Is there any way we can change for all the databases at one go.

SQL Server on Azure Virtual Machines
Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,135 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Alberto Morillo 32,896 Reputation points MVP
    2022-05-26T10:32:50.54+00:00

    This question has been answered here.

    0 comments No comments

  2. Prrudram-MSFT 22,396 Reputation points
    2022-05-26T11:18:58.773+00:00

    Hello @Chetan Jain ,

    Thank you for reaching out to the Microsoft Q&A platform. Happy to answer your question. We don't have a way to change the policy at one go for all workload items(DBs) from azure portal. Reference: https://learn.microsoft.com/en-us/azure/backup/manage-monitor-sql-database-backup#modify-policy

    I have tried testing through Powershell and below script did the job.

    $vault = Get-AzRecoveryServicesVault -Name <VaultName> -ResourceGroupName <RG Name of the Vault>
    $pols = Get-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -WorkloadType MSSQL -BackupManagementType AzureWorkload
    $targetPolicy = Get-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -Name <Target Policy Name>

    $containers = Get-AzRecoveryServicesBackupContainer -VaultId $vault.ID -ContainerType AzureVMAppContainer
    $bkpItems = Get-AzRecoveryServicesBackupItem -WorkloadType MSSQL -VaultId $vault.ID -Container $container
    foreach($container in $containers) {
    $bkpItems = Get-AzRecoveryServicesBackupItem -WorkloadType MSSQL -VaultId $vault.ID -Container $container
    foreach($bkpItem in $bkpItems) {
    Enable-AzRecoveryServicesBackupProtection -Item $bkpItem -Policy $targetPolicy -VaultId $vault.ID
    }
    }

    205834-image.png

    Note: It would be taking time to complete reconfiguring all the items since there is no parallelism However, at least it would not require the users make changes manually for each and every DB.

    Edit:
    And please note that this one will fetch all the protected servers configured with SQL backups in the vault and will change the policy for all the SQL instances in each of those servers..

    So, if the user wants to change the policy for DBs in a selected server, then the user would have to edit the script and replace the line starting with

    $containers = with the below information:$containers = Get-AzRecoveryServicesBackupContainer -VaultId $vault.ID -ContainerType AzureVMAppContainer | ?{$_.Name -eq "VMAppContainer;Compute;<RG Name of the SQL VM>;<VM Name>"}

    Reference: https://learn.microsoft.com/en-us/azure/backup/backup-azure-vms-automation#change-policy-for-backup-items

    Please "Accept as Answer" and Upvote if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.

    0 comments No comments