Ejemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                // fetch source vault and target vault subscription
                Dictionary <CmdletModel.UriEnums, string> SourceVaultDict = HelperUtils.ParseUri(SourceVault.ID);
                string sourceSub = SourceVaultDict[CmdletModel.UriEnums.Subscriptions];

                // change subscription for HTTP requests
                string subscriptionContext = ServiceClientAdapter.BmsAdapter.Client.SubscriptionId;

                // Prepare Data Move
                ServiceClientAdapter.BmsAdapter.Client.SubscriptionId = sourceSub;
                PrepareDataMoveRequest prepareMoveRequest             = new PrepareDataMoveRequest();
                prepareMoveRequest.TargetResourceId = TargetVault.ID;
                prepareMoveRequest.TargetRegion     = TargetVault.Location;

                /// currently only allowing vault level data move
                prepareMoveRequest.DataMoveLevel = "Vault";

                if (RetryOnlyFailed.IsPresent)
                {
                    prepareMoveRequest.IgnoreMoved = true;
                }
                else
                {
                    prepareMoveRequest.IgnoreMoved = false;
                }

                Logger.Instance.WriteDebug("Retry only with failed items : " + prepareMoveRequest.IgnoreMoved);
                Logger.Instance.WriteDebug("Location of Target vault: " + TargetVault.Location);

                /* move Prepare move function to vault APIs */
                string correlationId = ServiceClientAdapter.PrepareDataMove(SourceVault.Name, SourceVault.ResourceGroupName, prepareMoveRequest);

                ServiceClientAdapter.BmsAdapter.Client.SubscriptionId = subscriptionContext; // set subscription to original
                WriteObject(correlationId);
            }, ShouldProcess(TargetVault.Name, VerbsCommon.Set));
        }
        /// <summary>
        /// This method prepares the source vault for Data Move operation.
        /// </summary>
        /// <param name="vaultName"></param>
        /// <param name="resourceGroupName"></param>
        /// <param name="prepareMoveRequest"></param>
        public string PrepareDataMove(string vaultName, string resourceGroupName, PrepareDataMoveRequest prepareMoveRequest)
        {
            // prepare move
            var prepareMoveOperationResponse = ServiceClientAdapter.BmsAdapter.Client.BeginBMSPrepareDataMoveWithHttpMessagesAsync(
                vaultName, resourceGroupName, prepareMoveRequest).Result;

            // track prepare-move operation to success
            var operationStatus = TrackingHelpers.GetOperationStatusDataMove(
                prepareMoveOperationResponse,
                operationId => ServiceClientAdapter.GetDataMoveOperationStatus(operationId, vaultName, resourceGroupName));

            Logger.Instance.WriteDebug("Prepare move operation: " + operationStatus.Body.Status);

            // get the correlation Id and return it for trigger data move
            var operationResult = TrackingHelpers.GetCorrelationId(
                prepareMoveOperationResponse,
                operationId => ServiceClientAdapter.GetPrepareDataMoveOperationResult(operationId, vaultName, resourceGroupName));

            Logger.Instance.WriteDebug("Prepare move - correlationId:" + operationResult.CorrelationId);

            return(operationResult.CorrelationId);
        }
 /// <summary>
 /// Prepares source vault for Data Move operation
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='vaultName'>
 /// The name of the recovery services vault.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group where the recovery services vault is
 /// present.
 /// </param>
 /// <param name='parameters'>
 /// Prepare data move request
 /// </param>
 public static void BMSPrepareDataMove(this IRecoveryServicesBackupClient operations, string vaultName, string resourceGroupName, PrepareDataMoveRequest parameters)
 {
     operations.BMSPrepareDataMoveAsync(vaultName, resourceGroupName, parameters).GetAwaiter().GetResult();
 }
 /// <summary>
 /// Prepares source vault for Data Move operation
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='vaultName'>
 /// The name of the recovery services vault.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group where the recovery services vault is
 /// present.
 /// </param>
 /// <param name='parameters'>
 /// Prepare data move request
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task BMSPrepareDataMoveAsync(this IRecoveryServicesBackupClient operations, string vaultName, string resourceGroupName, PrepareDataMoveRequest parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.BMSPrepareDataMoveWithHttpMessagesAsync(vaultName, resourceGroupName, parameters, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
Ejemplo n.º 5
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                // fetch source vault and target vault subscription
                Dictionary <CmdletModel.UriEnums, string> SourceVaultDict = HelperUtils.ParseUri(SourceVault.ID);
                string sourceSub = SourceVaultDict[CmdletModel.UriEnums.Subscriptions];

                Dictionary <CmdletModel.UriEnums, string> TargetVaultDict = HelperUtils.ParseUri(TargetVault.ID);
                string targetSub = TargetVaultDict[CmdletModel.UriEnums.Subscriptions];

                // change subscription for HTTP requests
                string subscriptionContext = ServiceClientAdapter.BmsAdapter.Client.SubscriptionId;
                ServiceClientAdapter.BmsAdapter.Client.SubscriptionId = targetSub;

                // Check if the Target vault is empty
                // Check the containers count in target vault
                var protectionContainersCount = BackupUtils.GetProtectionContainersCount(TargetVault.Name, TargetVault.ResourceGroupName, ServiceClientAdapter);

                Logger.Instance.WriteDebug("Protection Containers within vault: " + TargetVault.Name + " and resource Group: "
                                           + TargetVault.ResourceGroupName + " are " + protectionContainersCount);

                if (protectionContainersCount > 0)
                {
                    throw new ArgumentException(string.Format(Resources.TargetVaultNotEmptyException));
                }

                // check the count for VM backupItems
                int vmItemsCount = BackupUtils.GetProtectedItems(TargetVault.Name, TargetVault.ResourceGroupName,
                                                                 BackupManagementType.AzureIaasVM, WorkloadType.VM, ServiceClientAdapter).Count;

                Logger.Instance.WriteDebug("Protected VMs within vault: " + TargetVault.Name + " and resource Group: "
                                           + TargetVault.ResourceGroupName + " are " + vmItemsCount);

                if (vmItemsCount > 0)
                {
                    throw new ArgumentException(string.Format(Resources.TargetVaultNotEmptyException));
                }

                // Confirm the target vault storage type
                BackupResourceConfigResource getStorageResponse = ServiceClientAdapter.GetVaultStorageType(
                    TargetVault.ResourceGroupName, TargetVault.Name);

                Logger.Instance.WriteDebug("Storage Type: " + getStorageResponse.Properties.StorageType);

                string correlationId = "";
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(Resources.TargetVaultStorageRedundancy, TargetVault.Name, getStorageResponse.Properties.StorageType),
                    Resources.TargetVaultStorageRedundancy,
                    getStorageResponse.Properties.StorageType, () =>
                {
                    base.ExecuteCmdlet();

                    if (string.Compare(ParameterSetName, AzureRSVaultDataMoveParameterSet) == 0)
                    {
                        // Prepare Data Move
                        ServiceClientAdapter.BmsAdapter.Client.SubscriptionId = sourceSub;
                        PrepareDataMoveRequest prepareMoveRequest             = new PrepareDataMoveRequest();
                        prepareMoveRequest.TargetResourceId = TargetVault.ID;
                        prepareMoveRequest.TargetRegion     = TargetVault.Location;

                        // currently only allowing vault level data move
                        prepareMoveRequest.DataMoveLevel = "Vault";

                        if (RetryOnlyFailed.IsPresent)
                        {
                            prepareMoveRequest.IgnoreMoved = true;
                        }
                        else
                        {
                            prepareMoveRequest.IgnoreMoved = false;
                        }

                        Logger.Instance.WriteDebug("Retry only with failed items : " + prepareMoveRequest.IgnoreMoved);
                        Logger.Instance.WriteDebug("Location of Target vault: " + TargetVault.Location);

                        correlationId = ServiceClientAdapter.PrepareDataMove(SourceVault.Name, SourceVault.ResourceGroupName, prepareMoveRequest);
                    }
                    else
                    {
                        correlationId = CorrelationIdForDataMove;
                    }

                    // Trigger Data Move
                    ServiceClientAdapter.BmsAdapter.Client.SubscriptionId = targetSub;
                    TriggerDataMoveRequest triggerMoveRequest             = new TriggerDataMoveRequest();
                    triggerMoveRequest.SourceResourceId = SourceVault.ID;
                    triggerMoveRequest.SourceRegion     = SourceVault.Location;

                    // currently only allowing vault level data move
                    triggerMoveRequest.DataMoveLevel = "Vault";
                    triggerMoveRequest.CorrelationId = correlationId;
                    triggerMoveRequest.PauseGC       = false;

                    Logger.Instance.WriteDebug("Location of Source vault: " + SourceVault.Location);
                    ServiceClientAdapter.TriggerDataMove(TargetVault.Name, TargetVault.ResourceGroupName, triggerMoveRequest);

                    // set subscription to original
                    ServiceClientAdapter.BmsAdapter.Client.SubscriptionId = subscriptionContext;

                    WriteObject(ParamHelpMsgs.DSMove.CmdletOutput);
                }
                    );
            }, ShouldProcess(TargetVault.Name, VerbsCommon.Set));
        }