First published on MSDN on Sep 13, 2017
Received a comment saying 'Can't Change the server Recovery Service Vault', took a breathe and start a new Lab on Azure Portal trying to find out how it can be changed, after a lot of tries unfortunately I realized that it can't be done through the portal, so what is our best friend Solution ?...
I decided to try using PowerShell , so this is what I 've done to change the Recovery Service Vault for an already configured LTR for an Azure SQL server .
I have Azure SQL Server "test" which contains 4 Azure DBs with Recovery Service Vault "Test Vault", I want to change the Vault for this server to be "New Vault" and add one of the DBs "testDB" to this Vault ,so find below an explained steps to reach that then the code to execute:
: Things to keep in mind about LTR and Recovery Service Vault.
# Retrieve the default retention policy for the AzureSQLDatabase workload type
$retentionPolicy = Get-AzureRmRecoveryServicesBackupRetentionPolicyObject -WorkloadType AzureSQLDatabase
# Set the retention value to two years (you can set to any time between 1 week and 10 years)
$retentionPolicy.RetentionDurationType = "Weeks"
$retentionPolicy.RetentionCount = 2
$retentionPolicyName = "my2weeksRetentionPolicy"
# Set the vault context to the vault you are creating the policy for
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
# Create the new policy
$policy = New-AzureRmRecoveryServicesBackupProtectionPolicy -name $retentionPolicyName -WorkloadType AzureSQLDatabase -retentionPolicy $retentionPolicy
# Enable long-term retention for a specific SQL database