public JobListResponse GetJobs( string jobId, string status, string operation, DateTime startTime, DateTime endTime, string backupManagementType, int?top = null, string skipToken = null) { string resourceName = BmsAdapter.GetResourceName(); string resourceGroupName = BmsAdapter.GetResourceGroupName(); // build pagination request PaginationRequest pagReq = new PaginationRequest() { SkipToken = skipToken }; // respecting top if provided if (top.HasValue) { pagReq.Top = top.ToString(); } CommonJobQueryFilters commonFilters = GetQueryObject( backupManagementType, startTime, endTime, jobId, status, operation); return(BmsAdapter.Client.Jobs.ListAsync( resourceGroupName, resourceName, commonFilters, pagReq, BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result); }
/// <summary> /// Revoke access for item level recovery connection identified by the input parameters /// </summary> /// <param name="containerName">Name of the container which the item belongs to</param> /// <param name="protectedItemName">Name of the item</param> /// <param name="recoveryPointId">ID of the recovery point</param> /// <returns>Azure operation response returned by the service</returns> public RestAzureNS.AzureOperationResponse RevokeItemLevelRecoveryAccess ( string containerName, string protectedItemName, string recoveryPointId ) { string resourceGroupName = BmsAdapter.GetResourceGroupName(); string resourceName = BmsAdapter.GetResourceName(); var response = BmsAdapter.Client.ItemLevelRecoveryConnections.RevokeWithHttpMessagesAsync( resourceName, resourceGroupName, AzureFabricName, containerName, protectedItemName, recoveryPointId, cancellationToken: BmsAdapter.CmdletCancellationToken).Result; return(response); }
/// <summary> /// Lists protectable items according to the query filter and the pagination params /// </summary> /// <param name="queryFilter">Query filter</param> /// <param name="skipToken">Skip token for pagination</param> /// <returns>List of protectable items</returns> public List <WorkloadProtectableItemResource> ListProtectableItem( ODataQuery <BMSPOQueryObject> queryFilter, string skipToken = default(string)) { string resourceName = BmsAdapter.GetResourceName(); string resourceGroupName = BmsAdapter.GetResourceGroupName(); Func <RestAzureNS.IPage <WorkloadProtectableItemResource> > listAsync = () => BmsAdapter.Client.ProtectableItems.ListWithHttpMessagesAsync( BmsAdapter.GetResourceName(), BmsAdapter.GetResourceGroupName(), queryFilter, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; Func <string, RestAzureNS.IPage <WorkloadProtectableItemResource> > listNextAsync = nextLink => BmsAdapter.Client.ProtectableItems.ListNextWithHttpMessagesAsync( nextLink, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; return(HelperUtils.GetPagedList(listAsync, listNextAsync)); }
/// <summary> /// Fetches backup engines in the vault according to the query params /// </summary> /// <param name="queryParams">Query parameters</param> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <returns>List of backup engines</returns> public IEnumerable <BackupEngineBaseResource> ListBackupEngines( ODataQuery <BMSBackupEnginesQueryObject> queryParams, string vaultName = null, string resourceGroupName = null) { queryParams.Top = 200; Func <RestAzureNS.IPage <BackupEngineBaseResource> > listAsync = () => BmsAdapter.Client.BackupEngines.ListWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), queryParams, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; Func <string, RestAzureNS.IPage <BackupEngineBaseResource> > listNextAsync = nextLink => BmsAdapter.Client.BackupEngines.ListNextWithHttpMessagesAsync( nextLink, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; var listResponse = HelperUtils.GetPagedList(listAsync, listNextAsync); return(listResponse); }
/// <summary> /// List protection intents /// </summary> /// <param name="queryFilter"></param> /// <param name="skipToken"></param> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <returns>List of protection intents resource</returns> public List <ProtectionIntentResource> ListProtectionIntent( ODataQuery <ProtectionIntentQueryObject> queryFilter, string skipToken = default(string), string vaultName = null, string resourceGroupName = null) { Func <RestAzureNS.IPage <ProtectionIntentResource> > listAsync = () => BmsAdapter.Client.BackupProtectionIntent.ListWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), queryFilter, skipToken, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; Func <string, RestAzureNS.IPage <ProtectionIntentResource> > listNextAsync = nextLink => BmsAdapter.Client.BackupProtectionIntent.ListNextWithHttpMessagesAsync( nextLink, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; return(HelperUtils.GetPagedList(listAsync, listNextAsync)); }
/// <summary> /// Gets detail about the recovery point identified by the input parameters /// </summary> /// <param name="containerName">Name of the container which the item belongs to</param> /// <param name="protectedItemName">Name of the item</param> /// <param name="recoveryPointId">ID of the recovery point</param> /// <returns>Recovery point response returned by the service</returns> public RecoveryPointResource GetRecoveryPointDetails ( string containerName, string protectedItemName, string recoveryPointId ) { string resourceGroupName = BmsAdapter.GetResourceGroupName(); string resourceName = BmsAdapter.GetResourceName(); var response = BmsAdapter.Client.RecoveryPoints.GetWithHttpMessagesAsync( resourceName, resourceGroupName, AzureFabricName, containerName, protectedItemName, recoveryPointId, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; return(response); }
/// <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> /// <param name="expiryDateTimeUtc">Date when the recovery points created by this backup operation will expire</param> /// <returns>Job created by this operation</returns> public RestAzureNS.AzureOperationResponse TriggerBackup( string containerName, string itemName, DateTime?expiryDateTimeUtc, string vaultName = null, string resourceGroupName = null) { BackupRequestResource triggerBackupRequest = new BackupRequestResource(); IaasVMBackupRequest iaasVmBackupRequest = new IaasVMBackupRequest(); iaasVmBackupRequest.RecoveryPointExpiryTimeInUTC = expiryDateTimeUtc; triggerBackupRequest.Properties = iaasVmBackupRequest; return(BmsAdapter.Client.Backups.TriggerWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerName, itemName, triggerBackupRequest, cancellationToken: BmsAdapter.CmdletCancellationToken).Result); }
/// <summary> /// Lists recovery points according to the input parameters /// </summary> /// <param name="containerName">Name of the container which the item belongs to</param> /// <param name="protectedItemName">Name of the item</param> /// <param name="queryFilter">Query filter</param> /// <returns>List of recovery points</returns> public RecoveryPointListResponse GetRecoveryPoints ( string containerName, string protectedItemName, RecoveryPointQueryParameters queryFilter ) { string resourceGroupName = BmsAdapter.GetResourceGroupName(); string resourceName = BmsAdapter.GetResourceName(); var response = BmsAdapter.Client.RecoveryPoints.ListAsync( resourceGroupName, resourceName, BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, containerName, protectedItemName, queryFilter, BmsAdapter.CmdletCancellationToken).Result; return(response); }
/// <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> /// List protected items protected from secondary region by the Recovery Services vault according to the query params /// and pagination params. /// </summary> /// <param name="queryFilter">Query params</param> /// <param name="skipToken">Skip token used for pagination</param> /// <returns>List of protected items</returns> public List <CrrModel.ProtectedItemResource> ListProtectedItemCrr( ODataQuery <CrrModel.ProtectedItemQueryObject> queryFilter, string skipToken = default(string), string vaultName = null, string resourceGroupName = null) { Func <RestAzureNS.IPage <CrrModel.ProtectedItemResource> > listAsync = () => CrrAdapter.Client.BackupProtectedItemsCrr.ListWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), queryFilter, skipToken, cancellationToken: CrrAdapter.CmdletCancellationToken).Result.Body; Func <string, RestAzureNS.IPage <CrrModel.ProtectedItemResource> > listNextAsync = nextLink => CrrAdapter.Client.BackupProtectedItemsCrr.ListNextWithHttpMessagesAsync( nextLink, cancellationToken: CrrAdapter.CmdletCancellationToken).Result.Body; var result = HelperUtils.GetPagedListCrr(listAsync, listNextAsync); return(result); }
/// <summary> /// Lists workload items according to the query filter and the pagination params /// </summary> /// <param name="containrName">Query filter</param> /// <param name="queryFilter">Query filter</param> /// <param name="skipToken">Skip token for pagination</param> /// <returns>List of protectable items</returns> public List <WorkloadItemResource> ListWorkloadItem( string containerName, ODataQuery <BMSWorkloadItemQueryObject> queryFilter, string skipToken = default(string), string vaultName = null, string resourceGroupName = null) { Func <RestAzureNS.IPage <WorkloadItemResource> > listAsync = () => BmsAdapter.Client.BackupWorkloadItems.ListWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerName, queryFilter, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; Func <string, RestAzureNS.IPage <WorkloadItemResource> > listNextAsync = nextLink => BmsAdapter.Client.BackupWorkloadItems.ListNextWithHttpMessagesAsync( nextLink, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; return(HelperUtils.GetPagedList(listAsync, listNextAsync)); }
/// <summary> /// provision item level recovery connection identified by the input parameters /// </summary> /// <param name="containerName">Name of the container which the item belongs to</param> /// <param name="protectedItemName">Name of the item</param> /// <param name="recoveryPointId">ID of the recovery point</param> /// <param name="registrationRequest">registration request for ILR</param> /// <returns>Azure operation response returned by the service</returns> public RestAzureNS.AzureOperationResponse ProvisioninItemLevelRecoveryAccess( string containerName, string protectedItemName, string recoveryPointId, ILRRequest registrationRequest, string vaultName = null, string resourceGroupName = null) { ILRRequestResource provisionRequest = new ILRRequestResource(); provisionRequest.Properties = registrationRequest; var response = BmsAdapter.Client.ItemLevelRecoveryConnections.ProvisionWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerName, protectedItemName, recoveryPointId, provisionRequest, cancellationToken: BmsAdapter.CmdletCancellationToken).Result; return(response); }
/// <summary> /// Method to fetch resource guard proxy. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="resourceGuardProxyName"></param> /// <returns></returns> public ResourceGuardProxyBaseResource GetResourceGuardMapping(string vaultName, string resourceGroupName, string resourceGuardProxyName) { return(BmsAdapter.Client.ResourceGuardProxy.GetWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), resourceGuardProxyName).Result.Body); }
/// <summary> /// Restores the disk based on the recovery point and other input parameters /// </summary> /// <param name="rp">Recovery point to restore the disk to</param> /// <param name="storageAccountId">ID of the storage account where to restore the disk</param> /// <param name="storageAccountLocation">Location of the storage account where to restore the disk</param> /// <param name="storageAccountType">Type of the storage account where to restore the disk</param> /// <returns>Job created by this operation</returns> public RestAzureNS.AzureOperationResponse RestoreDisk( AzureVmRecoveryPoint rp, string storageAccountId, string storageAccountLocation, string storageAccountType, bool osaOption, string vaultName = null, string resourceGroupName = null, string vaultLocation = null) { var useOsa = ShouldUseOsa(rp, osaOption); vaultLocation = vaultLocation ?? BmsAdapter.GetResourceLocation(); Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id); string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id); string recoveryPointId = rp.RecoveryPointId; //validtion block if (storageAccountLocation != vaultLocation) { throw new Exception(Resources.RestoreDiskIncorrectRegion); } string vmType = containerUri.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute"; string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts", StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute"; if (vmType != strType) { throw new Exception(string.Format(Resources.RestoreDiskStorageTypeError, vmType)); } IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest() { CreateNewCloudService = false, RecoveryPointId = recoveryPointId, RecoveryType = RecoveryType.RestoreDisks, Region = vaultLocation, StorageAccountId = storageAccountId, SourceResourceId = rp.SourceResourceId, OriginalStorageAccountOption = useOsa, }; RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource(); triggerRestoreRequest.Properties = restoreRequest; var response = BmsAdapter.Client.Restores.TriggerWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerUri, protectedItemUri, recoveryPointId, triggerRestoreRequest, cancellationToken: BmsAdapter.CmdletCancellationToken).Result; return(response); }
/// <summary> /// Method to create resource guard proxy. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="resourceGuardProxyName"></param> /// <param name="param"></param> /// <param name="auxiliaryAccessToken"></param> /// <returns></returns> public ResourceGuardProxyBaseResource CreateResourceGuardMapping(string vaultName, string resourceGroupName, string resourceGuardProxyName, ResourceGuardProxyBaseResource param, string auxiliaryAccessToken) { Dictionary <string, List <string> > customHeaders = new Dictionary <string, List <string> >(); if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { customHeaders.Add("x-ms-authorization-auxiliary", new List <string> { "Bearer " + auxiliaryAccessToken }); } return(BmsAdapter.Client.ResourceGuardProxy.PutWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), resourceGuardProxyName, param, customHeaders).Result.Body); }
/// <summary> /// Deletes a 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="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="auxiliaryAccessToken"></param> /// <param name="protectedItemUri"></param> /// <returns>Job created in the service for this operation</returns> public RestAzureNS.AzureOperationResponse DeleteProtectedItem( string containerName, string protectedItemName, string vaultName = null, string resourceGroupName = null, string auxiliaryAccessToken = null, string protectedItemUri = null) { Dictionary <string, List <string> > customHeaders = new Dictionary <string, List <string> >(); if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { customHeaders.Add("x-ms-authorization-auxiliary", new List <string> { "Bearer " + auxiliaryAccessToken }); } string operationRequest = null; // unlock UnlockDeleteRequest unlockDeleteRequest = new UnlockDeleteRequest(); List <ResourceGuardProxyBaseResource> resourceGuardMapping = ListResourceGuardMapping(vaultName, resourceGroupName); if (resourceGuardMapping != null && resourceGuardMapping.Count != 0) { foreach (ResourceGuardOperationDetail operationDetail in resourceGuardMapping[0].Properties.ResourceGuardOperationDetails) { if (operationDetail.VaultCriticalOperation == "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/delete") { operationRequest = operationDetail.DefaultResourceRequest; } } if (operationRequest != null) { unlockDeleteRequest.ResourceGuardOperationRequests = new List <string>(); unlockDeleteRequest.ResourceGuardOperationRequests.Add(operationRequest); if (protectedItemUri == null) { throw new ArgumentException(String.Format(Resources.ProtectedItemURICantBeNull)); } unlockDeleteRequest.ResourceToBeDeleted = protectedItemUri; UnlockDeleteResponse unlockDeleteResponse = BmsAdapter.Client.ResourceGuardProxy.UnlockDeleteWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), resourceGuardMapping[0].Name, unlockDeleteRequest, customHeaders).Result.Body; } else if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { throw new ArgumentException(String.Format(Resources.UnexpectedParameterToken, "Delete protection with DeleteBackupData")); } } else if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { throw new ArgumentException(String.Format(Resources.UnexpectedParameterToken, "Delete protection with DeleteBackupData")); } return(BmsAdapter.Client.ProtectedItems.DeleteWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerName, protectedItemName, cancellationToken: BmsAdapter.CmdletCancellationToken).Result); }
/// <summary> /// Method to delete resource guard proxy. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <param name="resourceGuardProxyName"></param> /// <param name="auxiliaryAccessToken"></param> /// <returns></returns> public RestAzureNS.AzureOperationResponse DeleteResourceGuardMapping(string vaultName, string resourceGroupName, string resourceGuardProxyName, string auxiliaryAccessToken) { Dictionary <string, List <string> > customHeaders = new Dictionary <string, List <string> >(); string operationRequest = null; if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { customHeaders.Add("x-ms-authorization-auxiliary", new List <string> { "Bearer " + auxiliaryAccessToken }); } // unlock UnlockDeleteRequest unlockDeleteRequest = new UnlockDeleteRequest(); List <ResourceGuardProxyBaseResource> resourceGuardMapping = ListResourceGuardMapping(vaultName, resourceGroupName); if (resourceGuardMapping != null && resourceGuardMapping.Count != 0) { foreach (ResourceGuardOperationDetail operationDetail in resourceGuardMapping[0].Properties.ResourceGuardOperationDetails) { if (operationDetail.VaultCriticalOperation == "Microsoft.RecoveryServices/vaults/backupResourceGuardProxies/delete") { operationRequest = operationDetail.DefaultResourceRequest; } } if (operationRequest != null) { unlockDeleteRequest.ResourceGuardOperationRequests = new List <string>(); unlockDeleteRequest.ResourceGuardOperationRequests.Add(operationRequest); UnlockDeleteResponse unlockDeleteResponse = BmsAdapter.Client.ResourceGuardProxy.UnlockDeleteWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), resourceGuardProxyName, unlockDeleteRequest, customHeaders).Result.Body; } } else if (auxiliaryAccessToken != null && auxiliaryAccessToken != "") { throw new ArgumentException(String.Format(Resources.ResourceGuardMappingNotFound)); } return(BmsAdapter.Client.ResourceGuardProxy.DeleteWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), resourceGuardProxyName).Result); }
/// <summary> /// Method to fetch resource guard proxy list. /// </summary> /// <param name="vaultName"></param> /// <param name="resourceGroupName"></param> /// <returns></returns> public List <ResourceGuardProxyBaseResource> ListResourceGuardMapping(string vaultName, string resourceGroupName) { Func <RestAzureNS.IPage <ResourceGuardProxyBaseResource> > proxyPagedList = () => BmsAdapter.Client.ResourceGuardProxies.GetWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName()).Result.Body; Func <string, RestAzureNS.IPage <ResourceGuardProxyBaseResource> > proxyPagedListNext = nextLink => BmsAdapter.Client.ResourceGuardProxies.GetNextWithHttpMessagesAsync( nextLink, cancellationToken: BmsAdapter.CmdletCancellationToken).Result.Body; var proxyList = HelperUtils.GetPagedList(proxyPagedList, proxyPagedListNext); return(proxyList); }
/// <summary> /// Gets the access token for CRR operation /// </summary> /// <param name="rp">Recovery point to restore the disk to</param> /// <param name="secondaryRegion">secondary region where to trigger the restore</param> /// <param name="vaultName">Name of recovery services vault</param> /// <param name="resourceGroupName">Name of the vault resource group</param> /// <returns>CRR access token</returns> public CrrAccessToken GetCRRAccessToken( AzureRecoveryPoint rp, string secondaryRegion, string vaultName = null, string resourceGroupName = null) { Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id); string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id); string recoveryPointId = rp.RecoveryPointId; AADPropertiesResource userInfo = GetAADProperties(secondaryRegion); var accessToken = BmsAdapter.Client.RecoveryPoints.GetAccessTokenWithHttpMessagesAsync(vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName(), AzureFabricName, containerUri, protectedItemUri, recoveryPointId, userInfo).Result.Body; return(accessToken.Properties); }
public BackupResourceVaultConfigResource GetVaultProperty(string vaultName, string resourceGroupName) { return(BmsAdapter.Client.BackupResourceVaultConfigs.GetWithHttpMessagesAsync( vaultName ?? BmsAdapter.GetResourceName(), resourceGroupName ?? BmsAdapter.GetResourceGroupName()).Result.Body); }
/// <summary> /// Restores the disk based on the recovery point and other input parameters /// </summary> /// <param name="rp">Recovery point to restore the disk to</param> /// <param name="storageAccountId">ID of the storage account where to restore the disk</param> /// <param name="storageAccountLocation">Location of the storage account where to restore the disk</param> /// <param name="storageAccountType">Type of the storage account where to restore the disk</param> /// <returns>Job created by this operation</returns> public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, string storageAccountId, string storageAccountLocation, string storageAccountType) { string resourceGroupName = BmsAdapter.GetResourceGroupName(); string resourceName = BmsAdapter.GetResourceName(); string vaultLocation = BmsAdapter.GetResourceLocation(); string containerName = rp.ContainerName; string protectedItemName = rp.ItemName; string recoveryPointId = rp.RecoveryPointId; //validtion block if (storageAccountLocation != vaultLocation) { throw new Exception(Resources.RestoreDiskIncorrectRegion); } string vmType = containerName.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute"; string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts", StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute"; if (vmType != strType) { throw new Exception(String.Format(Resources.RestoreDiskStorageTypeError, vmType)); } IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest() { CreateNewCloudService = false, RecoveryPointId = recoveryPointId, RecoveryType = RecoveryType.RestoreDisks, Region = vaultLocation, StorageAccountId = storageAccountId, SourceResourceId = rp.SourceResourceId, }; if (rp.EncryptionEnabled) { restoreRequest.EncryptionDetails = new EncryptionDetails() { EncryptionEnabled = rp.EncryptionEnabled, KekUrl = rp.KeyAndSecretDetails.KeyUrl, KekVaultId = rp.KeyAndSecretDetails.KeyVaultId, SecretKeyUrl = rp.KeyAndSecretDetails.SecretUrl, SecretKeyVaultId = rp.KeyAndSecretDetails.SecretVaultId, }; } TriggerRestoreRequest triggerRestoreRequest = new TriggerRestoreRequest(); triggerRestoreRequest.Item = new RestoreRequestResource(); triggerRestoreRequest.Item.Properties = new RestoreRequest(); triggerRestoreRequest.Item.Properties = restoreRequest; var response = BmsAdapter.Client.Restores.TriggerRestoreAsync( resourceGroupName, resourceName, BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, containerName, protectedItemName, recoveryPointId, triggerRestoreRequest, BmsAdapter.CmdletCancellationToken).Result; return(response); }