public RestAzureNS.AzureOperationResponse <ProtectedItemResource> UndeleteProtection() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; AzureWorkloadSQLDatabaseProtectedItem item = (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item]; Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); string containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); AzureVmWorkloadSQLDatabaseProtectedItem properties = new AzureVmWorkloadSQLDatabaseProtectedItem(); properties.PolicyId = null; properties.ProtectionState = ProtectionState.ProtectionStopped; properties.SourceResourceId = item.SourceResourceId; properties.IsRehydrate = true; ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties, }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest, vaultName: vaultName, resourceGroupName: resourceGroupName)); }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public AzureWorkloadSAPHanaDatabaseProtectedItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType, policyName) { AzureVmWorkloadSAPHanaDatabaseProtectedItem protectedItem = (AzureVmWorkloadSAPHanaDatabaseProtectedItem)protectedItemResource.Properties; FriendlyName = protectedItem.FriendlyName; ServerName = protectedItem.ServerName; ParentName = protectedItem.ParentName; ParentType = protectedItem.ParentType; LastBackupErrorDetail = protectedItem.LastBackupErrorDetail; ProtectedItemDataSourceId = protectedItem.ProtectedItemDataSourceId; ProtectedItemHealthStatus = protectedItem.ProtectedItemHealthStatus; LastBackupStatus = protectedItem.LastBackupStatus; LastBackupTime = protectedItem.LastBackupTime; ProtectionState = EnumUtils.GetEnum <ItemProtectionState>(protectedItem.ProtectionState.ToString()); ProtectionStatus = EnumUtils.GetEnum <ItemProtectionStatus>(protectedItem.ProtectionStatus); DateOfPurge = null; DeleteState = EnumUtils.GetEnum <ItemDeleteState>("NotDeleted"); if (protectedItem.IsScheduledForDeferredDelete.HasValue) { DateOfPurge = protectedItem.DeferredDeleteTimeInUTC.Value.AddDays(14); DeleteState = EnumUtils.GetEnum <ItemDeleteState>("ToBeDeleted"); } }
public AzureItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType) { ProtectionPolicyName = policyName; PolicyId = protectedItemResource.Properties.PolicyId; }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public AzureVmItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType, policyName) { AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties; LastBackupStatus = protectedItem.LastBackupStatus; LastBackupTime = protectedItem.LastBackupTime; ProtectionState = EnumUtils.GetEnum<ItemProtectionState>(protectedItem.ProtectionState.ToString()); ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus); VirtualMachineId = protectedItem.VirtualMachineId; HealthStatus = protectedItem.HealthStatus; DateOfPurge = null; DeleteState = EnumUtils.GetEnum<ItemDeleteState>("NotDeleted"); if (protectedItem.IsScheduledForDeferredDelete.HasValue) { DateOfPurge = protectedItem.DeferredDeleteTimeInUTC.Value.AddDays(14); DeleteState = EnumUtils.GetEnum<ItemDeleteState>("ToBeDeleted"); } if (protectedItem.ExtendedProperties != null && protectedItem.ExtendedProperties.DiskExclusionProperties != null) { DiskExclusionProperties diskExclusionProperties = protectedItem.ExtendedProperties.DiskExclusionProperties; IsInclusionList = diskExclusionProperties.IsInclusionList; DiskLunList = diskExclusionProperties.DiskLunList; } }
public void EnableAzureBackupProtectionTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace); ProtectedItemCreateOrUpdateRequest input = new ProtectedItemCreateOrUpdateRequest(); AzureIaaSClassicComputeVMProtectedItem iaasVmProtectedItem = new AzureIaaSClassicComputeVMProtectedItem(); iaasVmProtectedItem.PolicyId = ConfigurationManager.AppSettings["RsVaultIaasVMDefaultPolicyId"]; ProtectedItemResource protectedItemResource = new ProtectedItemResource(); protectedItemResource.Properties = iaasVmProtectedItem; input.Item = protectedItemResource; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasV1ContainerUniqueName"]; string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasV1ContainerUniqueName"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerName = containeType + ";" + containerUniqueName; string itemName = itemType + ";" + itemUniqueName; string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"]; string rsVaultRgName = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName); string rsVaultName = CommonTestHelper.GetSetting(TestConstants.RsVaultName); ProtectedItemTestHelper protectedItemTestHelper = new ProtectedItemTestHelper(client); var response = protectedItemTestHelper.AddOrUpdateProtectedItem(fabricName, containerName, itemName, input); } }
/// <summary> /// Creates a new protected item or updates an already existing protected item /// </summary> /// <param name="containerName">Name of the container which this item belongs to</param> /// <param name="protectedItemName">Name of the item</param> /// <param name="request">Protected item create or update request</param> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="auxiliaryAccessToken"></param> /// <param name="isMUAProtected"></param> /// <returns>Job created in the service for this operation</returns> public RestAzureNS.AzureOperationResponse <ProtectedItemResource> CreateOrUpdateProtectedItem( string containerName, string protectedItemName, ProtectedItemResource request, string vaultName = null, string resourceGroupName = null, string auxiliaryAccessToken = null, bool isMUAProtected = false) { Dictionary <string, List <string> > customHeaders = new Dictionary <string, List <string> >(); if (isMUAProtected) { List <ResourceGuardProxyBaseResource> resourceGuardMapping = ListResourceGuardMapping(vaultName, resourceGroupName); string operationRequest = null; if (resourceGuardMapping != null && resourceGuardMapping.Count != 0) { foreach (ResourceGuardOperationDetail operationDetail in resourceGuardMapping[0].Properties.ResourceGuardOperationDetails) { if (operationDetail.VaultCriticalOperation == "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/write") { operationRequest = operationDetail.DefaultResourceRequest; } } if (operationRequest != null) { request.Properties.ResourceGuardOperationRequests = new List <string>(); request.Properties.ResourceGuardOperationRequests.Add(operationRequest); } } if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { if (operationRequest != null) { customHeaders.Add("x-ms-authorization-auxiliary", new List <string> { "Bearer " + auxiliaryAccessToken }); } else { throw new ArgumentException(String.Format(Resources.UnexpectedParameterToken, "ModifyProtection")); } } } return(BmsAdapter.Client.ProtectedItems.CreateOrUpdateWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerName, protectedItemName, request, customHeaders, cancellationToken: BmsAdapter.CmdletCancellationToken).Result); }
/// <summary> /// Triggers the disable protection operation for the given item /// </summary> /// <returns>The job response returned from the service</returns> public RestAzureNS.AzureOperationResponse DisableProtection() { bool deleteBackupData = (bool)ProviderData[ItemParams.DeleteBackupData]; ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item]; AzureVmItem item = (AzureVmItem)ProviderData[ItemParams.Item]; // do validations ValidateAzureVMDisableProtectionRequest(itemBase); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); string containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); bool isComputeAzureVM = false; if (deleteBackupData) { return(ServiceClientAdapter.DeleteProtectedItem( containerUri, protectedItemUri)); } else { isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId); // construct Service Client protectedItem request AzureIaaSVMProtectedItem properties; if (isComputeAzureVM == false) { properties = new AzureIaaSClassicComputeVMProtectedItem(); } else { properties = new AzureIaaSComputeVMProtectedItem(); } properties.PolicyId = string.Empty; properties.ProtectionState = ProtectionState.ProtectionStopped; properties.SourceResourceId = item.SourceResourceId; ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties, }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest)); } }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public AzureSqlItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType) { AzureSqlProtectedItem protectedItem = (AzureSqlProtectedItem)protectedItemResource.Properties; ProtectedItemDataId = protectedItem.ProtectedItemDataId; ProtectionState = protectedItem.ProtectionState.ToString(); ProtectionPolicyName = policyName; }
public AzureVmItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType) { AzureIaaSVMProtectedItem protectedItem = (AzureIaaSVMProtectedItem)protectedItemResource.Properties; LastBackupStatus = protectedItem.LastBackupStatus; ProtectionPolicyName = policyName; ProtectionState = EnumUtils.GetEnum <ItemProtectionState>(protectedItem.ProtectionState); ProtectionStatus = EnumUtils.GetEnum <ItemProtectionStatus>(protectedItem.ProtectionStatus); VirtualMachineId = protectedItem.VirtualMachineId; }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public AzureFileShareItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType, policyName) { AzureFileshareProtectedItem protectedItem = (AzureFileshareProtectedItem)protectedItemResource.Properties; LastBackupStatus = protectedItem.LastBackupStatus; LastBackupTime = protectedItem.LastBackupTime; ProtectionState = EnumUtils.GetEnum <ItemProtectionState>(protectedItem.ProtectionState.ToString()); ProtectionStatus = EnumUtils.GetEnum <ItemProtectionStatus>(protectedItem.ProtectionStatus); }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public MabItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType, policyName) { MabFileFolderProtectedItem protectedItem = (MabFileFolderProtectedItem)protectedItemResource.Properties; LastBackupStatus = protectedItem.LastBackupStatus; LastBackupTime = protectedItem.LastBackupTime; ProtectionState = EnumUtils.GetEnum <ItemProtectionState>(protectedItem.ProtectionState.ToString()); FriendlyName = protectedItem.FriendlyName; }
public void EnableProtection(string vaultRgName, string vaultName, string policyId, string containerUri, string itemUri) { string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"]; ProtectedItemCreateOrUpdateRequest input = new ProtectedItemCreateOrUpdateRequest(); AzureIaaSClassicComputeVMProtectedItem iaasVmProtectedItem = new AzureIaaSClassicComputeVMProtectedItem(); iaasVmProtectedItem.PolicyId = policyId; ProtectedItemResource protectedItemResource = new ProtectedItemResource(); protectedItemResource.Properties = iaasVmProtectedItem; input.Item = protectedItemResource; AddOrUpdateProtectedItem(vaultRgName, vaultName, fabricName, containerUri, itemUri, input); }
/// <summary> /// Creates a new protected item or updates an already existing protected item /// </summary> /// <param name="containerName">Name of the container which this item belongs to</param> /// <param name="protectedItemName">Name of the item</param> /// <param name="request">Protected item create or update request</param> /// <returns>Job created in the service for this operation</returns> public RestAzureNS.AzureOperationResponse <ProtectedItemResource> CreateOrUpdateProtectedItem( string containerName, string protectedItemName, ProtectedItemResource request, string vaultName = null, string resourceGroupName = null) { return(BmsAdapter.Client.ProtectedItems.CreateOrUpdateWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerName, protectedItemName, request, cancellationToken: BmsAdapter.CmdletCancellationToken).Result); }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public AzureFileShareItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType, policyName) { AzureFileshareProtectedItem protectedItem = (AzureFileshareProtectedItem)protectedItemResource.Properties; LastBackupStatus = protectedItem.LastBackupStatus; LastBackupTime = protectedItem.LastBackupTime; ProtectionState = EnumUtils.GetEnum <ItemProtectionState>(protectedItem.ProtectionState.ToString()); ProtectionStatus = EnumUtils.GetEnum <ItemProtectionStatus>(protectedItem.ProtectionStatus); FriendlyName = protectedItem.FriendlyName; ResourceState = ""; if (protectedItem.ExtendedInfo != null && protectedItem.ExtendedInfo.ResourceState != null) { ResourceState = protectedItem.ExtendedInfo.ResourceState; } }
/// <summary> /// Constructor. Takes the service client object representing the protected item /// and converts it in to the PS protected item model /// </summary> /// <param name="protectedItemResource">Service client object representing the protected item resource</param> /// <param name="containerName">Name of the container associated with this protected item</param> /// <param name="containerType">Type of the container associated with this protected item</param> /// <param name="policyName">Name of the protection policy associated with this protected item</param> public AzureWorkloadSQLDatabaseProtectedItem(ProtectedItemResource protectedItemResource, string containerName, ContainerType containerType, string policyName) : base(protectedItemResource, containerName, containerType, policyName) { AzureVmWorkloadSQLDatabaseProtectedItem protectedItem = (AzureVmWorkloadSQLDatabaseProtectedItem)protectedItemResource.Properties; FriendlyName = protectedItem.FriendlyName; ServerName = protectedItem.ServerName; ParentName = protectedItem.ParentName; ParentType = protectedItem.ParentType; LastBackupErrorDetail = protectedItem.LastBackupErrorDetail; ProtectedItemDataSourceId = protectedItem.ProtectedItemDataSourceId; ProtectedItemHealthStatus = protectedItem.ProtectedItemHealthStatus; LastBackupStatus = protectedItem.LastBackupStatus; LastBackupTime = protectedItem.LastBackupTime; ProtectionState = EnumUtils.GetEnum <ItemProtectionState>(protectedItem.ProtectionState.ToString()); ProtectionStatus = EnumUtils.GetEnum <ItemProtectionStatus>(protectedItem.ProtectionStatus); }
public string EnableProtection(string containerName, string protectedItemName, string policyName) { ProtectionPolicyResource policy = GetPolicyWithRetries(policyName); BackupClient.ProtectionContainers.Refresh(VaultName, ResourceGroup, FabricName); ODataQuery <BMSPOQueryObject> query = new ODataQuery <BMSPOQueryObject>(po => po.BackupManagementType == BackupManagementType.AzureIaasVM); IPage <WorkloadProtectableItemResource> protectableItems = BackupClient.BackupProtectableItems.List(VaultName, ResourceGroup, odataQuery: query); var desiredProtectedItem = (AzureIaaSComputeVMProtectableItem)protectableItems.First( protectableItem => containerName.ToLower().Contains(protectableItem.Name.ToLower()) ).Properties; Assert.NotNull(desiredProtectedItem); var item = new ProtectedItemResource() { Properties = new AzureIaaSComputeVMProtectedItem() { PolicyId = policy.Id, SourceResourceId = desiredProtectedItem.VirtualMachineId, } }; var response = BackupClient.ProtectedItems.CreateOrUpdateWithHttpMessagesAsync( VaultName, ResourceGroup, FabricName, containerName, protectedItemName, item).Result; ValidateOperationResponse(response); var jobResponse = GetOperationResponse <ProtectedItemResource, OperationStatusJobExtendedInfo>( containerName, protectedItemName, response, operationId => BackupClient.ProtectedItemOperationResults.GetWithHttpMessagesAsync( VaultName, ResourceGroup, FabricName, containerName, protectedItemName, operationId).Result, operationId => BackupClient.ProtectedItemOperationStatuses.GetWithHttpMessagesAsync( VaultName, ResourceGroup, FabricName, containerName, protectedItemName, operationId).Result); Assert.NotNull(jobResponse.JobId); return(jobResponse.JobId); }
/// <summary> /// Enables backup of an item or to modifies the backup policy information of /// an already backed up item. This is an /// asynchronous operation. To know the status of the operation, call the /// GetItemOperationResult API. /// </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='fabricName'> /// Fabric name associated with the backup item. /// </param> /// <param name='containerName'> /// Container name associated with the backup item. /// </param> /// <param name='protectedItemName'> /// Item name to be backed up. /// </param> /// <param name='parameters'> /// resource backed up item /// </param> public static void CreateOrUpdate(this IProtectedItemsOperations operations, string vaultName, string resourceGroupName, string fabricName, string containerName, string protectedItemName, ProtectedItemResource parameters) { operations.CreateOrUpdateAsync(vaultName, resourceGroupName, fabricName, containerName, protectedItemName, parameters).GetAwaiter().GetResult(); }
/// <summary> /// Enables backup of an item or to modifies the backup policy information of /// an already backed up item. This is an /// asynchronous operation. To know the status of the operation, call the /// GetItemOperationResult API. /// </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='fabricName'> /// Fabric name associated with the backup item. /// </param> /// <param name='containerName'> /// Container name associated with the backup item. /// </param> /// <param name='protectedItemName'> /// Item name to be backed up. /// </param> /// <param name='parameters'> /// resource backed up item /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task CreateOrUpdateAsync(this IProtectedItemsOperations operations, string vaultName, string resourceGroupName, string fabricName, string containerName, string protectedItemName, ProtectedItemResource parameters, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.CreateOrUpdateWithHttpMessagesAsync(vaultName, resourceGroupName, fabricName, containerName, protectedItemName, parameters, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Triggers the enable protection operation for the given item /// </summary> /// <returns>The job response returned from the service</returns> public RestAzureNS.AzureOperationResponse EnableProtection() { string azureVMName = (string)ProviderData[ItemParams.AzureVMName]; string azureVMCloudServiceName = (string)ProviderData[ItemParams.AzureVMCloudServiceName]; string azureVMResourceGroupName = (string)ProviderData[ItemParams.AzureVMResourceGroupName]; string parameterSetName = (string)ProviderData[ItemParams.ParameterSetName]; PolicyBase policy = (PolicyBase)ProviderData[ItemParams.Policy]; ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item]; AzureVmItem item = (AzureVmItem)ProviderData[ItemParams.Item]; // do validations string containerUri = ""; string protectedItemUri = ""; bool isComputeAzureVM = false; string sourceResourceId = null; if (itemBase == null) { isComputeAzureVM = string.IsNullOrEmpty(azureVMCloudServiceName) ? true : false; string azureVMRGName = (isComputeAzureVM) ? azureVMResourceGroupName : azureVMCloudServiceName; ValidateAzureVMWorkloadType(policy.WorkloadType); ValidateAzureVMEnableProtectionRequest( azureVMName, azureVMCloudServiceName, azureVMResourceGroupName, policy); WorkloadProtectableItemResource protectableObjectResource = GetAzureVMProtectableObject(azureVMName, azureVMRGName, isComputeAzureVM); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableObjectResource.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, protectableObjectResource.Id); protectedItemUri = HelperUtils.GetProtectableItemUri( keyValueDict, protectableObjectResource.Id); IaaSVMProtectableItem iaasVmProtectableItem = (IaaSVMProtectableItem)protectableObjectResource.Properties; if (iaasVmProtectableItem != null) { sourceResourceId = iaasVmProtectableItem.VirtualMachineId; } } else { ValidateAzureVMWorkloadType(item.WorkloadType, policy.WorkloadType); ValidateAzureVMModifyProtectionRequest(itemBase, policy); isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); sourceResourceId = item.SourceResourceId; } // construct Service Client protectedItem request AzureIaaSVMProtectedItem properties; if (isComputeAzureVM == false) { properties = new AzureIaaSClassicComputeVMProtectedItem(); } else { properties = new AzureIaaSComputeVMProtectedItem(); } properties.PolicyId = policy.Id; properties.SourceResourceId = sourceResourceId; ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest)); }
/// <summary> /// Enables backup of an item or to modifies the backup policy information of /// an already backed up item. This is an /// asynchronous operation. To know the status of the operation, call the /// GetItemOperationResult API. /// </summary> /// <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='fabricName'> /// Fabric name associated with the backup item. /// </param> /// <param name='containerName'> /// Container name associated with the backup item. /// </param> /// <param name='protectedItemName'> /// Item name to be backed up. /// </param> /// <param name='parameters'> /// resource backed up item /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <ProtectedItemResource> > CreateOrUpdateWithHttpMessagesAsync(string vaultName, string resourceGroupName, string fabricName, string containerName, string protectedItemName, ProtectedItemResource parameters, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (vaultName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "vaultName"); } if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (fabricName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "fabricName"); } if (containerName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "containerName"); } if (protectedItemName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "protectedItemName"); } if (parameters == null) { throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); } string apiVersion = "2021-08-01"; // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("apiVersion", apiVersion); tracingParameters.Add("vaultName", vaultName); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("fabricName", fabricName); tracingParameters.Add("containerName", containerName); tracingParameters.Add("protectedItemName", protectedItemName); tracingParameters.Add("parameters", parameters); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "CreateOrUpdate", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}").ToString(); _url = _url.Replace("{vaultName}", System.Uri.EscapeDataString(vaultName)); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{fabricName}", System.Uri.EscapeDataString(fabricName)); _url = _url.Replace("{containerName}", System.Uri.EscapeDataString(containerName)); _url = _url.Replace("{protectedItemName}", System.Uri.EscapeDataString(protectedItemName)); List <string> _queryParameters = new List <string>(); if (apiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (parameters != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } System.Net.HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 202) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex = new CloudException(_errorBody.Message); ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_httpResponse.Headers.Contains("x-ms-request-id")) { ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <ProtectedItemResource>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <ProtectedItemResource>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
private RestAzureNS.AzureOperationResponse <ProtectedItemResource> EnableOrModifyProtection(bool disableWithRetentionData = false) { string vaultName = (string)ProviderData[VaultParams.VaultName]; string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; PolicyBase policy = ProviderData.ContainsKey(ItemParams.Policy) ? (PolicyBase)ProviderData[ItemParams.Policy] : null; ProtectableItemBase protectableItemBase = ProviderData.ContainsKey(ItemParams.ProtectableItem) ? (ProtectableItemBase)ProviderData[ItemParams.ProtectableItem] : null; AzureWorkloadProtectableItem protectableItem = ProviderData.ContainsKey(ItemParams.ProtectableItem) ? (AzureWorkloadProtectableItem)ProviderData[ItemParams.ProtectableItem] : null; ItemBase itemBase = ProviderData.ContainsKey(ItemParams.Item) ? (ItemBase)ProviderData[ItemParams.Item] : null; AzureWorkloadSQLDatabaseProtectedItem item = ProviderData.ContainsKey(ItemParams.Item) ? (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item] : null; AzureVmWorkloadSQLDatabaseProtectedItem properties = new AzureVmWorkloadSQLDatabaseProtectedItem(); string containerUri = ""; string protectedItemUri = ""; if (disableWithRetentionData) { //Disable protection while retaining backup data ValidateAzureWorkloadDisableProtectionRequest(itemBase); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); properties.PolicyId = string.Empty; properties.ProtectionState = ProtectionState.ProtectionStopped; properties.SourceResourceId = item.SourceResourceId; } else { if (protectableItem != null) { Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableItem.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, protectableItem.Id); protectedItemUri = HelperUtils.GetProtectableItemUri( keyValueDict, protectableItem.Id); properties.PolicyId = policy.Id; } else if (item != null) { Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri( keyValueDict, item.Id); properties.PolicyId = policy.Id; } } ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); }
private RestAzureNS.AzureOperationResponse <ProtectedItemResource> EnableOrModifyProtection(bool disableWithRetentionData = false) { string vaultName = (string)ProviderData[VaultParams.VaultName]; string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string azureFileShareName = ProviderData.ContainsKey(ItemParams.ItemName) ? (string)ProviderData[ItemParams.ItemName] : null; string storageAccountName = ProviderData.ContainsKey(ItemParams.StorageAccountName) ? (string)ProviderData[ItemParams.StorageAccountName] : null; string parameterSetName = ProviderData.ContainsKey(ItemParams.ParameterSetName) ? (string)ProviderData[ItemParams.ParameterSetName] : null; PolicyBase policy = ProviderData.ContainsKey(ItemParams.Policy) ? (PolicyBase)ProviderData[ItemParams.Policy] : null; ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item]; AzureFileShareItem item = (AzureFileShareItem)ProviderData[ItemParams.Item]; string containerUri = ""; string protectedItemUri = ""; string sourceResourceId = null; AzureFileshareProtectedItem properties = new AzureFileshareProtectedItem(); if (itemBase == null) { //Enable protection ValidateAzureFilesWorkloadType(policy.WorkloadType); ValidateFileShareEnableProtectionRequest( azureFileShareName, storageAccountName); WorkloadProtectableItemResource protectableObjectResource = GetAzureFileShareProtectableObject( azureFileShareName, storageAccountName, vaultName: vaultName, vaultResourceGroupName: vaultResourceGroupName); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableObjectResource.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, protectableObjectResource.Id); protectedItemUri = HelperUtils.GetProtectableItemUri( keyValueDict, protectableObjectResource.Id); AzureFileShareProtectableItem azureFileShareProtectableItem = (AzureFileShareProtectableItem)protectableObjectResource.Properties; if (azureFileShareProtectableItem != null) { sourceResourceId = azureFileShareProtectableItem.ParentContainerFabricId; } // construct Service Client protectedItem request properties.PolicyId = policy.Id; properties.SourceResourceId = sourceResourceId; } else if (itemBase != null && !disableWithRetentionData) { //modify policy with new policy ValidateAzureFilesWorkloadType(item.WorkloadType, policy.WorkloadType); ValidateAzureFilesModifyProtectionRequest(itemBase, policy); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); sourceResourceId = item.SourceResourceId; // construct Service Client protectedItem request properties.PolicyId = policy.Id; properties.SourceResourceId = sourceResourceId; } else if (disableWithRetentionData) { //Disable protection while retaining backup data ValidateAzureFileShareDisableProtectionRequest(itemBase); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); properties.PolicyId = string.Empty; properties.ProtectionState = ProtectionState.ProtectionStopped; properties.SourceResourceId = item.SourceResourceId; } ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); }