public string BackupProtectedItem(string rsVaultRgName, string rsVaultName, string containerUri, string protectedItemUri)
        {
            string fabricName = CommonTestHelper.GetSetting(TestConstants.ProviderTypeAzureIaasVM);

            TriggerBackupRequest backupRequest = new TriggerBackupRequest();
            backupRequest.Item = new BackupRequestResource();
            IaaSVMBackupRequest iaasVmBackupRequest = new IaaSVMBackupRequest();
            iaasVmBackupRequest.RecoveryPointExpiryTimeInUTC = DateTime.UtcNow.AddDays(2);
            backupRequest.Item.Properties = iaasVmBackupRequest;

            var response = Client.Backups.TriggerBackup(rsVaultRgName, rsVaultName, CommonTestHelper.GetCustomRequestHeaders(),
                fabricName, containerUri, protectedItemUri, backupRequest);

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            Assert.NotNull(response.Location);
            Assert.NotNull(response.AzureAsyncOperation);
            Assert.NotNull(response.RetryAfter);

            var operationResponse = Client.ProtectedItems.GetProtectedItemOperationResultByURLAsync(response.Location, CommonTestHelper.GetCustomRequestHeaders());
            while (operationResponse.Result.StatusCode == HttpStatusCode.Accepted)
            {
                if (HttpMockServer.Mode == HttpRecorderMode.Record)
                {
                    System.Threading.Thread.Sleep(5 * 1000);
                }
                operationResponse = Client.ProtectedItems.GetProtectedItemOperationResultByURLAsync(response.Location, CommonTestHelper.GetCustomRequestHeaders());
            }

            var operationStatusResponse = Client.GetOperationStatusByURLAsync(response.AzureAsyncOperation, CommonTestHelper.GetCustomRequestHeaders());
            var operationJobResponse = (OperationStatusJobExtendedInfo)operationStatusResponse.Result.OperationStatus.Properties;
            Assert.NotNull(operationJobResponse.JobId);

            return operationJobResponse.JobId;
        }
 /// <summary>
 /// The Trigger Backup Operation starts an operation in the service
 /// which triggers the backup of the specified item in the specified
 /// container in your Recovery Services Vault. This is an asynchronous
 /// operation. To determine whether the backend service has finished
 /// processing the request, call Get Protected Item Operation Result
 /// API.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IBackupOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. Request header parameters.
 /// </param>
 /// <param name='fabricName'>
 /// Optional. Fabric name of the protected item.
 /// </param>
 /// <param name='containerName'>
 /// Optional. Name of the container where the protected item belongs to.
 /// </param>
 /// <param name='protectedItemName'>
 /// Optional. Name of the protected item which has to be backed up.
 /// </param>
 /// <param name='request'>
 /// Optional. Backup request for the backup item.
 /// </param>
 /// <returns>
 /// Base recovery job response for all the asynchronous operations.
 /// </returns>
 public static BaseRecoveryServicesJobResponse TriggerBackup(this IBackupOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string fabricName, string containerName, string protectedItemName, TriggerBackupRequest request)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IBackupOperations)s).TriggerBackupAsync(resourceGroupName, resourceName, customRequestHeaders, fabricName, containerName, protectedItemName, request);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Triggers backup on the specified item
        /// </summary>
        /// <param name="containerName">Name of the container which this item belongs to</param>
        /// <param name="itemName">Name of the item</param>
        /// <returns>Job created by this operation</returns>
        public BaseRecoveryServicesJobResponse TriggerBackup(
            string containerName, 
            string itemName, 
            DateTime? expiryDateTimeUtc)
        {
            TriggerBackupRequest triggerBackupRequest = new TriggerBackupRequest();
            triggerBackupRequest.Item = new BackupRequestResource();
            IaaSVMBackupRequest iaasVmBackupRequest = new IaaSVMBackupRequest();
            iaasVmBackupRequest.RecoveryPointExpiryTimeInUTC = expiryDateTimeUtc;
            triggerBackupRequest.Item.Properties = iaasVmBackupRequest;

            return BmsAdapter.Client.Backups.TriggerBackupAsync(
                BmsAdapter.GetResourceGroupName(),
                BmsAdapter.GetResourceName(),
                BmsAdapter.GetCustomRequestHeaders(),
                ServiceClientAdapter.AzureFabricName,
                containerName,
                itemName,
                triggerBackupRequest,
                BmsAdapter.CmdletCancellationToken).Result;
        }
 /// <summary>
 /// The Trigger Backup Operation starts an operation in the service
 /// which triggers the backup of the specified item in the specified
 /// container in your Recovery Services Vault. This is an asynchronous
 /// operation. To determine whether the backend service has finished
 /// processing the request, call Get Protected Item Operation Result
 /// API.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IBackupOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. Request header parameters.
 /// </param>
 /// <param name='fabricName'>
 /// Optional. Fabric name of the protected item.
 /// </param>
 /// <param name='containerName'>
 /// Optional. Name of the container where the protected item belongs to.
 /// </param>
 /// <param name='protectedItemName'>
 /// Optional. Name of the protected item which has to be backed up.
 /// </param>
 /// <param name='request'>
 /// Optional. Backup request for the backup item.
 /// </param>
 /// <returns>
 /// Base recovery job response for all the asynchronous operations.
 /// </returns>
 public static Task<BaseRecoveryServicesJobResponse> TriggerBackupAsync(this IBackupOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string fabricName, string containerName, string protectedItemName, TriggerBackupRequest request)
 {
     return operations.TriggerBackupAsync(resourceGroupName, resourceName, customRequestHeaders, fabricName, containerName, protectedItemName, request, CancellationToken.None);
 }