コード例 #1
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();

            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);
        }
コード例 #2
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);
            }
        }