/// <summary>
 /// Restore Azure BackUpItem.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IRestoreOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <param name='containerName'>
 /// Optional.
 /// </param>
 /// <param name='itemName'>
 /// Optional.
 /// </param>
 /// <param name='recoveryPointName'>
 /// Optional.
 /// </param>
 /// <param name='parameters'>
 /// Optional.
 /// </param>
 /// <returns>
 /// The definition of a Operation Response.
 /// </returns>
 public static OperationResponse TriggerResotre(this IRestoreOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string containerName, string itemName, string recoveryPointName, CSMRestoreRequest parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRestoreOperations)s).TriggerResotreAsync(resourceGroupName, resourceName, customRequestHeaders, containerName, itemName, recoveryPointName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void TriggerRestoreTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient<BackupServicesManagementClient>();

                string containerName = ConfigurationManager.AppSettings["ContainerName"];
                string itemName = ConfigurationManager.AppSettings["ItemName"];
                string recoveryPointName = ConfigurationManager.AppSettings["RecoveryPointName"];
                string region = ConfigurationManager.AppSettings["Region"];
                string storageAccountName = ConfigurationManager.AppSettings["StorageAccountName"];

                AzureIaaSVMRecoveryInputsCSMObject azureIaaSVMRecoveryInputsCSMObject = new AzureIaaSVMRecoveryInputsCSMObject()
                {
                    AffinityGroup = string.Empty,
                    CloudServiceName = string.Empty,
                    VmName = string.Empty,
                    CreateNewCloudService = false,
                    Region = region,
                    InputStorageAccountName = storageAccountName,
                    ContinueProtection = false,
                    SubNetName = string.Empty,
                    TargetVNet = string.Empty,
                };

                var serializer = new JavaScriptSerializer();
                string azureIaaSVMRecoveryInputsCSMObjectString = serializer.Serialize(azureIaaSVMRecoveryInputsCSMObject);

                CSMRestoreRequest restoreRequest = new CSMRestoreRequest()
                {
                    Properties = new CSMRestoreRequestProperties()
                    {
                        TypeOfRecovery = RecoveryType.RestoreDisks.ToString(),
                        RecoveryDSTypeSpecificInputs = azureIaaSVMRecoveryInputsCSMObjectString,
                    },
                };

                var response = client.Restore.TriggerResotre(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, GetCustomRequestHeaders(), containerName, itemName, recoveryPointName, restoreRequest);
                Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            }
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            ExecutionBlock(() =>
            {
                WriteDebug(Resources.MakingClientCall);
                AzureIaaSVMRecoveryInputsCSMObject azureIaaSVMRecoveryInputsCSMObject = new AzureIaaSVMRecoveryInputsCSMObject()
                {
                    CloudServiceName = string.Empty,
                    VmName = string.Empty,
                    CreateNewCloudService = false,
                    ContinueProtection = false,
                    InputStorageAccountName = StorageAccountName,
                    AffinityGroup = "",
                    Region = RecoveryPoint.Location,
                };

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string azureIaaSVMRecoveryInputsCSMObjectString = serializer.Serialize(azureIaaSVMRecoveryInputsCSMObject);

                CSMRestoreRequest csmRestoreRequest = new CSMRestoreRequest()
                {
                    Properties = new CSMRestoreRequestProperties()
                    {
                        TypeOfRecovery = RecoveryType.RestoreDisks.ToString(),
                        RecoveryDSTypeSpecificInputs = azureIaaSVMRecoveryInputsCSMObjectString,
                    },
                };

                Guid operationId = AzureBackupClient.TriggerRestore(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, RecoveryPoint.ContainerUniqueName, RecoveryPoint.ItemName, RecoveryPoint.RecoveryPointName, csmRestoreRequest);
                WriteDebug(string.Format(Resources.TriggeringRestore, operationId));

                var operationStatus = TrackOperation(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, operationId);
                WriteObject(GetCreatedJobs(RecoveryPoint.ResourceGroupName,
                    RecoveryPoint.ResourceName,
                    new Models.AzureRMBackupVault(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, RecoveryPoint.Location),
                    operationStatus.JobList).FirstOrDefault());

            });
        }
Esempio n. 4
0
 /// <summary>
 /// Lists recovery points for specified item
 /// </summary>
 /// <param name="containerName"></param>
 /// <param name="itemName"></param>
 /// <param name="recoveryPointName"></param>
 /// <returns></returns>
 public Guid TriggerRestore(string resourceGroupName, string resourceName, string containerName, string itemName, string recoveryPointName, CSMRestoreRequest csmRestoreRequest)
 {
     var response = AzureBackupClient.Restore.TriggerResotreAsync(resourceGroupName, resourceName, GetCustomRequestHeaders(), containerName, itemName, recoveryPointName, csmRestoreRequest, CmdletCancellationToken).Result;
     return response.OperationId;
 }
 /// <summary>
 /// Restore Azure BackUpItem.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IRestoreOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <param name='containerName'>
 /// Optional.
 /// </param>
 /// <param name='itemName'>
 /// Optional.
 /// </param>
 /// <param name='recoveryPointName'>
 /// Optional.
 /// </param>
 /// <param name='parameters'>
 /// Optional.
 /// </param>
 /// <returns>
 /// The definition of a Operation Response.
 /// </returns>
 public static Task<OperationResponse> TriggerResotreAsync(this IRestoreOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string containerName, string itemName, string recoveryPointName, CSMRestoreRequest parameters)
 {
     return operations.TriggerResotreAsync(resourceGroupName, resourceName, customRequestHeaders, containerName, itemName, recoveryPointName, parameters, CancellationToken.None);
 }