/// <summary> /// This method triggers the Data Move operation on Target vault. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="triggerMoveRequest"></param> public void TriggerDataMove(string vaultName, string resourceGroupName, TriggerDataMoveRequest triggerMoveRequest) { //trigger move var triggerMoveOperationResponse = ServiceClientAdapter.BmsAdapter.Client.BeginBMSTriggerDataMoveWithHttpMessagesAsync( vaultName, resourceGroupName, triggerMoveRequest).Result; // track trigger-move operation to success var operationStatus = TrackingHelpers.GetOperationStatusDataMove( triggerMoveOperationResponse, operationId => ServiceClientAdapter.GetDataMoveOperationStatus(operationId, vaultName, resourceGroupName)); Logger.Instance.WriteDebug("Trigger move operation: " + operationStatus.Body.Status); }
/// <summary> /// Triggers Data Move Operation on target vault /// </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'> /// Trigger data move request /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task BeginBMSTriggerDataMoveAsync(this IRecoveryServicesBackupClient operations, string vaultName, string resourceGroupName, TriggerDataMoveRequest parameters, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.BeginBMSTriggerDataMoveWithHttpMessagesAsync(vaultName, resourceGroupName, parameters, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Triggers Data Move Operation on target vault /// </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'> /// Trigger data move request /// </param> public static void BeginBMSTriggerDataMove(this IRecoveryServicesBackupClient operations, string vaultName, string resourceGroupName, TriggerDataMoveRequest parameters) { operations.BeginBMSTriggerDataMoveAsync(vaultName, resourceGroupName, parameters).GetAwaiter().GetResult(); }
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)); }