Пример #1
0
        /// <summary>
        /// Gets the access token for CRR operation
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="secondaryRegion">secondary region where to trigger the restore</param>
        /// <param name="vaultName">Name of recovery services vault</param>
        /// <param name="resourceGroupName">Name of the vault resource group</param>
        /// <returns>CRR access token</returns>
        public CrrModel.CrrAccessToken GetCRRAccessToken(
            AzureRecoveryPoint rp,
            string secondaryRegion,
            string vaultName            = null,
            string resourceGroupName    = null,
            string backupManagementType = null)
        {
            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri     = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId  = rp.RecoveryPointId;

            CrrModel.AADPropertiesResource userInfo = GetAADProperties(secondaryRegion, backupManagementType);
            var accessToken = CrrAdapter.Client.RecoveryPoints.GetAccessTokenWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(),
                                                                                                   AzureFabricName, containerUri, protectedItemUri, recoveryPointId, userInfo).Result.Body;

            return(accessToken.Properties);
        }
Пример #2
0
        /// <summary>
        /// Restores the disk to the secondaryRegion based on the recovery point and other input parameters
        /// </summary>
        /// <param name="rp">Recovery point to restore the disk to</param>
        /// <param name="storageAccountLocation">ID of the storage account where to restore the disk</param>
        /// <param name="triggerCRRRestoreRequest">Location of the storage account where to restore the disk</param>
        /// <param name="secondaryRegion">Type of the storage account where to restore the disk</param>
        /// <returns>Job created by this operation</returns>
        public RestAzureNS.AzureOperationResponse RestoreDiskSecondryRegion(
            AzureRecoveryPoint rp,
            CrossRegionRestoreRequest triggerCRRRestoreRequest,
            string storageAccountLocation = null,
            string secondaryRegion        = null)
        {
            //validation block
            if (!triggerCRRRestoreRequest.RestoreRequest.GetType().IsSubclassOf(typeof(AzureWorkloadRestoreRequest)))
            {
                if (storageAccountLocation != secondaryRegion)
                {
                    throw new Exception(Resources.TriggerRestoreIncorrectRegion);
                }
            }

            var response = BmsAdapter.Client.CrossRegionRestore.TriggerWithHttpMessagesAsync(secondaryRegion, triggerCRRRestoreRequest).Result;

            return(response);
        }
Пример #3
0
        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);
            }
        }