Skip to content

Commit c2e6147

Browse files
authored
Added vault tier restore and update backup instance for blobs (#24557)
* Added support for vaulted blobs restore and Update-backupInstance. * added update BI test case added ILR test case added deep validate added examples * re-recorded failed tests * re-recorded failed test
1 parent 2f4a496 commit c2e6147

32 files changed

+1621
-1003
lines changed

src/DataProtection/DataProtection.Autorest/Az.DataProtection.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DotNetFrameworkVersion = '4.7.2'
1212
RequiredAssemblies = './bin/Az.DataProtection.private.dll'
1313
FormatsToProcess = './Az.DataProtection.format.ps1xml'
14-
FunctionsToExport = 'Backup-AzDataProtectionBackupInstanceAdhoc', 'Edit-AzDataProtectionPolicyRetentionRuleClientObject', 'Edit-AzDataProtectionPolicyTagClientObject', 'Edit-AzDataProtectionPolicyTriggerClientObject', 'Find-AzDataProtectionRestorableTimeRange', 'Get-AzDataProtectionBackupInstance', 'Get-AzDataProtectionBackupPolicy', 'Get-AzDataProtectionBackupVault', 'Get-AzDataProtectionJob', 'Get-AzDataProtectionOperation', 'Get-AzDataProtectionOperationStatus', 'Get-AzDataProtectionPolicyTemplate', 'Get-AzDataProtectionRecoveryPoint', 'Get-AzDataProtectionResourceGuard', 'Get-AzDataProtectionResourceGuardMapping', 'Get-AzDataProtectionSoftDeletedBackupInstance', 'Initialize-AzDataProtectionBackupInstance', 'Initialize-AzDataProtectionRestoreRequest', 'New-AzDataProtectionBackupConfigurationClientObject', 'New-AzDataProtectionBackupInstance', 'New-AzDataProtectionBackupPolicy', 'New-AzDataProtectionBackupVault', 'New-AzDataProtectionBackupVaultStorageSettingObject', 'New-AzDataProtectionPolicyTagCriteriaClientObject', 'New-AzDataProtectionPolicyTriggerScheduleClientObject', 'New-AzDataProtectionResourceGuard', 'New-AzDataProtectionRestoreConfigurationClientObject', 'New-AzDataProtectionRetentionLifeCycleClientObject', 'Remove-AzDataProtectionBackupInstance', 'Remove-AzDataProtectionBackupPolicy', 'Remove-AzDataProtectionBackupVault', 'Remove-AzDataProtectionResourceGuard', 'Remove-AzDataProtectionResourceGuardMapping', 'Resume-AzDataProtectionBackupInstanceProtection', 'Search-AzDataProtectionBackupInstanceInAzGraph', 'Search-AzDataProtectionBackupVaultInAzGraph', 'Search-AzDataProtectionJobInAzGraph', 'Set-AzDataProtectionMSIPermission', 'Set-AzDataProtectionResourceGuardMapping', 'Start-AzDataProtectionBackupInstanceRestore', 'Stop-AzDataProtectionBackupInstanceProtection', 'Suspend-AzDataProtectionBackupInstanceBackup', 'Sync-AzDataProtectionBackupInstance', 'Test-AzDataProtectionBackupInstanceReadiness', 'Test-AzDataProtectionBackupInstanceRestore', 'Undo-AzDataProtectionBackupInstanceDeletion', 'Unlock-AzDataProtectionResourceGuardOperation', 'Update-AzDataProtectionBackupInstanceAssociatedPolicy', 'Update-AzDataProtectionBackupVault', 'Update-AzDataProtectionResourceGuard', '*'
14+
FunctionsToExport = 'Backup-AzDataProtectionBackupInstanceAdhoc', 'Edit-AzDataProtectionPolicyRetentionRuleClientObject', 'Edit-AzDataProtectionPolicyTagClientObject', 'Edit-AzDataProtectionPolicyTriggerClientObject', 'Find-AzDataProtectionRestorableTimeRange', 'Get-AzDataProtectionBackupInstance', 'Get-AzDataProtectionBackupPolicy', 'Get-AzDataProtectionBackupVault', 'Get-AzDataProtectionJob', 'Get-AzDataProtectionOperation', 'Get-AzDataProtectionOperationStatus', 'Get-AzDataProtectionPolicyTemplate', 'Get-AzDataProtectionRecoveryPoint', 'Get-AzDataProtectionResourceGuard', 'Get-AzDataProtectionResourceGuardMapping', 'Get-AzDataProtectionSoftDeletedBackupInstance', 'Initialize-AzDataProtectionBackupInstance', 'Initialize-AzDataProtectionRestoreRequest', 'New-AzDataProtectionBackupConfigurationClientObject', 'New-AzDataProtectionBackupInstance', 'New-AzDataProtectionBackupPolicy', 'New-AzDataProtectionBackupVault', 'New-AzDataProtectionBackupVaultStorageSettingObject', 'New-AzDataProtectionPolicyTagCriteriaClientObject', 'New-AzDataProtectionPolicyTriggerScheduleClientObject', 'New-AzDataProtectionResourceGuard', 'New-AzDataProtectionRestoreConfigurationClientObject', 'New-AzDataProtectionRetentionLifeCycleClientObject', 'Remove-AzDataProtectionBackupInstance', 'Remove-AzDataProtectionBackupPolicy', 'Remove-AzDataProtectionBackupVault', 'Remove-AzDataProtectionResourceGuard', 'Remove-AzDataProtectionResourceGuardMapping', 'Resume-AzDataProtectionBackupInstanceProtection', 'Search-AzDataProtectionBackupInstanceInAzGraph', 'Search-AzDataProtectionBackupVaultInAzGraph', 'Search-AzDataProtectionJobInAzGraph', 'Set-AzDataProtectionMSIPermission', 'Set-AzDataProtectionResourceGuardMapping', 'Start-AzDataProtectionBackupInstanceRestore', 'Stop-AzDataProtectionBackupInstanceProtection', 'Suspend-AzDataProtectionBackupInstanceBackup', 'Sync-AzDataProtectionBackupInstance', 'Test-AzDataProtectionBackupInstanceReadiness', 'Test-AzDataProtectionBackupInstanceRestore', 'Undo-AzDataProtectionBackupInstanceDeletion', 'Unlock-AzDataProtectionResourceGuardOperation', 'Update-AzDataProtectionBackupInstance', 'Update-AzDataProtectionBackupInstanceAssociatedPolicy', 'Update-AzDataProtectionBackupVault', 'Update-AzDataProtectionResourceGuard', '*'
1515
AliasesToExport = '*'
1616
PrivateData = @{
1717
PSData = @{

src/DataProtection/DataProtection.Autorest/custom/Cmdlets/Backupcenter/Search-AzDataProtectionBackupVaultInAzGraph.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[Parameter(Mandatory, HelpMessage='Subscription of Vault')]
99
[Alias('SubscriptionId')]
1010
[System.String[]]
11-
${Subscription},
11+
${Subscription}, # TODO: add alias to all ARG command params
1212

1313
[Parameter(Mandatory=$false, HelpMessage='Resource Group of Vault')]
1414
[Alias('ResourceGroupName')]

src/DataProtection/DataProtection.Autorest/custom/Cmdlets/Common/Initialize-AzDataProtectionBackupInstance.ps1 renamed to src/DataProtection/DataProtection.Autorest/custom/Cmdlets/Platform/BackupInstance/Initialize-AzDataProtectionBackupInstance.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Initialize-AzDataProtectionBackupInstance {
4343
[System.String]
4444
${FriendlyName},
4545

46-
[Parameter(Mandatory=$false, HelpMessage='Backup configuration for backup. Use this parameter to configure protection for AzureKubernetesService.')]
46+
[Parameter(Mandatory=$false, HelpMessage='Backup configuration for backup. Use this parameter to configure protection for AzureKubernetesService,AzureBlob.')]
4747
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.IBackupDatasourceParameters]
4848
${BackupConfiguration}
4949
)
@@ -118,7 +118,7 @@ function Initialize-AzDataProtectionBackupInstance {
118118
else{
119119
$errormsg = "Please ensure that secret store based authentication is supported for given data source"
120120
throw $errormsg
121-
}
121+
}
122122
}
123123

124124
$backupInstanceResource = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.BackupInstanceResource]::new()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
3+
function Update-AzDataProtectionBackupInstance
4+
{
5+
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.IBackupInstanceResource')]
6+
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess)]
7+
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Description('Updates a given backup instance')]
8+
9+
param(
10+
[Parameter(Mandatory=$false, HelpMessage='Subscription Id of the vault')]
11+
[System.String]
12+
${SubscriptionId},
13+
14+
[Parameter(Mandatory, HelpMessage='Resource Group of the backup vault')]
15+
[System.String]
16+
${ResourceGroupName},
17+
18+
[Parameter(Mandatory, HelpMessage='Name of the backup vault')]
19+
[System.String]
20+
${VaultName},
21+
22+
[Parameter(Mandatory, HelpMessage='Unique Name of protected backup instance')]
23+
[System.String]
24+
${BackupInstanceName},
25+
26+
[Parameter(Mandatory=$false, HelpMessage='Id of the Policy to be associated with the backup instance')]
27+
[System.String]
28+
${PolicyId},
29+
30+
[Parameter(Mandatory=$false, HelpMessage='List of containers to be backed up inside the VaultStore. Use this parameter for DatasourceType AzureBlob.')]
31+
[System.String[]]
32+
${VaultedBackupContainer},
33+
34+
[Parameter()]
35+
[Alias('AzureRMContext', 'AzureCredential')]
36+
[ValidateNotNull()]
37+
[System.Management.Automation.PSObject]
38+
# The credentials, account, tenant, and subscription used for communication with Azure.
39+
${DefaultProfile},
40+
41+
[Parameter(DontShow)]
42+
[System.Management.Automation.SwitchParameter]
43+
# Wait for .NET debugger to attach
44+
${Break},
45+
46+
[Parameter(DontShow)]
47+
[ValidateNotNull()]
48+
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Runtime.SendAsyncStep[]]
49+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
50+
${HttpPipelineAppend},
51+
52+
[Parameter(DontShow)]
53+
[ValidateNotNull()]
54+
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Runtime.SendAsyncStep[]]
55+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
56+
${HttpPipelinePrepend},
57+
58+
[Parameter(DontShow)]
59+
[System.Uri]
60+
# The URI for the proxy server to use
61+
${Proxy},
62+
63+
[Parameter()]
64+
[System.Management.Automation.SwitchParameter]
65+
# Run the command as a job
66+
${AsJob},
67+
68+
[Parameter()]
69+
[System.Management.Automation.SwitchParameter]
70+
# Run the command asynchronously
71+
${NoWait},
72+
73+
[Parameter(DontShow)]
74+
[ValidateNotNull()]
75+
[System.Management.Automation.PSCredential]
76+
# Credentials for a proxy server to use for the remote call
77+
${ProxyCredential},
78+
79+
[Parameter(DontShow)]
80+
[System.Management.Automation.SwitchParameter]
81+
# Use the default credentials for the proxy
82+
${ProxyUseDefaultCredentials}
83+
)
84+
85+
process
86+
{
87+
$hasPolicyId = $PSBoundParameters.Remove("PolicyId")
88+
$hasVaultedBackupContainer = $PSBoundParameters.Remove("VaultedBackupContainer")
89+
90+
$instance = Az.DataProtection\Get-AzDataProtectionBackupInstance @PSBoundParameters
91+
92+
if($hasPolicyId){
93+
$instance.Property.PolicyInfo.PolicyId = $PolicyId
94+
}
95+
96+
$DatasourceType = GetClientDatasourceType -ServiceDatasourceType $instance.Property.DataSourceInfo.Type
97+
# $manifest = LoadManifest -DatasourceType $DatasourceType.ToString()
98+
99+
if($hasVaultedBackupContainer){
100+
101+
if($DatasourceType -ne "AzureBlob"){
102+
$err = "Parameter VaultedBackupContainer isn't supported for given Datasource"
103+
throw $err
104+
}
105+
106+
# exclude containers which start with $ except $web, $root
107+
$unsupportedContainers = $VaultedBackupContainer | Where-Object { $_ -like '$*' -and $_ -ne "`$root" -and $_ -ne "`$web"}
108+
if($unsupportedContainers.Count -gt 0){
109+
$message = "Following containers are not allowed for configure protection with AzureBlob - $unsupportedContainers. Please remove them and try again."
110+
throw $message
111+
}
112+
113+
$datasourceParam = $instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList
114+
115+
if($datasourceParam -ne $null -and $datasourceParam[0].ObjectType -eq "BlobBackupDatasourceParameters"){
116+
$instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList[0].ContainersList = $VaultedBackupContainer
117+
}
118+
elseif($datasourceParam -eq $null){
119+
$backupConfiguration = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.BlobBackupDatasourceParameters]::new()
120+
$backupConfiguration.ObjectType = "BlobBackupDatasourceParameters"
121+
$backupConfiguration.ContainersList = $VaultedBackupContainer
122+
123+
$instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList += @($backupConfiguration)
124+
}
125+
else{
126+
$err = "instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList is not in proper format."
127+
throw $err
128+
}
129+
}
130+
131+
# deep validate for update-BI
132+
$instance.Property.ValidationType = "DeepValidation"
133+
134+
$null = $PSBoundParameters.Remove("BackupInstanceName")
135+
$null = $PSBoundParameters.Add("Name", $instance.Name)
136+
$null = $PSBoundParameters.Add("Parameter", $instance)
137+
Az.DataProtection.Internal\New-AzDataProtectionBackupInstance @PSBoundParameters
138+
}
139+
}

src/DataProtection/DataProtection.Autorest/custom/Cmdlets/Platform/Restore/Initialize-AzDataProtectionRestoreRequest.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@
102102
[Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Container names for Item Level Recovery.')]
103103
[System.String[]]
104104
${ContainersList},
105+
106+
[Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Use this parameter to filter block blobs by prefix in a container for alternate location ILR. When you specify a prefix, only blobs matching that prefix in the container will be restored. Input for this parameter is a hashtable where each key is a container name and each value is an array of string prefixes for that container.')]
107+
[Hashtable]
108+
${PrefixMatch},
105109

106-
[Parameter(ParameterSetName="OriginalLocationILR", Mandatory=$false, HelpMessage='Minimum matching value for Item Level Recovery.')]
110+
[Parameter(ParameterSetName="OriginalLocationILR", Mandatory=$false, HelpMessage='Specify the blob restore start range for PITR. You can use this option to specify the starting range for a subset of blobs in each container to restore. use a forward slash (/) to separate the container name from the blob prefix pattern.')]
107111
# [Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Minimum matching value for Item Level Recovery.')]
108112
[System.String[]]
109113
${FromPrefixPattern},
110114

111-
[Parameter(ParameterSetName="OriginalLocationILR", Mandatory=$false, HelpMessage='Maximum matching value for Item Level Recovery.')]
115+
[Parameter(ParameterSetName="OriginalLocationILR", Mandatory=$false, HelpMessage='Specify the blob restore end range for PITR. You can use this option to specify the ending range for a subset of blobs in each container to restore. use a forward slash (/) to separate the container name from the blob prefix pattern.')]
112116
# [Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Maximum matching value for Item Level Recovery.')]
113117
[System.String[]]
114118
${ToPrefixPattern},
@@ -257,6 +261,7 @@
257261
if($DatasourceType -ne "AzureKubernetesService"){ # TODO: remove Datasource dependency
258262

259263
if(($RecoveryPoint -ne $null) -and ($RecoveryPoint -ne "") -and $ContainersList.length -gt 0){
264+
$hasPrefixMatch = $PSBoundParameters.Remove("PrefixMatch")
260265
for($i = 0; $i -lt $ContainersList.length; $i++){
261266

262267
$restoreCriteria = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.ItemPathBasedRestoreCriteria]::new()
@@ -265,6 +270,14 @@
265270
$restoreCriteria.ItemPath = $ContainersList[$i]
266271
$restoreCriteria.IsPathRelativeToBackupItem = $true
267272

273+
if($hasPrefixMatch){
274+
$pathPrefix = $PrefixMatch[$ContainersList[$i]]
275+
if($pathPrefix -ne $null -and !($pathPrefix -is [Array])){
276+
throw "values for PrefixMatch must be string array for each container"
277+
}
278+
$restoreCriteria.SubItemPathPrefix = $pathPrefix
279+
}
280+
268281
# adding a criteria for each container given
269282
$restoreCriteriaList += ($restoreCriteria)
270283
}

src/DataProtection/DataProtection.Autorest/docs/Az.DataProtection.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ Undeletes a soft deleted backup instance
152152
### [Unlock-AzDataProtectionResourceGuardOperation](Unlock-AzDataProtectionResourceGuardOperation.md)
153153
Unlocks the critical operation which is protected by the resource guard
154154

155+
### [Update-AzDataProtectionBackupInstance](Update-AzDataProtectionBackupInstance.md)
156+
Updates a given backup instance
157+
155158
### [Update-AzDataProtectionBackupInstanceAssociatedPolicy](Update-AzDataProtectionBackupInstanceAssociatedPolicy.md)
156159
Updates associated policy for a given backup instance
157160

src/DataProtection/DataProtection.Autorest/docs/Initialize-AzDataProtectionBackupInstance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This object can now be used to configure backup for the given disk.
4848

4949
### Example 2: Initialize Backup instance object for AzureKubernetesService
5050
```powershell
51-
$policy = Get-AzDataProtectionBackupPolicy -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -VaultName "vaultName" -ResourceGroupName "resourceGroupName" | where {$_.Name -eq "policyName"}
51+
$policy = Get-AzDataProtectionBackupPolicy -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -VaultName "vaultName" -ResourceGroupName "resourceGroupName" | Where-Object {$_.Name -eq "policyName"}
5252
$sourceClusterId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourceGroupName/providers/Microsoft.ContainerService/managedClusters/aks-cluster"
5353
$snapshotResourceGroupId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourceGroupName"
5454
$backupConfig = New-AzDataProtectionBackupConfigurationClientObject -SnapshotVolume $true -IncludeClusterScopeResource $true -DatasourceType AzureKubernetesService -LabelSelector "x=y","foo=bar"
@@ -92,7 +92,7 @@ Similarly use datasourcetype AzureDatabaseForMySQL to initialize backup instance
9292

9393
### -BackupConfiguration
9494
Backup configuration for backup.
95-
Use this parameter to configure protection for AzureKubernetesService.
95+
Use this parameter to configure protection for AzureKubernetesService,AzureBlob.
9696
To construct, see NOTES section for BACKUPCONFIGURATION properties and create a hash table.
9797

9898
```yaml

src/DataProtection/DataProtection.Autorest/docs/Initialize-AzDataProtectionRestoreRequest.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Initialize-AzDataProtectionRestoreRequest -DatasourceType <DatasourceTypes> -Res
2525
```
2626
Initialize-AzDataProtectionRestoreRequest -DatasourceType <DatasourceTypes> -ItemLevelRecovery
2727
-RestoreLocation <String> -RestoreType <RestoreTargetType> -SourceDataStore <DataStoreType>
28-
-TargetResourceId <String> [-ContainersList <String[]>] [-RecoveryPoint <String>]
28+
-TargetResourceId <String> [-ContainersList <String[]>] [-PrefixMatch <Hashtable>] [-RecoveryPoint <String>]
2929
[-RestoreConfiguration <KubernetesClusterRestoreCriteria>] [<CommonParameters>]
3030
```
3131

@@ -250,7 +250,9 @@ Accept wildcard characters: False
250250
```
251251
252252
### -FromPrefixPattern
253-
Minimum matching value for Item Level Recovery.
253+
Specify the blob restore start range for PITR.
254+
You can use this option to specify the starting range for a subset of blobs in each container to restore.
255+
use a forward slash (/) to separate the container name from the blob prefix pattern.
254256
255257
```yaml
256258
Type: System.String[]
@@ -294,6 +296,23 @@ Accept pipeline input: False
294296
Accept wildcard characters: False
295297
```
296298
299+
### -PrefixMatch
300+
Use this parameter to filter block blobs by prefix in a container for alternate location ILR.
301+
When you specify a prefix, only blobs matching that prefix in the container will be restored.
302+
Input for this parameter is a hashtable where each key is a container name and each value is an array of string prefixes for that container.
303+
304+
```yaml
305+
Type: System.Collections.Hashtable
306+
Parameter Sets: AlternateLocationILR
307+
Aliases:
308+
309+
Required: False
310+
Position: Named
311+
Default value: None
312+
Accept pipeline input: False
313+
Accept wildcard characters: False
314+
```
315+
297316
### -RecoveryPoint
298317
Id of the recovery point to be restored.
299318
@@ -482,7 +501,9 @@ Accept wildcard characters: False
482501
```
483502
484503
### -ToPrefixPattern
485-
Maximum matching value for Item Level Recovery.
504+
Specify the blob restore end range for PITR.
505+
You can use this option to specify the ending range for a subset of blobs in each container to restore.
506+
use a forward slash (/) to separate the container name from the blob prefix pattern.
486507
487508
```yaml
488509
Type: System.String[]

0 commit comments

Comments
 (0)