Skip to content

Commit 1a77085

Browse files
Merge pull request #35769 from WilliamDAssafMSFT/20251106-backup-immutability-azure-cli
20251106 add Azure CLI
2 parents 78390a4 + 57e1d6e commit 1a77085

2 files changed

Lines changed: 74 additions & 10 deletions

File tree

azure-sql/database/backup-immutability-legal-hold.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to configure legal hold backup immutability for long-term
55
author: WilliamDAssafMSFT
66
ms.author: wiassaf
77
ms.reviewer: dinethi
8-
ms.date: 09/29/2025
8+
ms.date: 11/06/2025
99
ms.service: azure-sql-database
1010
ms.subservice: backup-restore
1111
ms.topic: how-to
@@ -35,7 +35,7 @@ For permissions to view, managed, and delete LTR backups, see [Manage Azure SQL
3535

3636
## Enable legal hold immutability for existing LTR backups
3737

38-
You can enable legal hold immutability on any existing backups. These backups are protected from any edits or deletes until the legal hold is explicitly removed.
38+
You can enable legal hold immutability on any existing backups in the Azure portal, PowerShell, and Azure CLI. These backups are protected from any edits or deletes until the legal hold is explicitly removed.
3939

4040
> [!IMPORTANT]
4141
> Legal hold backup immutability can apply only to existing backups. To make future backups automatically immutable, instead use [time-based immutability](backup-immutability-time-based.md).
@@ -56,19 +56,31 @@ You can enable legal hold immutability on any existing backups. These backups ar
5656

5757
**To enable legal hold backup immutability with PowerShell:**
5858

59+
Replace `<backup name>` with the unique identifier of the desired backup.
60+
5961
```powershell
6062
Set-AzSqlDatabaseLongTermRetentionBackupLegalHold
6163
-Location southeastasia
6264
-ServerName myAzureSQL
6365
-DatabaseName mysqldb
64-
-BackupName 'myLTRbackup-1-24'
66+
-BackupName '<backup name>'
67+
```
68+
69+
#### [Azure CLI](#tab/azure-cli)
70+
71+
**To enable legal hold backup immutability with the Azure CLI:**
72+
73+
Replace `<backup name>` with the unique identifier of the desired backup.
74+
75+
```azurecli
76+
az sql db ltr-backup set-legal-hold-immutability --resource-group mygroup --location southeastasia --server myserver --database mydb --name "<backup name>"
6577
```
6678

6779
---
6880

6981
## Remove legal hold immutability
7082

71-
Legal hold immutability on specific backups can be disabled as follows:
83+
Legal hold immutability on specific backups can be disabled in the Azure portal, PowerShell, and Azure CLI.
7284

7385
#### [Azure portal](#tab/azure-portal)
7486

@@ -84,12 +96,24 @@ Legal hold immutability on specific backups can be disabled as follows:
8496

8597
**To remove legal hold immutability from a backup with PowerShell:**
8698

99+
Replace `<backup name>` with the unique identifier of the desired backup.
100+
87101
```powershell
88102
Remove-AzSqlDatabaseLongTermRetentionBackupLegalHold
89103
-Location southeastasia
90104
-ServerName myAzureSQL
91105
-DatabaseName mysqldb
92-
-BackupName 'myLTRbackup-1-24'
106+
-BackupName '<backup name>'
107+
```
108+
109+
#### [Azure CLI](#tab/azure-cli)
110+
111+
**To remove legal hold immutability from a backup with the Azure CLI:**
112+
113+
Replace `<backup name>` with the unique identifier of the desired backup.
114+
115+
```azurecli
116+
az sql db ltr-backup remove-legal-hold-immutability --resource-group mygroup --location southeastasia --server myserver --database mydb --name "<backup name>"
93117
```
94118

95119
---

azure-sql/database/backup-immutability-time-based.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to configure time-based backup immutability for long-term
55
author: WilliamDAssafMSFT
66
ms.author: wiassaf
77
ms.reviewer: dinethi
8-
ms.date: 09/29/2025
8+
ms.date: 11/06/2025
99
ms.service: azure-sql-database
1010
ms.subservice: backup-restore
1111
ms.topic: how-to
@@ -38,6 +38,8 @@ For permissions to view, managed, and delete LTR backups, see [Manage Azure SQL
3838
> [!IMPORTANT]
3939
> Only backups taken after enabling and locking the policy will be immutable. To make existing backups immutable, instead use [legal hold immutability](backup-immutability-legal-hold.md).
4040
41+
You can create time-based immutability in the Azure portal, PowerShell, and Azure CLI.
42+
4143
#### [Azure portal](#tab/azure-portal)
4244

4345
**To enable and lock time-based immutability from the Azure portal:**
@@ -69,7 +71,13 @@ Set-AzSqlDatabaseBackupLongTermRetentionPolicy
6971
-TimeBasedImmutabilityMode Locked
7072
```
7173

74+
#### [Azure CLI](#tab/azure-cli)
75+
76+
**To enable and lock time-based immutability with Azure CLI:**
7277

78+
```azurecli
79+
az sql db ltr-policy set --resource-group mygroup --server myserver --name mydb --weekly-retention "P0W" --monthly-retention "P0M" --yearly-retention "P0Y" --tb-immutability Enabled --tb-immutability-mode Locked
80+
```
7381

7482
---
7583

@@ -82,7 +90,7 @@ For backups that have immutability enabled but not locked, there are two options
8290
- Lock the immutability.
8391
- Remove immutability for each backup.
8492

85-
Locking immutability for specific backups can be done as follows:
93+
Locking immutability for specific backups can be done in the Azure portal, PowerShell, and Azure CLI.
8694

8795
#### [Azure portal](#tab/azure-portal)
8896

@@ -101,15 +109,29 @@ Locking immutability for specific backups can be done as follows:
101109
> [!IMPORTANT]
102110
> The command needs to be run independently for each of the LTR backups that have immutability enabled but not locked.
103111
112+
Replace `<backup name>` with the unique identifier of the desired backup.
113+
104114
```powershell
105115
Lock-AzSqlDatabaseLongTermRetentionBackupImmutability
106116
-Location southeastasia
107117
-ServerName myAzureSQL
108118
-DatabaseName mysqldb
109-
-BackupName 'myLTRbackup-1-24'
119+
-BackupName '<backup name>'
110120
-ResourceGroupName testrg
111121
```
112122

123+
#### [Azure CLI](#tab/azure-cli)
124+
125+
**To lock time-based immutability on a backup with the Azure CLI:**
126+
127+
> [!IMPORTANT]
128+
> The command needs to be run independently for each of the LTR backups that have immutability enabled but not locked.
129+
130+
Replace `<backup name>` with the unique identifier of the desired backup.
131+
132+
```azurecli
133+
az sql db ltr-backup lock-time-based-immutability --resource-group mygroup --location southeastasia --server myserver --database mydb --name "<backup name>"
134+
```
113135

114136
---
115137

@@ -131,21 +153,32 @@ For backups that have immutability enabled but not locked, the immutability can
131153

132154
**To remove immutability on a backup with PowerShell:**
133155

156+
Replace `<backup name>` with the unique identifier of the desired backup.
157+
134158
```powershell
135159
Remove-AzSqlDatabaseLongTermRetentionBackupImmutability
136160
-Location southeastasia
137161
-ServerName myAzureSQL
138162
-DatabaseName mysqldb
139-
-BackupName 'myLTRbackup-1-24'
163+
-BackupName '<backup name>'
140164
-ResourceGroupName testrg
141165
```
142166

167+
#### [Azure CLI](#tab/azure-cli)
168+
169+
**To remove immutability on a backup with the Azure CLI:**
170+
171+
Replace `<backup name>` with the unique identifier of the desired backup.
172+
173+
```azurecli
174+
az sql db ltr-backup remove-time-based-immutability --resource-group mygroup --location southeastasia --server myserver --database mydb --name "<backup name>"
175+
```
143176

144177
---
145178

146179
## Disable immutability policy
147180

148-
Immutability can be disabled from the LTR policy configuration page in the Azure portal and PowerShell.
181+
Immutability can be disabled from the LTR policy configuration page in the Azure portal, PowerShell, and Azure CLI.
149182

150183
Once immutability is disabled, any new LTR backups from this point won't be protected from immutability. Any existing LTR backups however, will continue to be immutable, if already locked as immutable.
151184

@@ -173,6 +206,13 @@ Set-AzSqlDatabaseBackupLongTermRetentionPolicy
173206
-TimeBasedImmutability Disabled
174207
```
175208

209+
#### [Azure CLI](#tab/azure-cli)
210+
211+
**To disable a backup immutability policy with the Azure CLI:**
212+
213+
```azurecli
214+
az sql db ltr-policy set --resource-group mygroup --server myserver --name mydb --weekly-retention "P0W" --monthly-retention "P0M" --yearly-retention "P0Y" --tb-immutability disabled
215+
```
176216

177217
---
178218

0 commit comments

Comments
 (0)