从此处,可使用 SQL Server Management Studio 连接到已还原的数据库,执行所需任务,例如从恢复的数据库中提取一部分数据,复制到现有数据库或删除现有数据库,并将已还原的数据库重命名为现有数据库名。 请参阅时间点还原。
查看 LTR 策略
此示例展示了如何列出单个数据库的实例内的 LTR 策略。
# gets the current version of LTR policy for a database
$LTRPolicy = @{
InstanceName = $instanceName
DatabaseName = $dbName
ResourceGroupName = $resourceGroup
}
Get-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy @LTRPolicy
此示例展示了如何列出实例上所有数据库的 LTR 策略。
# gets the current version of LTR policy for all of the databases on an instance
$Databases = Get-AzSqlInstanceDatabase -ResourceGroupName $resourceGroup -InstanceName $instanceName
$LTRParams = @{
InstanceName = $instanceName
ResourceGroupName = $resourceGroup
}
foreach($database in $Databases.Name){
Get-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy @LTRParams -DatabaseName $database
}
清除 LTR 策略
此示例演示如何从数据库中清除 LTR 策略。
# remove the LTR policy from a database
$LTRPolicy = @{
InstanceName = $instanceName
DatabaseName = $dbName
ResourceGroupName = $resourceGroup
RemovePolicy = $true
}
Set-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy @LTRPolicy
查看 LTR 备份
此示例展示了如何列出实例内的 LTR 备份。
$instance = Get-AzSqlInstance -Name $instanceName -ResourceGroupName $resourceGroup
# get the list of all LTR backups in a specific Azure region
# backups are grouped by the logical database id, within each group they are ordered by the timestamp, the earliest backup first
Get-AzSqlInstanceDatabaseLongTermRetentionBackup -Location $instance.Location
# get the list of LTR backups from the Azure region under the given managed instance
$LTRBackupParam = @{
Location = $instance.Location
InstanceName = $instanceName
}
Get-AzSqlInstanceDatabaseLongTermRetentionBackup @LTRBackupParam
# get the LTR backups for a specific database from the Azure region under the given managed instance
$LTRBackupParam = @{
Location = $instance.Location
InstanceName = $instanceName
DatabaseName = $dbName
}
Get-AzSqlInstanceDatabaseLongTermRetentionBackup @LTRBackupParam
# list LTR backups only from live databases (you have option to choose All/Live/Deleted)
$LTRBackupParam = @{
Location = $instance.Location
DatabaseState = 'Live'
}
Get-AzSqlInstanceDatabaseLongTermRetentionBackup @LTRBackupParam
# only list the latest LTR backup for each database
$LTRBackupParam = @{
Location = $instance.Location
InstanceName = $instanceName
OnlyLatestPerDatabase = $true
}
Get-AzSqlInstanceDatabaseLongTermRetentionBackup @LTRBackupParam
从 LTR 备份进行还原
此示例展示了如何从 LTR 备份进行还原。 请注意,此接口没有更改,但是资源 ID 参数现在要求提供 LTR 备份资源 ID。
# restore a specific LTR backup as an P1 database on the instance $instanceName of the resource group $resourceGroup
$LTRBackupParam = @{
Location = $instance.Location
InstanceName = $instanceName
DatabaseName = $dbname
OnlyLatestPerDatabase = $true
}
$ltrBackup = Get-AzSqlInstanceDatabaseLongTermRetentionBackup @LTRBackupParam
$RestoreLTRParam = @{
TargetInstanceName = $instanceName
TargetResourceGroupName = $resourceGroup
TargetInstanceDatabaseName = $dbName
FromLongTermRetentionBackup = $true
ResourceId = $ltrBackup.ResourceId
}
Restore-AzSqlInstanceDatabase @RestoreLTRParam
# remove the earliest backup
# get the LTR backups for a specific database from the Azure region under the given SQL managed instance
$LTRBackupParam = @{
Location = $instance.Location
InstanceName = $instanceName
DatabaseName = $dbName
}
$ltrBackups = Get-AzSqlInstanceDatabaseLongTermRetentionBackup @LTRBackupParam
$ltrBackup = $ltrBackups[0]
Remove-AzSqlInstanceDatabaseLongTermRetentionBackup -ResourceId $ltrBackup.ResourceId