Skip to content

Commit

Permalink
Migrate DataProtection from generation to main (Azure#24658)
Browse files Browse the repository at this point in the history
* Move DataProtection to main

* Update ChangeLog.md

---------

Co-authored-by: NanxiangLiu <[email protected]>
  • Loading branch information
azure-powershell-bot and Nickcandy authored Apr 19, 2024
1 parent e220a68 commit 4b94eea
Show file tree
Hide file tree
Showing 186 changed files with 6,257 additions and 1,248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DotNetFrameworkVersion = '4.7.2'
RequiredAssemblies = './bin/Az.DataProtection.private.dll'
FormatsToProcess = './Az.DataProtection.format.ps1xml'
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', '*'
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', '*'
AliasesToExport = '*'
PrivateData = @{
PSData = @{
Expand Down
24 changes: 14 additions & 10 deletions src/DataProtection/DataProtection.Autorest/Az.DataProtection.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,41 @@

# Ask for the shared functionality table
$VTable = Register-AzModule

# Tweaks the pipeline on module load
$instance.OnModuleLoad = $VTable.OnModuleLoad

# Following two delegates are added for telemetry
$instance.GetTelemetryId = $VTable.GetTelemetryId
$instance.Telemetry = $VTable.Telemetry


# Delegate to sanitize the output object
$instance.SanitizeOutput = $VTable.SanitizerHandler

# Delegate to get the telemetry info
$instance.GetTelemetryInfo = $VTable.GetTelemetryInfo

# Tweaks the pipeline per call
$instance.OnNewRequest = $VTable.OnNewRequest

# Gets shared parameter values
$instance.GetParameterValue = $VTable.GetParameterValue

# Allows shared module to listen to events from this module
$instance.EventListener = $VTable.EventListener

# Gets shared argument completers
$instance.ArgumentCompleter = $VTable.ArgumentCompleter

# The name of the currently selected Azure profile
$instance.ProfileName = $VTable.ProfileName


# Load the custom module
$customModulePath = Join-Path $PSScriptRoot './custom/Az.DataProtection.custom.psm1'
if(Test-Path $customModulePath) {
$null = Import-Module -Name $customModulePath
}

# Export nothing to clear implicit exports
Export-ModuleMember

Expand All @@ -97,12 +101,12 @@
# Load the last folder if no profile is selected
$profileDirectory = $directories | Select-Object -Last 1
}

if($profileDirectory) {
Write-Information "Loaded Azure profile '$($profileDirectory.Name)' for module '$($instance.Name)'"
$exportsPath = $profileDirectory.FullName
}

if($exportsPath) {
Get-ChildItem -Path $exportsPath -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
$cmdletNames = Get-ScriptCmdlet -ScriptFolder $exportsPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[Parameter(Mandatory, HelpMessage='Subscription of Vault')]
[Alias('SubscriptionId')]
[System.String[]]
${Subscription},
${Subscription}, # TODO: add alias to all ARG command params

[Parameter(Mandatory=$false, HelpMessage='Resource Group of Vault')]
[Alias('ResourceGroupName')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function Initialize-AzDataProtectionBackupInstance {
[System.String]
${FriendlyName},

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

$backupInstanceResource = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.BackupInstanceResource]::new()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@


function Update-AzDataProtectionBackupInstance
{
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.IBackupInstanceResource')]
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess)]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Description('Updates a given backup instance')]

param(
[Parameter(Mandatory=$false, HelpMessage='Subscription Id of the vault')]
[System.String]
${SubscriptionId},

[Parameter(Mandatory, HelpMessage='Resource Group of the backup vault')]
[System.String]
${ResourceGroupName},

[Parameter(Mandatory, HelpMessage='Name of the backup vault')]
[System.String]
${VaultName},

[Parameter(Mandatory, HelpMessage='Unique Name of protected backup instance')]
[System.String]
${BackupInstanceName},

[Parameter(Mandatory=$false, HelpMessage='Id of the Policy to be associated with the backup instance')]
[System.String]
${PolicyId},

[Parameter(Mandatory=$false, HelpMessage='List of containers to be backed up inside the VaultStore. Use this parameter for DatasourceType AzureBlob.')]
[System.String[]]
${VaultedBackupContainer},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[System.Management.Automation.PSObject]
# The credentials, account, tenant, and subscription used for communication with Azure.
${DefaultProfile},

[Parameter(DontShow)]
[System.Management.Automation.SwitchParameter]
# Wait for .NET debugger to attach
${Break},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be appended to the front of the pipeline
${HttpPipelineAppend},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
${HttpPipelinePrepend},

[Parameter(DontShow)]
[System.Uri]
# The URI for the proxy server to use
${Proxy},

[Parameter()]
[System.Management.Automation.SwitchParameter]
# Run the command as a job
${AsJob},

[Parameter()]
[System.Management.Automation.SwitchParameter]
# Run the command asynchronously
${NoWait},

[Parameter(DontShow)]
[ValidateNotNull()]
[System.Management.Automation.PSCredential]
# Credentials for a proxy server to use for the remote call
${ProxyCredential},

[Parameter(DontShow)]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)

process
{
$hasPolicyId = $PSBoundParameters.Remove("PolicyId")
$hasVaultedBackupContainer = $PSBoundParameters.Remove("VaultedBackupContainer")

$instance = Az.DataProtection\Get-AzDataProtectionBackupInstance @PSBoundParameters

if($hasPolicyId){
$instance.Property.PolicyInfo.PolicyId = $PolicyId
}

$DatasourceType = GetClientDatasourceType -ServiceDatasourceType $instance.Property.DataSourceInfo.Type
# $manifest = LoadManifest -DatasourceType $DatasourceType.ToString()

if($hasVaultedBackupContainer){

if($DatasourceType -ne "AzureBlob"){
$err = "Parameter VaultedBackupContainer isn't supported for given Datasource"
throw $err
}

# exclude containers which start with $ except $web, $root
$unsupportedContainers = $VaultedBackupContainer | Where-Object { $_ -like '$*' -and $_ -ne "`$root" -and $_ -ne "`$web"}
if($unsupportedContainers.Count -gt 0){
$message = "Following containers are not allowed for configure protection with AzureBlob - $unsupportedContainers. Please remove them and try again."
throw $message
}

$datasourceParam = $instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList

if($datasourceParam -ne $null -and $datasourceParam[0].ObjectType -eq "BlobBackupDatasourceParameters"){
$instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList[0].ContainersList = $VaultedBackupContainer
}
elseif($datasourceParam -eq $null){
$backupConfiguration = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20231201.BlobBackupDatasourceParameters]::new()
$backupConfiguration.ObjectType = "BlobBackupDatasourceParameters"
$backupConfiguration.ContainersList = $VaultedBackupContainer

$instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList += @($backupConfiguration)
}
else{
$err = "instance.Property.PolicyInfo.PolicyParameter.BackupDatasourceParametersList is not in proper format."
throw $err
}
}

# deep validate for update-BI
$instance.Property.ValidationType = "DeepValidation"

$null = $PSBoundParameters.Remove("BackupInstanceName")
$null = $PSBoundParameters.Add("Name", $instance.Name)
$null = $PSBoundParameters.Add("Parameter", $instance)
Az.DataProtection.Internal\New-AzDataProtectionBackupInstance @PSBoundParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@
[Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Container names for Item Level Recovery.')]
[System.String[]]
${ContainersList},

[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.')]
[Hashtable]
${PrefixMatch},

[Parameter(ParameterSetName="OriginalLocationILR", Mandatory=$false, HelpMessage='Minimum matching value for Item Level Recovery.')]
[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.')]
# [Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Minimum matching value for Item Level Recovery.')]
[System.String[]]
${FromPrefixPattern},

[Parameter(ParameterSetName="OriginalLocationILR", Mandatory=$false, HelpMessage='Maximum matching value for Item Level Recovery.')]
[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.')]
# [Parameter(ParameterSetName="AlternateLocationILR", Mandatory=$false, HelpMessage='Maximum matching value for Item Level Recovery.')]
[System.String[]]
${ToPrefixPattern},
Expand Down Expand Up @@ -257,6 +261,7 @@
if($DatasourceType -ne "AzureKubernetesService"){ # TODO: remove Datasource dependency

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

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

if($hasPrefixMatch){
$pathPrefix = $PrefixMatch[$ContainersList[$i]]
if($pathPrefix -ne $null -and !($pathPrefix -is [Array])){
throw "values for PrefixMatch must be string array for each container"
}
$restoreCriteria.SubItemPathPrefix = $pathPrefix
}

# adding a criteria for each container given
$restoreCriteriaList += ($restoreCriteria)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This object can now be used to configure backup for the given disk.

### Example 2: Initialize Backup instance object for AzureKubernetesService
```powershell
$policy = Get-AzDataProtectionBackupPolicy -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -VaultName "vaultName" -ResourceGroupName "resourceGroupName" | where {$_.Name -eq "policyName"}
$policy = Get-AzDataProtectionBackupPolicy -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -VaultName "vaultName" -ResourceGroupName "resourceGroupName" | Where-Object {$_.Name -eq "policyName"}
$sourceClusterId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourceGroupName/providers/Microsoft.ContainerService/managedClusters/aks-cluster"
$snapshotResourceGroupId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourceGroupName"
$backupConfig = New-AzDataProtectionBackupConfigurationClientObject -SnapshotVolume $true -IncludeClusterScopeResource $true -DatasourceType AzureKubernetesService -LabelSelector "x=y","foo=bar"
Expand Down
Loading

0 comments on commit 4b94eea

Please sign in to comment.