Skip to content

Commit b52f02f

Browse files
committed
added notes about ltr with mi (AzB 1699239)
1 parent 0d75a4f commit b52f02f

3 files changed

+155
-208
lines changed

articles/sql-database/sql-database-long-term-retention.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ If you are using active geo-replication or failover groups as your business cont
7676
Using long term retention with a Azure SQL Database managed instances has the following limitations:
7777

7878
- **Limited public preview** - Only whitelisted subscriptions have access to the LTR feature.
79-
- **PowerShell only** - There is currently no Azure portal support. LTR must be enabled using PowerShell.
79+
- [**PowerShell only**](sql-database-managed-instance-long-term-backup-retention-configure.md) - There is currently no Azure portal support. LTR must be enabled using PowerShell.
8080

8181

8282
## Configure long-term backup retention

articles/sql-database/sql-database-managed-instance-long-term-backup-retention-configure - Copy.md

Lines changed: 0 additions & 207 deletions
This file was deleted.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
title: "Managed instance: Long-term backup retention (PowerShell)
3+
description: "Learn how to store and restore automated backups on separate Azure Blob storage containers for an Azure SQL Database managed instance using PowerShell. "
4+
services: sql-database
5+
ms.service: sql-database
6+
ms.subservice: backup-restore
7+
ms.custom:
8+
ms.devlang:
9+
ms.topic: conceptual
10+
author: anosov1960
11+
ms.author: sashan
12+
ms.reviewer: mathoma, carlrab
13+
manager: craigg
14+
ms.date: 08/21/2019
15+
---
16+
17+
# Manage Azure SQL Database managed instance long-term backup retention (PowerShell)
18+
19+
In Azure SQL Database managed instance, you can configure a [long-term backup retention](sql-database-long-term-retention.md#managed-instance-support) policy (LTR) as a limited public preview feature. This allows you to to automatically retain database backups in separate Azure Blob storage containers for up to 10 years. You can then recover a database using these backups using PowerShell.
20+
21+
[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)]
22+
23+
> [!IMPORTANT]
24+
> The PowerShell Azure Resource Manager module is still supported by Azure SQL Database managed instance, but all future development is for the Az.Sql module. For these cmdlets, see [AzureRM.Sql](https://docs.microsoft.com/powershell/module/AzureRM.Sql/). The arguments for the commands in the Az module and in the AzureRm modules are substantially identical.
25+
26+
The following sections show you how to use PowerShell to configure the long-term backup retention, view backups in Azure SQL storage, and restore from a backup in Azure SQL storage.
27+
28+
## RBAC roles to manage long-term retention
29+
30+
For **Get-AzSqlInstanceDatabaseLongTermRetentionBackup** and **Restore-AzSqlInstanceDatabase**, you will need to have one of the following roles:
31+
32+
- Subscription Owner role or
33+
- SQL Server Contributor role or
34+
- Custom role with the following permissions:
35+
36+
```Microsoft.Sql/locations/longTermRetentionManagedInstanceBackups/read```
37+
```Microsoft.Sql/locations/longTermRetentionManagedInstances/longTermRetentionManagedInstanceBackups/read```
38+
```Microsoft.Sql/locations/longTermRetentionManagedInstances/longTermRetentionDatabases/longTermRetentionManagedInstanceBackups/read``
39+
40+
For **Remove-AzSqlInstanceDatabaseLongTermRetentionBackup**, you will need to have one of the following roles:
41+
42+
- Subscription Owner role or
43+
- Custom role with the following permission:
44+
45+
```Microsoft.Sql/locations/longTermRetentionManagedInstances/longTermRetentionDatabases/longTermRetentionManagedInstanceBackups/delete```
46+
47+
> [!NOTE]
48+
> The SQL Server Contributor role does not have permission to delete LTR backups.
49+
50+
RBAC permissions could be granted in either *subscription* or *resource group* scope. However, to access LTR backups that belong to a dropped server, the permission must be granted in the *subscription* scope of that server.
51+
52+
```Microsoft.Sql/locations/longTermRetentionManagedInstances/longTermRetentionDatabases/longTermRetentionManagedInstanceBackups/delete```
53+
54+
## Create an LTR policy
55+
56+
```powershell
57+
# get the Managed Instance
58+
$subId = "<subscriptionId>"
59+
$instanceName = "<instanceName>"
60+
$resourceGroup = "<resourceGroupName>"
61+
$dbName = "<databaseName>"
62+
63+
Connect-AzAccount
64+
Select-AzSubscription -SubscriptionId $subId
65+
66+
$instance = Get-AzSqlInstance -Name $instanceName -ResourceGroupName $resourceGroup
67+
68+
# create LTR policy with WeeklyRetention = 12 weeks. MonthlyRetention and YearlyRetention = 0 by default.
69+
Set-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy -InstanceName $instanceName `
70+
-DatabaseName $dbName -ResourceGroupName $resourceGroup -WeeklyRetention P12W
71+
72+
# create LTR policy with WeeklyRetention = 12 weeks, YearlyRetention = 5 years and WeekOfYear = 16 (week of April 15). MonthlyRetention = 0 by default.
73+
Set-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy -InstanceName $instanceName `
74+
-DatabaseName $dbName -ResourceGroupName $resourceGroup -WeeklyRetention P12W -YearlyRetention P5Y -WeekOfYear 16
75+
76+
```
77+
78+
## View LTR policies
79+
80+
This example shows how to list the LTR policies within a server
81+
82+
```powershell
83+
# gets the current version of LTR policy for the database
84+
$ltrPolicies = Get-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy -InstanceName $instanceName `
85+
-DatabaseName $dbName -ResourceGroupName $resourceGroup
86+
87+
```
88+
89+
## Clear an LTR policy
90+
91+
This example shows how to clear an LTR policy from a database
92+
93+
```powershell
94+
Set-AzSqlInstanceDatabaseBackupLongTermRetentionPolicy -InstanceName $instanceName `
95+
-DatabaseName $dbName -ResourceGroupName $resourceGroup -RemovePolicy
96+
```
97+
98+
## View LTR backups
99+
100+
This example shows how to list the LTR backups within a server.
101+
102+
```powershell
103+
# get the list of all LTR backups in a specific Azure region
104+
# backups are grouped by the logical database id, within each group they are ordered by the timestamp, the earliest backup first
105+
$ltrBackups = Get-AzSqlInstanceDatabaseLongTermRetentionBackup -Location $instance.Location
106+
107+
# get the list of LTR backups from the Azure region under the given managed instance
108+
$ltrBackups = Get-AzSqlInstanceDatabaseLongTermRetentionBackup -Location $instance.Location -InstanceName $instanceName
109+
110+
# get the LTR backups for a specific database from the Azure region under the given managed instance
111+
$ltrBackups = Get-AzSqlInstanceDatabaseLongTermRetentionBackup -Location $instance.Location -InstanceName $instanceName -DatabaseName $dbName
112+
113+
# list LTR backups only from live databases (you have option to choose All/Live/Deleted)
114+
$ltrBackups = Get-AzSqlInstanceDatabaseLongTermRetentionBackup -Location $instance.Location -DatabaseState Live
115+
116+
# only list the latest LTR backup for each database
117+
$ltrBackups = Get-AzSqlInstanceDatabaseLongTermRetentionBackup -Location $instance.Location -InstanceName $instanceName -OnlyLatestPerDatabase
118+
119+
```
120+
121+
## Delete LTR backups
122+
123+
This example shows how to delete an LTR backup from the list of backups.
124+
125+
```powershell
126+
# remove the earliest backup
127+
$ltrBackup = $ltrBackups[0]
128+
Remove-AzSqlInstanceDatabaseLongTermRetentionBackup -ResourceId $ltrBackup.ResourceId
129+
```
130+
131+
> [!IMPORTANT]
132+
> 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](../azure-monitor/platform/alerts-activity-log.md) for detailed instructions.
133+
134+
## Restore from LTR backups
135+
136+
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.
137+
138+
```powershell
139+
# restore a specific LTR backup as an P1 database on the server $serverName of the resource group $resourceGroup
140+
Restore-AzSqlInstanceDatabase -FromLongTermRetentionBackup -ResourceId $ltrBackup.ResourceId `
141+
-TargetInstanceName $instanceName -TargetResourceGroupName $resourceGroup -TargetInstanceDatabaseName $dbName
142+
143+
```
144+
145+
> [!IMPORTANT]
146+
> To restore from an LTR backup after the server 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.
147+
148+
> [!NOTE]
149+
> 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](sql-database-recovery-using-backups.md#point-in-time-restore).
150+
151+
## Next steps
152+
153+
- To learn about service-generated automatic backups, see [automatic backups](sql-database-automated-backups.md)
154+
- To learn about long-term backup retention, see [long-term backup retention](sql-database-long-term-retention.md)

0 commit comments

Comments
 (0)