Skip to content

Commit 752d21f

Browse files
authored
Merge pull request #292372 from AbhishekMallick-MS/Dec-24-2024-Blob
Blob backup - Update policy PS command updates
2 parents 6a96453 + 38dcd31 commit 752d21f

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

articles/backup/backup-blobs-storage-account-ps.md

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Back up Azure blobs within a storage account using Azure PowerShell
33
description: Learn how to back up all Azure blobs within a storage account using Azure PowerShell.
44
ms.topic: how-to
55
ms.custom: devx-track-azurepowershell
6-
ms.date: 11/27/2024
6+
ms.date: 12/27/2024
77
author: AbhishekMallick-MS
88
ms.author: v-abhmallick
99
---
@@ -156,7 +156,96 @@ To update the backup instance, run the following cmdlets:
156156

157157
1. Change the policy used for backing up the Azure Blobs by using the [Update-AzDataProtectionBackupInstance](/powershell/module/az.dataprotection/update-azdataprotectionbackupinstance?view=azps-13.0.0&preserve-view=true). Specify the relevant backup item and the new backup policy.
158158

159+
1. Update the policy or the new containers to existing backup items.
159160

160-
## Next steps
161+
1. Create the storage account context by using the `New-AzStorageContext` cmdlet. Provide the `-UseConnectedAccount` parameter so that data operations are performed using your Microsoft Entra credentials. Learn more [about the storage account commands](/azure/storage/blobs/blob-containers-powershell#list-containers).
162+
163+
```azurepowershell
164+
Create a context object using Azure AD credentials
165+
$ctx = New-AzStorageContext -StorageAccountName xxx -UseConnectedAccount
166+
167+
```
168+
169+
1. Retrieve the storage containers using the `Get-AzStorageContainer` cmdlet. To retrieve a single container, provide the `-Name` parameter. To return a list of containers that begins with a given character string, specify a value for the `-Prefix` parameter.
170+
171+
The following example retrieves both an individual container and a list of container resources:
172+
173+
```azurepowershell
174+
175+
176+
# Create variables
177+
$containerName = "individual-container"
178+
$prefixName = "loop-"
179+
180+
# Approach 1: Retrieve an individual container
181+
Get-AzStorageContainer -Name $containerName -Context $ctx
182+
Write-Host
183+
184+
# Approach 2: Retrieve a list of containers
185+
$targetContainers = Get-AzStorageContainer -Context $ctx | Where-Object { $_.Name -match "cont" }
186+
```
187+
188+
The result provides the URI of the blob endpoint and lists the containers retrieved by name and prefix:
189+
190+
```
191+
Storage Account Name: demostorageaccount
192+
193+
Name PublicAccess LastModified IsDeleted VersionId
194+
---- ------------ ------------ --------- ---------
195+
individual-container 11/2/2021 5:52:08 PM +00:00
196+
197+
loop-container1 11/2/2021 12:22:00 AM +00:00
198+
loop-container2 11/2/2021 12:22:00 AM +00:00
199+
200+
loop-container1 11/2/2021 12:22:00 AM +00:00
201+
loop-container2 11/2/2021 12:22:00 AM +00:00
202+
loop-container3 11/2/2021 12:22:00 AM +00:00 True 01D7E7129FDBD7D4
203+
loop-container4 11/2/2021 12:22:00 AM +00:00 True 01D7E8A5EF01C787
204+
```
205+
206+
1. Fetch the backup instance that needs to be updated.
207+
208+
```azurepowershell
209+
C:\Users\dapatil> $instance = Search-AzDataProtectionBackupInstanceInAzGraph -Subscription "Demosub" -ResourceGroup Demo-BCDR-RG -Vault BCDR-BV-EastUS -DatasourceType AzureBlob
210+
PS C:\Users\dapatil> $instance
211+
Output
212+
Name BackupInstanceName
213+
---- ------------------
214+
blobsa-blobsa-c7325e08-980d-43b2-863f-68feee4fd03c blobsa-blobsa-c7325e08-980d-43b2-863f-68feee4fd03c
215+
blobsavaulted-blobsavaulted-40c36519-f422-45aa-bbeb-3f0eedb440c7 blobsavaulted-blobsavaulted-40c36519-f422-45aa-bbeb-3f0eedb440c7
216+
testdpp-testdpp-ff4254dd-7a70-437b-9a10-8c0d2223d037 testdpp-testdpp-ff4254dd-7a70-437b-9a10-8c0d2223d037
217+
218+
```
219+
220+
1. Fetch the backup policy with the name of vaulted-policy that you want to update in Backup Instance. You can also fetch the new policy that needs to be updated in Backup Instance.
221+
222+
```azurepowershell
223+
$updatePolicy = Get-AzDataProtectionBackupPolicy -SubscriptionId "Demosub" -VaultName BCDR-BV-EastUS -ResourceGroupName Demo-BCDR-RG -name continer-1
224+
```
225+
226+
1. Update the backup instance with new list of container (the existing backed up containers & new containers).
227+
228+
```azurepowershell
229+
PS C:\Users\dapatil> $updateBI = Update-AzDataProtectionBackupInstance -ResourceGroupName Daya-BCDR-RG -VaultName DPBCDR-BV-EastUS -BackupInstanceName $instance[0].Name -SubscriptionId "ef4ab5a7-c2c0-4304-af80-af49f48af3d1" -PolicyId $updatePolicy.id -VaultedBackupContainer $targetContainers.name
230+
231+
232+
PS C:\Users\dapatil> $updateBI.Property.PolicyInfo.PolicyId
233+
/subscriptions/ef4ab5a7-c2c0-4304-af80-af49f48af3d1/resourceGroups/Daya-BCDR-RG/providers/Microsoft.DataProtection/backupVaults/DPBCDR-BV-EastUS/backupPolicies/continerdeltest-1
234+
PS C:\Users\dapatil> $updateBI.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList[0].ContainersList
235+
cont-01
236+
cont-02
237+
cont-03
238+
cont-04
239+
cont-05
240+
cont-06
241+
cont-07
242+
cont-08
243+
cont-09
244+
cont-10
245+
cont-11
246+
```
247+
248+
249+
## Next steps
161250
162251
[Restore Azure blobs using Azure PowerShell](restore-blobs-storage-account-ps.md)

0 commit comments

Comments
 (0)