我的Azure sql server中有两个不同的数据库,并且两者都配置了长期备份。
我想从恢复服务保险库中删除备份只有一个,但即使我编码检查该名称(名称中带有“xxx”),它也删除了其他数据库的备份(“ YYY“)。
现在,在其他数据库(“yyy”)的门户中,当我转到数据库/ restore / long-term / AzureVaultBackups刀片时,它显示“TemplateBladeVirtualPart”“SQLAZUREEXTENTION”。
如果我尝试在Sql Server /长期备份保留刀片中为“yyy”重新设置备份(在门户中),它永远不会分配策略(它也不会显示错误)。但是,我可以为“xxx”重新分配备份。以下是删除备份的代码:
$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $recoveryServiceVaultName
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
$containers = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureSQL -FriendlyName $vault.Name
ForEach ($container in $containers)
{
$items = Get-AzureRmRecoveryServicesBackupItem -container $container -WorkloadType AzureSQLDatabase
ForEach ($item in $items)
{
if ($item.name -like "*xxx*") {
write-host "Item is systemstore"
$item
# Remove the backups from the vault
###################################
Disable-AzureRmRecoveryServicesBackupProtection -item $item -ea SilentlyContinue
}
}
Unregister-AzureRmRecoveryServicesBackupContainer -Container $container
}
我还试图通过代码将长期备份重新分配给“yyy”数据库,但它在“set-AzureRMSqlDatabaseBackupLongTermRetentionPolicy
”命令上失败,错误为“BadRequest:服务器和recoveryServicesVault应该是在相同的订阅和资源组“(他们已经是)。
我的问题是:
set-AzureRMSqlDatabaseBackupLongTermRetentionPolicy
”上收到BadRequest错误?答案 0 :(得分:0)
以下是我用来删除长期备份的内容:
# We need to set recovery services context to work with recovery vault
$vault = Get-AzureRmRecoveryServicesVault -Name '{VaultName}'
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
# Get protection containers to work with those
$containers = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureSQL -Status Registered
foreach ($container in $containers) {
$item = Get-AzureRmRecoveryServicesBackupItem -Container $container -WorkloadType AzureSQLDatabase
# possibly need another iterator here
Disable-AzureRmRecoveryServicesBackupProtection -Item $item -RemoveRecoveryPoints
Unregister-AzureRmRecoveryServicesBackupContainer -Container $container
}