從這裡開始,您可以使用 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
# 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
限制
從已設定 SQL Server 2022 更新原則的執行個體中取得的資料庫備份可以還原至已設定 SQL Server 2022 或一律保持最新的更新原則的執行個體。 從已設定一律保持最新的更新原則的執行個體中取得的資料庫備份只能還原至同時已設定一律保持最新的更新原則的執行個體。