public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; Dictionary <Enum, object> providerParameters = new Dictionary <Enum, object>(); providerParameters.Add(VaultParams.VaultName, vaultName); providerParameters.Add(VaultParams.ResourceGroupName, resourceGroupName); providerParameters.Add(VaultParams.VaultLocation, VaultLocation); providerParameters.Add(RestoreBackupItemParams.RecoveryPoint, RecoveryPoint); providerParameters.Add(RestoreVMBackupItemParams.OsaOption, UseOriginalStorageAccount.IsPresent); providerParameters.Add(RestoreFSBackupItemParams.ResolveConflict, ResolveConflict.ToString()); providerParameters.Add(RestoreFSBackupItemParams.SourceFilePath, SourceFilePath); providerParameters.Add(RestoreFSBackupItemParams.TargetStorageAccountName, TargetStorageAccountName); providerParameters.Add(RestoreFSBackupItemParams.TargetFileShareName, TargetFileShareName); providerParameters.Add(RestoreFSBackupItemParams.TargetFolder, TargetFolder); providerParameters.Add(RestoreWLBackupItemParams.WLRecoveryConfig, WLRecoveryConfig); providerParameters.Add(RestoreVMBackupItemParams.RestoreDiskList, RestoreDiskList); providerParameters.Add(RestoreVMBackupItemParams.RestoreOnlyOSDisk, RestoreOnlyOSDisk); providerParameters.Add(RestoreVMBackupItemParams.RestoreAsUnmanagedDisks, RestoreAsUnmanagedDisks); if (StorageAccountName != null) { providerParameters.Add(RestoreBackupItemParams.StorageAccountName, StorageAccountName); } if (StorageAccountResourceGroupName != null) { providerParameters.Add(RestoreBackupItemParams.StorageAccountResourceGroupName, StorageAccountResourceGroupName); } if (TargetResourceGroupName != null) { providerParameters.Add(RestoreVMBackupItemParams.TargetResourceGroupName, TargetResourceGroupName); } if (SourceFileType != null) { providerParameters.Add(RestoreFSBackupItemParams.SourceFileType, SourceFileType.ToString()); } PsBackupProviderManager providerManager = new PsBackupProviderManager(providerParameters, ServiceClientAdapter); IPsBackupProvider psBackupProvider = null; if (string.Compare(ParameterSetName, AzureWorkloadParameterSet) != 0) { psBackupProvider = providerManager.GetProviderInstance( RecoveryPoint.WorkloadType, RecoveryPoint.BackupManagementType); } else { psBackupProvider = providerManager.GetProviderInstance( WorkloadType.MSSQL, BackupManagementType.AzureWorkload); } var jobResponse = psBackupProvider.TriggerRestore(); WriteDebug(string.Format("Restore submitted")); HandleCreatedJob( jobResponse, Resources.RestoreOperation, vaultName: vaultName, resourceGroupName: resourceGroupName); }, ShouldProcess(RecoveryPoint != null ? RecoveryPoint.ItemName : WLRecoveryConfig.ToString(), VerbsData.Restore)); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; Dictionary <Enum, object> providerParameters = new Dictionary <Enum, object>(); string secondaryRegion = ""; if (RestoreToSecondaryRegion.IsPresent) { ARSVault vault = ServiceClientAdapter.GetVault(resourceGroupName, vaultName); secondaryRegion = BackupUtils.regionMap[vault.Location]; providerParameters.Add(CRRParams.SecondaryRegion, secondaryRegion); } if (RehydratePriority != null) { Logger.Instance.WriteDebug("Rehydrate priority is " + RehydratePriority); int rehydrateExpiryInDays = Int32.Parse(RehydrateDuration); // Rehydrate duration is taken as days if (rehydrateExpiryInDays < 10 || rehydrateExpiryInDays > 30) { throw new ArgumentException(Resources.InvalidRehydrateDuration); } providerParameters.Add(RecoveryPointParams.RehydrateDuration, RehydrateDuration); providerParameters.Add(RecoveryPointParams.RehydratePriority, RehydratePriority); } if (UseSystemAssignedIdentity.IsPresent || UserAssignedIdentityId != null) { if (UseSystemAssignedIdentity.IsPresent && UserAssignedIdentityId != null) { throw new ArgumentException(Resources.MultipleMSIProvidedForRestore); } /*if (UseSystemAssignedIdentity.IsPresent) * { * // check to be added on vault.Identity * } * else * { * // check whether given User MSI is present on vault * }*/ } string RestoreType = null; if (string.Compare(ParameterSetName, AzureManagedVMReplaceExistingParameterSet) == 0) { RestoreType = "OriginalLocation"; } providerParameters.Add(VaultParams.VaultName, vaultName); providerParameters.Add(VaultParams.ResourceGroupName, resourceGroupName); providerParameters.Add(VaultParams.VaultLocation, VaultLocation); providerParameters.Add(RestoreBackupItemParams.RecoveryPoint, RecoveryPoint); providerParameters.Add(RestoreVMBackupItemParams.OsaOption, UseOriginalStorageAccount.IsPresent); providerParameters.Add(RestoreFSBackupItemParams.ResolveConflict, ResolveConflict.ToString()); providerParameters.Add(RestoreFSBackupItemParams.SourceFilePath, SourceFilePath); providerParameters.Add(RestoreFSBackupItemParams.TargetStorageAccountName, TargetStorageAccountName); providerParameters.Add(RestoreFSBackupItemParams.TargetFileShareName, TargetFileShareName); providerParameters.Add(RestoreFSBackupItemParams.TargetFolder, TargetFolder); providerParameters.Add(RestoreWLBackupItemParams.WLRecoveryConfig, WLRecoveryConfig); providerParameters.Add(RestoreVMBackupItemParams.RestoreDiskList, RestoreDiskList); providerParameters.Add(RestoreVMBackupItemParams.RestoreOnlyOSDisk, RestoreOnlyOSDisk); providerParameters.Add(RestoreVMBackupItemParams.RestoreAsUnmanagedDisks, RestoreAsUnmanagedDisks); providerParameters.Add(CRRParams.UseSecondaryRegion, RestoreToSecondaryRegion.IsPresent); providerParameters.Add(RestoreVMBackupItemParams.RestoreAsManagedDisk, RestoreAsManagedDisk.IsPresent); providerParameters.Add(RestoreVMBackupItemParams.UseSystemAssignedIdentity, UseSystemAssignedIdentity.IsPresent); providerParameters.Add(RestoreVMBackupItemParams.UserAssignedIdentityId, UserAssignedIdentityId); providerParameters.Add(RestoreVMBackupItemParams.RestoreType, RestoreType); providerParameters.Add(RestoreVMBackupItemParams.TargetVMName, TargetVMName); providerParameters.Add(RestoreVMBackupItemParams.TargetVNetName, TargetVNetName); providerParameters.Add(RestoreVMBackupItemParams.TargetVNetResourceGroup, TargetVNetResourceGroup); providerParameters.Add(RestoreVMBackupItemParams.TargetSubnetName, TargetSubnetName); if (DiskEncryptionSetId != null) { AzureVmRecoveryPoint rp = (AzureVmRecoveryPoint)RecoveryPoint; ServiceClientModel.BackupResourceEncryptionConfigExtendedResource vaultEncryptionSettings = ServiceClientAdapter.GetVaultEncryptionConfig(resourceGroupName, vaultName); if ((vaultEncryptionSettings.Properties.EncryptionAtRestType == "CustomerManaged") && rp.IsManagedVirtualMachine && !(rp.EncryptionEnabled) && !(RestoreToSecondaryRegion.IsPresent)) { providerParameters.Add(RestoreVMBackupItemParams.DiskEncryptionSetId, DiskEncryptionSetId); } } if (TargetZoneNumber != null) { // get storage type ServiceClientModel.BackupResourceConfigResource getStorageResponse = ServiceClientAdapter.GetVaultStorageType(resourceGroupName, vaultName); string storageType = getStorageResponse.Properties.StorageType; bool crrEnabled = (bool)getStorageResponse.Properties.CrossRegionRestoreFlag; if (storageType == AzureRmRecoveryServicesBackupStorageRedundancyType.ZoneRedundant.ToString() || (storageType == AzureRmRecoveryServicesBackupStorageRedundancyType.GeoRedundant.ToString() && crrEnabled)) { AzureVmRecoveryPoint rp = (AzureVmRecoveryPoint)RecoveryPoint; if (rp.RecoveryPointTier == RecoveryPointTier.VaultStandard) // RP recovery type should be vault only { if (rp.Zones != null) { //target region should support Zones /*if (RestoreToSecondaryRegion.IsPresent) * { * FeatureSupportRequest iaasvmFeatureRequest = new FeatureSupportRequest(); * ServiceClientAdapter.BmsAdapter.Client.FeatureSupport.ValidateWithHttpMessagesAsync(secondaryRegion, iaasvmFeatureRequest); * }*/ providerParameters.Add(RecoveryPointParams.TargetZone, TargetZoneNumber); } else { throw new ArgumentException(string.Format(Resources.RecoveryPointZonePinnedException)); } } else { throw new ArgumentException(string.Format(Resources.RecoveryPointVaultRecoveryTypeException)); } } else { throw new ArgumentException(string.Format(Resources.ZonalRestoreVaultStorageRedundancyException)); } } if (StorageAccountName != null) { providerParameters.Add(RestoreBackupItemParams.StorageAccountName, StorageAccountName); } if (StorageAccountResourceGroupName != null) { providerParameters.Add(RestoreBackupItemParams.StorageAccountResourceGroupName, StorageAccountResourceGroupName); } if (TargetResourceGroupName != null) { providerParameters.Add(RestoreVMBackupItemParams.TargetResourceGroupName, TargetResourceGroupName); } if (SourceFileType != null) { providerParameters.Add(RestoreFSBackupItemParams.SourceFileType, SourceFileType.ToString()); } if (MultipleSourceFilePath != null) { providerParameters.Add(RestoreFSBackupItemParams.MultipleSourceFilePath, MultipleSourceFilePath); } PsBackupProviderManager providerManager = new PsBackupProviderManager(providerParameters, ServiceClientAdapter); IPsBackupProvider psBackupProvider = null; if (string.Compare(ParameterSetName, AzureWorkloadParameterSet) != 0) { psBackupProvider = providerManager.GetProviderInstance( RecoveryPoint.WorkloadType, RecoveryPoint.BackupManagementType); } else { psBackupProvider = providerManager.GetProviderInstance( WorkloadType.MSSQL, BackupManagementType.AzureWorkload); } var jobResponse = psBackupProvider.TriggerRestore(); if (RestoreToSecondaryRegion.IsPresent) { var operationId = jobResponse.Request.RequestUri.Segments.Last(); var response = ServiceClientAdapter.GetCrrOperationStatus(secondaryRegion, operationId); string jobIdJson = JsonConvert.SerializeObject(response.Body.Properties); string[] jobSplits = jobIdJson.Split(new char[] { '\"' }); string jobId = jobSplits[jobSplits.Length - 2]; WriteObject(GetCrrJobObject(secondaryRegion, VaultId, jobId)); } else { HandleCreatedJob( jobResponse, Resources.RestoreOperation, vaultName: vaultName, resourceGroupName: resourceGroupName); } }, ShouldProcess(RecoveryPoint != null ? RecoveryPoint.ItemName : WLRecoveryConfig.ToString(), VerbsData.Restore)); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; Dictionary <Enum, object> providerParameters = new Dictionary <Enum, object>(); string secondaryRegion = ""; if (RestoreToSecondaryRegion.IsPresent) { ARSVault vault = ServiceClientAdapter.GetVault(resourceGroupName, vaultName); secondaryRegion = BackupUtils.regionMap[vault.Location]; providerParameters.Add(CRRParams.SecondaryRegion, secondaryRegion); } providerParameters.Add(VaultParams.VaultName, vaultName); providerParameters.Add(VaultParams.ResourceGroupName, resourceGroupName); providerParameters.Add(VaultParams.VaultLocation, VaultLocation); providerParameters.Add(RestoreBackupItemParams.RecoveryPoint, RecoveryPoint); providerParameters.Add(RestoreVMBackupItemParams.OsaOption, UseOriginalStorageAccount.IsPresent); providerParameters.Add(RestoreFSBackupItemParams.ResolveConflict, ResolveConflict.ToString()); providerParameters.Add(RestoreFSBackupItemParams.SourceFilePath, SourceFilePath); providerParameters.Add(RestoreFSBackupItemParams.TargetStorageAccountName, TargetStorageAccountName); providerParameters.Add(RestoreFSBackupItemParams.TargetFileShareName, TargetFileShareName); providerParameters.Add(RestoreFSBackupItemParams.TargetFolder, TargetFolder); providerParameters.Add(RestoreWLBackupItemParams.WLRecoveryConfig, WLRecoveryConfig); providerParameters.Add(RestoreVMBackupItemParams.RestoreDiskList, RestoreDiskList); providerParameters.Add(RestoreVMBackupItemParams.RestoreOnlyOSDisk, RestoreOnlyOSDisk); providerParameters.Add(RestoreVMBackupItemParams.RestoreAsUnmanagedDisks, RestoreAsUnmanagedDisks); providerParameters.Add(CRRParams.UseSecondaryRegion, RestoreToSecondaryRegion.IsPresent); if (DiskEncryptionSetId != null) { AzureVmRecoveryPoint rp = (AzureVmRecoveryPoint)RecoveryPoint; BackupResourceEncryptionConfigResource vaultEncryptionSettings = ServiceClientAdapter.GetVaultEncryptionConfig(resourceGroupName, vaultName); if ((vaultEncryptionSettings.Properties.EncryptionAtRestType == "CustomerManaged") && rp.IsManagedVirtualMachine && !(rp.EncryptionEnabled) && !(RestoreToSecondaryRegion.IsPresent)) { providerParameters.Add(RestoreVMBackupItemParams.DiskEncryptionSetId, DiskEncryptionSetId); } } if (StorageAccountName != null) { providerParameters.Add(RestoreBackupItemParams.StorageAccountName, StorageAccountName); } if (StorageAccountResourceGroupName != null) { providerParameters.Add(RestoreBackupItemParams.StorageAccountResourceGroupName, StorageAccountResourceGroupName); } if (TargetResourceGroupName != null) { providerParameters.Add(RestoreVMBackupItemParams.TargetResourceGroupName, TargetResourceGroupName); } if (SourceFileType != null) { providerParameters.Add(RestoreFSBackupItemParams.SourceFileType, SourceFileType.ToString()); } if (MultipleSourceFilePath != null) { providerParameters.Add(RestoreFSBackupItemParams.MultipleSourceFilePath, MultipleSourceFilePath); } PsBackupProviderManager providerManager = new PsBackupProviderManager(providerParameters, ServiceClientAdapter); IPsBackupProvider psBackupProvider = null; if (string.Compare(ParameterSetName, AzureWorkloadParameterSet) != 0) { psBackupProvider = providerManager.GetProviderInstance( RecoveryPoint.WorkloadType, RecoveryPoint.BackupManagementType); } else { psBackupProvider = providerManager.GetProviderInstance( WorkloadType.MSSQL, BackupManagementType.AzureWorkload); } var jobResponse = psBackupProvider.TriggerRestore(); if (RestoreToSecondaryRegion.IsPresent) { var operationId = jobResponse.Request.RequestUri.Segments.Last(); var response = ServiceClientAdapter.GetCrrOperationStatus(secondaryRegion, operationId); string jobIDJson = JsonConvert.SerializeObject(response.Body.Properties); string[] jobSplits = jobIDJson.Split(new char[] { '\"' }); string jobID = jobSplits[jobSplits.Length - 2]; WriteObject(GetCrrJobObject(secondaryRegion, VaultId, jobID)); } else { HandleCreatedJob( jobResponse, Resources.RestoreOperation, vaultName: vaultName, resourceGroupName: resourceGroupName); } }, ShouldProcess(RecoveryPoint != null ? RecoveryPoint.ItemName : WLRecoveryConfig.ToString(), VerbsData.Restore)); }