public RestAzureNS.AzureOperationResponse TriggerRestore() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string vaultLocation = (string)ProviderData[VaultParams.VaultLocation]; CmdletModel.AzureFileShareRecoveryPoint recoveryPoint = ProviderData[RestoreBackupItemParams.RecoveryPoint] as CmdletModel.AzureFileShareRecoveryPoint; string copyOptions = (string)ProviderData[RestoreFSBackupItemParams.ResolveConflict]; string sourceFilePath = ProviderData.ContainsKey(RestoreFSBackupItemParams.SourceFilePath) ? (string)ProviderData[RestoreFSBackupItemParams.SourceFilePath] : null; string sourceFileType = ProviderData.ContainsKey(RestoreFSBackupItemParams.SourceFileType) ? (string)ProviderData[RestoreFSBackupItemParams.SourceFileType] : null; string targetStorageAccountName = ProviderData.ContainsKey(RestoreFSBackupItemParams.TargetStorageAccountName) ? (string)ProviderData[RestoreFSBackupItemParams.TargetStorageAccountName] : null; string targetFileShareName = ProviderData.ContainsKey(RestoreFSBackupItemParams.TargetFileShareName) ? (string)ProviderData[RestoreFSBackupItemParams.TargetFileShareName] : null; string targetFolder = ProviderData.ContainsKey(RestoreFSBackupItemParams.TargetFolder) ? (string)ProviderData[RestoreFSBackupItemParams.TargetFolder] : null; string[] multipleSourceFilePaths = ProviderData.ContainsKey(RestoreFSBackupItemParams.MultipleSourceFilePath) ? (string[])ProviderData[RestoreFSBackupItemParams.MultipleSourceFilePath] : null; //validate file recovery request ValidateFileRestoreRequest(sourceFilePath, sourceFileType, multipleSourceFilePaths); //validate alternate location restore request ValidateLocationRestoreRequest(targetFileShareName, targetStorageAccountName, targetFolder); if (targetFileShareName != null && targetStorageAccountName != null && targetFolder == null) { targetFolder = "/"; } GenericResource storageAccountResource = ServiceClientAdapter.GetStorageAccountResource(recoveryPoint.ContainerName.Split(';')[2]); GenericResource targetStorageAccountResource = null; string targetStorageAccountLocation = null; if (targetStorageAccountName != null) { targetStorageAccountResource = ServiceClientAdapter.GetStorageAccountResource(targetStorageAccountName); targetStorageAccountLocation = targetStorageAccountResource.Location; } List <RestoreFileSpecs> restoreFileSpecs = null; TargetAFSRestoreInfo targetDetails = null; RestoreFileSpecs restoreFileSpec = new RestoreFileSpecs(); AzureFileShareRestoreRequest restoreRequest = new AzureFileShareRestoreRequest(); restoreRequest.CopyOptions = copyOptions; restoreRequest.SourceResourceId = storageAccountResource.Id; if (sourceFilePath != null) { restoreFileSpec.Path = sourceFilePath; restoreFileSpec.FileSpecType = sourceFileType; restoreRequest.RestoreRequestType = RestoreRequestType.ItemLevelRestore; if (targetFolder != null) { //scenario : item level restore for alternate location restoreFileSpec.TargetFolderPath = targetFolder; targetDetails = new TargetAFSRestoreInfo(); targetDetails.Name = targetFileShareName; targetDetails.TargetResourceId = targetStorageAccountResource.Id; restoreRequest.RecoveryType = RecoveryType.AlternateLocation; } else { //scenario : item level restore for original location restoreFileSpec.TargetFolderPath = null; restoreRequest.RecoveryType = RecoveryType.OriginalLocation; } restoreFileSpecs = new List <RestoreFileSpecs>(); restoreFileSpecs.Add(restoreFileSpec); } else if (multipleSourceFilePaths != null) { restoreFileSpecs = new List <RestoreFileSpecs>(); foreach (string filepath in multipleSourceFilePaths) { RestoreFileSpecs fileSpec = new RestoreFileSpecs(); fileSpec.Path = filepath; fileSpec.FileSpecType = sourceFileType; restoreRequest.RestoreRequestType = RestoreRequestType.ItemLevelRestore; if (targetFolder != null) { fileSpec.TargetFolderPath = targetFolder; targetDetails = new TargetAFSRestoreInfo(); targetDetails.Name = targetFileShareName; targetDetails.TargetResourceId = targetStorageAccountResource.Id; restoreRequest.RecoveryType = RecoveryType.AlternateLocation; } else { fileSpec.TargetFolderPath = null; restoreRequest.RecoveryType = RecoveryType.OriginalLocation; } restoreFileSpecs.Add(fileSpec); } } else { restoreRequest.RestoreRequestType = RestoreRequestType.FullShareRestore; if (targetFolder != null) { //scenario : full level restore for alternate location restoreFileSpec.Path = null; restoreFileSpec.TargetFolderPath = targetFolder; restoreFileSpec.FileSpecType = null; restoreFileSpecs = new List <RestoreFileSpecs>(); restoreFileSpecs.Add(restoreFileSpec); targetDetails = new TargetAFSRestoreInfo(); targetDetails.Name = targetFileShareName; targetDetails.TargetResourceId = targetStorageAccountResource.Id; restoreRequest.RecoveryType = RecoveryType.AlternateLocation; } else { //scenario : full level restore for original location restoreRequest.RecoveryType = RecoveryType.OriginalLocation; } } restoreRequest.RestoreFileSpecs = restoreFileSpecs; restoreRequest.TargetDetails = targetDetails; RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource(); triggerRestoreRequest.Properties = restoreRequest; var response = ServiceClientAdapter.RestoreDisk( recoveryPoint, targetStorageAccountLocation = targetStorageAccountLocation ?? storageAccountResource.Location, triggerRestoreRequest, vaultName: vaultName, resourceGroupName: resourceGroupName, vaultLocation: vaultLocation ?? ServiceClientAdapter.BmsAdapter.GetResourceLocation()); return(response); }
public RestAzureNS.AzureOperationResponse TriggerRestore() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string vaultLocation = (string)ProviderData[VaultParams.VaultLocation]; RecoveryConfigBase wLRecoveryConfigBase = (RecoveryConfigBase)ProviderData[RestoreWLBackupItemParams.WLRecoveryConfig]; AzureWorkloadRecoveryConfig wLRecoveryConfig = (AzureWorkloadRecoveryConfig)ProviderData[RestoreWLBackupItemParams.WLRecoveryConfig]; RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource(); if (wLRecoveryConfig.RecoveryPoint.ContainerName != null && wLRecoveryConfig.FullRP == null) { // validate container name to be a full name AzureWorkloadProviderHelper.ValidateContainerName(wLRecoveryConfig.RecoveryPoint.ContainerName); AzureWorkloadSQLRestoreRequest azureWorkloadSQLRestoreRequest = new AzureWorkloadSQLRestoreRequest(); azureWorkloadSQLRestoreRequest.SourceResourceId = wLRecoveryConfig.SourceResourceId; azureWorkloadSQLRestoreRequest.ShouldUseAlternateTargetLocation = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") != 0 ? true : false; azureWorkloadSQLRestoreRequest.IsNonRecoverable = string.Compare(wLRecoveryConfig.NoRecoveryMode, "Enabled") == 0 ? true : false; azureWorkloadSQLRestoreRequest.RecoveryType = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") == 0 ? RecoveryType.OriginalLocation : RecoveryType.AlternateLocation; if (azureWorkloadSQLRestoreRequest.RecoveryType == RecoveryType.AlternateLocation) { azureWorkloadSQLRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, DatabaseName = wLRecoveryConfig.TargetInstance + "/" + wLRecoveryConfig.RestoredDBName, ContainerId = wLRecoveryConfig.ContainerId }; azureWorkloadSQLRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath; } if (wLRecoveryConfig.RecoveryMode == "FileRecovery") { azureWorkloadSQLRestoreRequest.RecoveryMode = "FileRecovery"; azureWorkloadSQLRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, ContainerId = wLRecoveryConfig.ContainerId, TargetDirectoryForFileRestore = wLRecoveryConfig.FilePath }; } triggerRestoreRequest.Properties = azureWorkloadSQLRestoreRequest; } else { AzureWorkloadSQLPointInTimeRestoreRequest azureWorkloadSQLPointInTimeRestoreRequest = new AzureWorkloadSQLPointInTimeRestoreRequest(); azureWorkloadSQLPointInTimeRestoreRequest.SourceResourceId = wLRecoveryConfig.SourceResourceId; azureWorkloadSQLPointInTimeRestoreRequest.ShouldUseAlternateTargetLocation = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") != 0 ? true : false; azureWorkloadSQLPointInTimeRestoreRequest.IsNonRecoverable = string.Compare(wLRecoveryConfig.NoRecoveryMode, "Enabled") == 0 ? true : false; azureWorkloadSQLPointInTimeRestoreRequest.RecoveryType = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") == 0 ? RecoveryType.OriginalLocation : RecoveryType.AlternateLocation; if (azureWorkloadSQLPointInTimeRestoreRequest.RecoveryType == RecoveryType.AlternateLocation) { azureWorkloadSQLPointInTimeRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, DatabaseName = wLRecoveryConfig.TargetInstance + "/" + wLRecoveryConfig.RestoredDBName, ContainerId = wLRecoveryConfig.ContainerId }; azureWorkloadSQLPointInTimeRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath; } if (wLRecoveryConfig.RecoveryMode == "FileRecovery") { azureWorkloadSQLPointInTimeRestoreRequest.RecoveryMode = "FileRecovery"; azureWorkloadSQLPointInTimeRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, ContainerId = wLRecoveryConfig.ContainerId, TargetDirectoryForFileRestore = wLRecoveryConfig.FilePath }; } azureWorkloadSQLPointInTimeRestoreRequest.PointInTime = wLRecoveryConfig.PointInTime; triggerRestoreRequest.Properties = azureWorkloadSQLPointInTimeRestoreRequest; } var response = ServiceClientAdapter.RestoreDisk( (AzureRecoveryPoint)wLRecoveryConfig.RecoveryPoint, "LocationNotRequired", triggerRestoreRequest, vaultName: vaultName, resourceGroupName: resourceGroupName, vaultLocation: vaultLocation); return(response); }
public RestAzureNS.AzureOperationResponse TriggerRestore() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string vaultLocation = (string)ProviderData[VaultParams.VaultLocation]; RecoveryConfigBase wLRecoveryConfigBase = (RecoveryConfigBase)ProviderData[RestoreWLBackupItemParams.WLRecoveryConfig]; AzureWorkloadRecoveryConfig wLRecoveryConfig = (AzureWorkloadRecoveryConfig)ProviderData[RestoreWLBackupItemParams.WLRecoveryConfig]; RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource(); bool useSecondaryRegion = (bool)ProviderData[CRRParams.UseSecondaryRegion]; String secondaryRegion = useSecondaryRegion ? (string)ProviderData[CRRParams.SecondaryRegion] : null; if (wLRecoveryConfig.RecoveryPoint.ContainerName != null && wLRecoveryConfig.FullRP == null) { AzureWorkloadSQLRestoreRequest azureWorkloadSQLRestoreRequest = new AzureWorkloadSQLRestoreRequest(); azureWorkloadSQLRestoreRequest.SourceResourceId = wLRecoveryConfig.SourceResourceId; azureWorkloadSQLRestoreRequest.ShouldUseAlternateTargetLocation = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") != 0 ? true : false; azureWorkloadSQLRestoreRequest.IsNonRecoverable = string.Compare(wLRecoveryConfig.NoRecoveryMode, "Enabled") == 0 ? true : false; azureWorkloadSQLRestoreRequest.RecoveryType = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") == 0 ? RecoveryType.OriginalLocation : RecoveryType.AlternateLocation; if (azureWorkloadSQLRestoreRequest.RecoveryType == RecoveryType.AlternateLocation) { azureWorkloadSQLRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, DatabaseName = wLRecoveryConfig.TargetInstance + "/" + wLRecoveryConfig.RestoredDBName, ContainerId = wLRecoveryConfig.ContainerId }; azureWorkloadSQLRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath; if (wLRecoveryConfig.TargetVirtualMachineId != null && wLRecoveryConfig.TargetVirtualMachineId != "") { azureWorkloadSQLRestoreRequest.TargetVirtualMachineId = wLRecoveryConfig.TargetVirtualMachineId; } else { throw new ArgumentException(Resources.TargetVirtualMachineIdRequiredException); } } if (wLRecoveryConfig.RecoveryMode == "FileRecovery") { azureWorkloadSQLRestoreRequest.RecoveryMode = "FileRecovery"; azureWorkloadSQLRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, ContainerId = wLRecoveryConfig.ContainerId, TargetDirectoryForFileRestore = wLRecoveryConfig.FilePath }; } triggerRestoreRequest.Properties = azureWorkloadSQLRestoreRequest; } else { AzureWorkloadSQLPointInTimeRestoreRequest azureWorkloadSQLPointInTimeRestoreRequest = new AzureWorkloadSQLPointInTimeRestoreRequest(); azureWorkloadSQLPointInTimeRestoreRequest.SourceResourceId = wLRecoveryConfig.SourceResourceId; azureWorkloadSQLPointInTimeRestoreRequest.ShouldUseAlternateTargetLocation = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") != 0 ? true : false; azureWorkloadSQLPointInTimeRestoreRequest.IsNonRecoverable = string.Compare(wLRecoveryConfig.NoRecoveryMode, "Enabled") == 0 ? true : false; azureWorkloadSQLPointInTimeRestoreRequest.RecoveryType = string.Compare(wLRecoveryConfig.RestoreRequestType, "Original WL Restore") == 0 ? RecoveryType.OriginalLocation : RecoveryType.AlternateLocation; if (azureWorkloadSQLPointInTimeRestoreRequest.RecoveryType == RecoveryType.AlternateLocation) { azureWorkloadSQLPointInTimeRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, DatabaseName = wLRecoveryConfig.TargetInstance + "/" + wLRecoveryConfig.RestoredDBName, ContainerId = wLRecoveryConfig.ContainerId }; azureWorkloadSQLPointInTimeRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath; if (wLRecoveryConfig.TargetVirtualMachineId != null && wLRecoveryConfig.TargetVirtualMachineId != "") { azureWorkloadSQLPointInTimeRestoreRequest.TargetVirtualMachineId = wLRecoveryConfig.TargetVirtualMachineId; } else { throw new ArgumentException(Resources.TargetVirtualMachineIdRequiredException); } } if (wLRecoveryConfig.RecoveryMode == "FileRecovery") { azureWorkloadSQLPointInTimeRestoreRequest.RecoveryMode = "FileRecovery"; azureWorkloadSQLPointInTimeRestoreRequest.TargetInfo = new TargetRestoreInfo() { OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ? OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite, ContainerId = wLRecoveryConfig.ContainerId, TargetDirectoryForFileRestore = wLRecoveryConfig.FilePath }; } azureWorkloadSQLPointInTimeRestoreRequest.PointInTime = wLRecoveryConfig.PointInTime; triggerRestoreRequest.Properties = azureWorkloadSQLPointInTimeRestoreRequest; } if (useSecondaryRegion) { AzureRecoveryPoint rp = (AzureRecoveryPoint)wLRecoveryConfig.RecoveryPoint; // get access token CrrAccessToken accessToken = ServiceClientAdapter.GetCRRAccessToken(rp, secondaryRegion, vaultName: vaultName, resourceGroupName: resourceGroupName, ServiceClientModel.BackupManagementType.AzureWorkload); // AzureWorkload CRR Request Logger.Instance.WriteDebug("Triggering Restore to secondary region: " + secondaryRegion); CrossRegionRestoreRequest crrRestoreRequest = new CrossRegionRestoreRequest(); crrRestoreRequest.CrossRegionRestoreAccessDetails = accessToken; crrRestoreRequest.RestoreRequest = triggerRestoreRequest.Properties; // storage account location isn't required in case of workload restore var response = ServiceClientAdapter.RestoreDiskSecondryRegion( rp, triggerCRRRestoreRequest: crrRestoreRequest, secondaryRegion: secondaryRegion); return(response); } else { var response = ServiceClientAdapter.RestoreDisk( (AzureRecoveryPoint)wLRecoveryConfig.RecoveryPoint, "LocationNotRequired", triggerRestoreRequest, vaultName: vaultName, resourceGroupName: resourceGroupName, vaultLocation: vaultLocation); return(response); } }