/// <summary>
 /// Apply recovery point for the given Replication protected item.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IReplicationProtectedItemOperations.
 /// </param>
 /// <param name='fabricName'>
 /// Required. Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Required. Protection container name.
 /// </param>
 /// <param name='replicationProtectedItemName'>
 /// Required. Replication protected item name.
 /// </param>
 /// <param name='input'>
 /// Required. Apply recovery point input.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static LongRunningOperationResponse ApplyRecoveryPoint(this IReplicationProtectedItemOperations operations, string fabricName, string protectionContainerName, string replicationProtectedItemName, ApplyRecoveryPointInput input, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IReplicationProtectedItemOperations)s).ApplyRecoveryPointAsync(fabricName, protectionContainerName, replicationProtectedItemName, input, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Apply recovery point for the given Replication protected item.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IReplicationProtectedItemOperations.
 /// </param>
 /// <param name='fabricName'>
 /// Required. Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Required. Protection container name.
 /// </param>
 /// <param name='replicationProtectedItemName'>
 /// Required. Replication protected item name.
 /// </param>
 /// <param name='input'>
 /// Required. Apply recovery point input.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static Task<LongRunningOperationResponse> ApplyRecoveryPointAsync(this IReplicationProtectedItemOperations operations, string fabricName, string protectionContainerName, string replicationProtectedItemName, ApplyRecoveryPointInput input, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ApplyRecoveryPointAsync(fabricName, protectionContainerName, replicationProtectedItemName, input, customRequestHeaders, CancellationToken.None);
 }
Пример #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.");
                }
            }
        }
        /// <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 = primaryKekCertpfx,
                    SecondaryKekCertificatePfx = secondaryKekCertpfx,
                    VaultLocation = this.GetCurrentVaultLocation()
                };
                input.Properties.ProviderSpecificDetails = hyperVReplicaAzureApplyRecoveryPointInput;
            }

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

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

            WriteObject(new ASRJob(jobResponse.Job));
        }