Azure VM specific recovery point class.
Наследование: RecoveryPointBase
Пример #1
0
        /// <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();
            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,
            };

            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, 
                containerUri, 
                protectedItemUri, 
                recoveryPointId, 
                triggerRestoreRequest, 
                BmsAdapter.CmdletCancellationToken).Result;

            return response;
        }
        /// <summary>
        /// Helper function to convert ps recovery points list model from service response.
        /// </summary>
        public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
            ServiceClientModel.RecoveryPointListResponse rpList,
            ItemBase item)
        {
            if (rpList == null || rpList.RecoveryPointList == null ||
                rpList.RecoveryPointList.RecoveryPoints == null)
            {
                throw new ArgumentNullException("RPList");
            }

            Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            List<RecoveryPointBase> result = new List<RecoveryPointBase>();
            foreach (ServiceClientModel.RecoveryPointResource rp in rpList.RecoveryPointList.RecoveryPoints)
            {
                if (rp.Properties.GetType() == typeof(ServiceClientModel.RecoveryPoint))
                {
                    ServiceClientModel.RecoveryPoint recPoint =
                        rp.Properties as ServiceClientModel.RecoveryPoint;

                    DateTime recPointTime = DateTime.ParseExact(
                        recPoint.RecoveryPointTime,
                        @"MM/dd/yyyy HH:mm:ss",
                        CultureInfo.InvariantCulture);

                    AzureVmRecoveryPoint rpBase = new AzureVmRecoveryPoint()
                    {
                        RecoveryPointId = rp.Name,
                        BackupManagementType = item.BackupManagementType,
                        ItemName = protectedItemName,
                        ContainerName = containerUri,
                        ContainerType = item.ContainerType,
                        RecoveryPointTime = recPointTime,
                        RecoveryPointType = recPoint.RecoveryPointType,
                        Id = rp.Id,
                        WorkloadType = item.WorkloadType,
                        RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                        SourceVMStorageType = recPoint.SourceVMStorageType,
                        SourceResourceId = item.SourceResourceId,
                        EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ?
                            recPoint.IsSourceVMEncrypted.Value : false,
                        IlrSessionActive = recPoint.IsInstantILRSessionActive,
                    };

                    if (rpBase.EncryptionEnabled)
                    {
                        rpBase.KeyAndSecretDetails = new KeyAndSecretDetails()
                        {
                            SecretUrl = recPoint.KeyAndSecret.BekDetails.SecretUrl,
                            KeyUrl = recPoint.KeyAndSecret.KekDetails.KeyUrl,
                            SecretData = recPoint.KeyAndSecret.BekDetails.SecretData,
                            KeyBackupData = recPoint.KeyAndSecret.KekDetails.KeyBackupData,
                            KeyVaultId = recPoint.KeyAndSecret.KekDetails.KeyVaultId,
                            SecretVaultId = recPoint.KeyAndSecret.BekDetails.SecretVaultId,
                        };
                    }

                    result.Add(rpBase);
                }

                if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
                {
                    ServiceClientModel.GenericRecoveryPoint recPoint =
                        rp.Properties as ServiceClientModel.GenericRecoveryPoint;

                    DateTime recPointTime = DateTime.ParseExact(
                        recPoint.RecoveryPointTime,
                        @"MM/dd/yyyy HH:mm:ss",
                        CultureInfo.InvariantCulture);

                    AzureSqlRecoveryPoint rpBase = new AzureSqlRecoveryPoint()
                    {
                        RecoveryPointId = rp.Name,
                        BackupManagementType = item.BackupManagementType,
                        ItemName = protectedItemName,
                        ContainerName = containerUri,
                        ContainerType = item.ContainerType,
                        RecoveryPointTime = recPointTime,
                        RecoveryPointType = recPoint.RecoveryPointType,
                        Id = rp.Id,
                        WorkloadType = item.WorkloadType,
                        RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                        FriendlyName = recPoint.FriendlyName,
                    };

                    result.Add(rpBase);
                }
            }

            return result;
        }
Пример #3
0
        /// <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;
        }