Beispiel #1
0
        /// <summary>
        ///     Starts PE Apply Recovery Point.
        /// </summary>
        private void StartPEApplyRecoveryPoint()
        {
            var applyRecoveryPointInputProperties = new ApplyRecoveryPointInputProperties
            {
                RecoveryPointId         = this.RecoveryPoint.ID,
                ProviderSpecificDetails = new ApplyRecoveryPointProviderSpecificInput()
            };

            var input =
                new ApplyRecoveryPointInput {
                Properties = applyRecoveryPointInputProperties
            };

            if (0 ==
                string.Compare(
                    this.ReplicationProtectedItem.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                var hyperVReplicaAzureApplyRecoveryPointInput =
                    new HyperVReplicaAzureApplyRecoveryPointInput
                {
                    PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                    SecondaryKekCertificatePfx = this.secondaryKekCertpfx,
                    VaultLocation = "dummy"
                };
                input.Properties.ProviderSpecificDetails =
                    hyperVReplicaAzureApplyRecoveryPointInput;
            }

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryApplyRecoveryPoint(
                this.fabricName,
                this.protectionContainerName,
                this.ReplicationProtectedItem.Name,
                input);

            var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Starts PE Apply Recovery Point.
        /// </summary>
        private void StartPEApplyRecoveryPoint()
        {
            var applyRecoveryPointInputProperties = new ApplyRecoveryPointInputProperties
            {
                RecoveryPointId         = this.RecoveryPoint.ID,
                ProviderSpecificDetails = new ApplyRecoveryPointProviderSpecificInput()
            };

            var input =
                new ApplyRecoveryPointInput {
                Properties = applyRecoveryPointInputProperties
            };

            if (0 ==
                string.Compare(
                    this.ReplicationProtectedItem.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                var hyperVReplicaAzureApplyRecoveryPointInput =
                    new HyperVReplicaAzureApplyRecoveryPointInput
                {
                    PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                    SecondaryKekCertificatePfx = this.secondaryKekCertpfx,
                    VaultLocation = "dummy"
                };
                input.Properties.ProviderSpecificDetails =
                    hyperVReplicaAzureApplyRecoveryPointInput;
            }
            else if (string.Compare(
                         this.ReplicationProtectedItem.ReplicationProvider,
                         Constants.InMageAzureV2,
                         StringComparison.OrdinalIgnoreCase) ==
                     0)
            {
                // Create the InMageAzureV2 specific Apply Recovery Point Input.
                var inMageAzureV2ApplyRecoveryPointInput =
                    new InMageAzureV2ApplyRecoveryPointInput();
                input.Properties.ProviderSpecificDetails = inMageAzureV2ApplyRecoveryPointInput;
            }
            else if (string.Compare(
                         this.ReplicationProtectedItem.ReplicationProvider,
                         Constants.InMage,
                         StringComparison.OrdinalIgnoreCase) ==
                     0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.UnsupportedReplicationProviderForApplyRecoveryPoint,
                              this.ReplicationProtectedItem.ReplicationProvider));
            }
            else if (Constants.A2A.Equals(this.ReplicationProtectedItem.ReplicationProvider, StringComparison.OrdinalIgnoreCase))
            {
                input.Properties.ProviderSpecificDetails = new A2AApplyRecoveryPointInput();
            }

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryApplyRecoveryPoint(
                this.fabricName,
                this.protectionContainerName,
                this.ReplicationProtectedItem.Name,
                input);

            var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            this.WriteObject(new ASRJob(jobResponse));
        }
Beispiel #3
0
        public void ApplyRecoveryPoint()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                var fabrics = client.Fabrics.List(RequestHeaders);

                Fabric selectedFabric = null;
                ProtectionContainer selectedContainer = null;

                foreach (var fabric in fabrics.Fabrics)
                {
                    if (fabric.Properties.CustomDetails.InstanceType.Contains("VMM"))
                    {
                        selectedFabric = fabric;
                        break;
                    }
                }

                var containers = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders);

                foreach (var container in containers.ProtectionContainers)
                {
                    if (container.Properties.ProtectedItemCount > 0 &&
                        container.Properties.Role.Equals("Primary"))
                    {
                        selectedContainer = container;
                        break;
                    }
                }

                string fabricId    = selectedFabric.Name;
                string containerId = selectedContainer.Name;

                if (selectedContainer != null)
                {
                    var pgs = client.ReplicationProtectedItem.List(fabricId, containerId, RequestHeaders);
                    var rps = client.RecoveryPoint.List(fabricId, containerId, pgs.ReplicationProtectedItems[0].Name, RequestHeaders);

                    ApplyRecoveryPointInputProperties applyRpProp = new ApplyRecoveryPointInputProperties()
                    {
                        RecoveryPointId         = rps.RecoveryPoints[rps.RecoveryPoints.Count - 2].Id,
                        ProviderSpecificDetails = new HyperVReplicaAzureApplyRecoveryPointInput()
                        {
                            VaultLocation = "SoutheastAsia"
                        }
                    };

                    ApplyRecoveryPointInput applyRpInput = new ApplyRecoveryPointInput()
                    {
                        Properties = applyRpProp
                    };

                    var applyRpResp = client.ReplicationProtectedItem.ApplyRecoveryPoint(
                        fabricId,
                        containerId,
                        pgs.ReplicationProtectedItems[0].Name,
                        applyRpInput,
                        RequestHeaders);
                }
                else
                {
                    throw new System.Exception("Container not found.");
                }
            }
        }