View LTR policies
Run the az sql db ltr-policy show command to view the LTR policy for a single database on your server.
az sql db ltr-policy show \
--resource-group mygroup \
--server myserver \
--name mydb
View LTR backups
Use the az sql db ltr-backup list command to list the LTR backups for a database. You can use this command to find the name parameter for use in other commands.
az sql db ltr-backup list \
--location eastus2 \
--server myserver \
--database mydb
Delete LTR backups
Run the az sql db ltr-backup delete command to remove an LTR backup. You can use az sql db ltr-backup list to find the backup name.
az sql db ltr-backup delete \
--location eastus2 \
--server myserver \
--database mydb \
--name "3214b3fb-fba9-43e7-96a3-09e35ffcb336;132292152080000000"
Important
Deleting LTR backup is non-reversible. To delete an LTR backup after the server has been deleted you must have Subscription scope permission. You can set up notifications about each delete in Azure Monitor by filtering for operation 'Deletes a long term retention backup'. The activity log contains information on who and when made the request. See Create activity log alerts for detailed instructions.
Restore from LTR backups
Run the az sql db ltr-backup restore command to restore your database from an LTR backup. You can run az sql db ltr-backup show to get the backup-id.
Create a variable for the backup-id with the command `az sql db ltr-backup show' for future use.
get_backup_id=$(az sql db ltr-backup show
--location eastus2 \
--server myserver \
--database mydb \
--name "3214b3fb-fba9-43e7-96a3-09e35ffcb336;132292152080000000" \
--query 'id' \
--output tsv)
Restore your database from the LTR backup.
az sql db ltr-backup restore \
--dest-database targetdb \
--dest-server myserver \
--dest-resource-group mygroup \
--backup-id $get_backup_id
Important
To restore from an LTR backup after the server or resource group has been deleted, you must have permissions scoped to the server's subscription and that subscription must be active. You must also omit the optional -ResourceGroupName parameter.
Note
From here, you can connect to the restored database using SQL Server Management Studio to perform needed tasks, like database swapping. See point in time restore.
View LTR policies
This example shows how to list the LTR policies within a server.
# get all LTR policies within a server
$ltrPolicies = Get-AzSqlDatabase -ResourceGroupName $resourceGroup -ServerName $serverName | `
Get-AzSqlDatabaseLongTermRetentionPolicy
# get the LTR policy of a specific database
$ltrPolicies = Get-AzSqlDatabaseBackupLongTermRetentionPolicy -ServerName $serverName -DatabaseName $dbName `
-ResourceGroupName $resourceGroup
Clear an LTR policy
This example shows how to clear an LTR policy from a database.
Set-AzSqlDatabaseBackupLongTermRetentionPolicy -ServerName $serverName -DatabaseName $dbName `
-ResourceGroupName $resourceGroup -RemovePolicy
View LTR backups
This example shows how to list the LTR backups within a server.
# 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
$ltrBackups = Get-AzSqlDatabaseLongTermRetentionBackup -Location $server.Location
# get the list of LTR backups from the Azure region under the named server
$ltrBackups = Get-AzSqlDatabaseLongTermRetentionBackup -Location $server.Location -ServerName $serverName
# get the LTR backups for a specific database from the Azure region under the named server
$ltrBackups = Get-AzSqlDatabaseLongTermRetentionBackup -Location $server.Location -ServerName $serverName -DatabaseName $dbName
# list LTR backups only from live databases (you have option to choose All/Live/Deleted)
$ltrBackups = Get-AzSqlDatabaseLongTermRetentionBackup -Location $server.Location -DatabaseState Live
# only list the latest LTR backup for each database
$ltrBackups = Get-AzSqlDatabaseLongTermRetentionBackup -Location $server.Location -ServerName $serverName -OnlyLatestPerDatabase
Delete LTR backups
This example shows how to delete an LTR backup from the list of backups.
# remove the earliest backup
$ltrBackup = $ltrBackups[0]
Remove-AzSqlDatabaseLongTermRetentionBackup -ResourceId $ltrBackup.ResourceId
Important
Deleting LTR backup is non-reversible. To delete an LTR backup after the server has been deleted you must have Subscription scope permission. You can set up notifications about each delete in Azure Monitor by filtering for operation 'Deletes a long term retention backup'. The activity log contains information on who and when made the request. See Create activity log alerts for detailed instructions.
Restore from LTR backups
This example shows how to restore from an LTR backup. Note, this interface did not change but the resource ID parameter now requires the LTR backup resource ID.
# restore a specific LTR backup as an P1 database on the server $serverName of the resource group $resourceGroup
Restore-AzSqlDatabase -FromLongTermRetentionBackup -ResourceId $ltrBackup.ResourceId -ServerName $serverName -ResourceGroupName $resourceGroup `
-TargetDatabaseName $dbName -ServiceObjectiveName P1
Important
To restore from an LTR backup after the server or resource group has been deleted, you must have permissions scoped to the server's subscription and that subscription must be active. You must also omit the optional -ResourceGroupName parameter.
Note
From here, you can connect to the restored database using SQL Server Management Studio to perform needed tasks, such as to extract a bit of data from the restored database to copy into the existing database or to delete the existing database and rename the restored database to the existing database name. See point in time restore.
If you are using LTR backups to meet compliance or other mission-critical requirements, consider conducting periodic recovery drills to verify that LTR backups can be restored, and that the restore results in expected database state.
Limitations
- When restoring from an LTR backup, the read scale property is disabled. To enable, read scale on the restored database, update the database after it has been created.
- You need to specify the target service level objective, when restoring from an LTR backup, which was created when the database was in an elastic pool.
Next steps