Esempio n. 1
0
        private BackupStoreInformation  GetBackupStoreInformationFromBackupStorage(BackupStorage backupStorage)
        {
            BackupStoreInformation storeInformation;

            switch (backupStorage.BackupStorageType)
            {
            case BackupStorageType.AzureBlobStore:
                var azureStorage = (AzureBlobBackupStorageInfo)backupStorage;
                storeInformation = new AzureBlobBackupStore
                {
                    ConnectionString      = azureStorage.ConnectionString,
                    ContainerName         = azureStorage.ContainerName,
                    FolderPath            = UtilityHelper.GetBaseDirectoryPathForPartition(this.ServiceUri, this.PartitionId),             // TODO: This should be constructed
                    IsAccountKeyEncrypted = azureStorage.IsConnectionStringEncrypted,
                };
                break;

            case BackupStorageType.DsmsAzureBlobStore:
                var dsmsAzureStorage = (DsmsAzureBlobBackupStorageInfo)backupStorage;
                storeInformation = new DsmsAzureBlobBackupStore
                {
                    StorageCredentialsSourceLocation = dsmsAzureStorage.StorageCredentialsSourceLocation,
                    ContainerName = dsmsAzureStorage.ContainerName,
                    FolderPath    = UtilityHelper.GetBaseDirectoryPathForPartition(this.ServiceUri, this.PartitionId),
                };
                break;

            case BackupStorageType.FileShare:
                var fileShareStorage = (FileShareBackupStorageInfo)backupStorage;
                storeInformation = new FileShareBackupStore
                {
                    AccessType          = String.IsNullOrEmpty(fileShareStorage.PrimaryUserName) ? FileShareAccessType.None : FileShareAccessType.DomainUser,
                    FileSharePath       = Path.Combine(fileShareStorage.Path, UtilityHelper.GetBaseDirectoryPathForPartition(this.ServiceUri, this.PartitionId)),
                    PrimaryUserName     = fileShareStorage.PrimaryUserName,
                    PrimaryPassword     = fileShareStorage.PrimaryPassword,
                    SecondaryUserName   = fileShareStorage.SecondaryUserName,
                    SecondaryPassword   = fileShareStorage.SecondaryPassword,
                    IsPasswordEncrypted = fileShareStorage.IsPasswordEncrypted,
                };
                break;

            default:
                throw new ArgumentException(string.Format("{0} not supported.", backupStorage.BackupStorageType));
            }

            return(storeInformation);
        }
        private BackupPolicyDataStructure GetBackupPolicyDataStructure(BackupPolicy backupPolicyModel, string serviceName, string partitionId)
        {
            BackupPolicyDataStructure backupPolicy;

            switch (backupPolicyModel.BackupSchedule.BackupScheduleType)
            {
            case BackupScheduleType.FrequencyBased:
                backupPolicy = new FrequencyBasedBackupPolicy();
                var frequencyBasedSchedulePolicy = (FrequencyBasedBackupSchedule)backupPolicyModel.BackupSchedule;
                backupPolicy.PolicyType = BackupPolicyType.FrequencyBased;
                var freqBackupPolicy = (FrequencyBasedBackupPolicy)backupPolicy;
                freqBackupPolicy.RunFrequency = (ushort)frequencyBasedSchedulePolicy.Interval;

                if (frequencyBasedSchedulePolicy.IntervalType == BackupScheduleInterval.Hours)
                {
                    freqBackupPolicy.RunFrequencyType = BackupPolicyRunFrequency.Hours;
                }

                if (frequencyBasedSchedulePolicy.IntervalType == BackupScheduleInterval.Minutes)
                {
                    freqBackupPolicy.RunFrequencyType = BackupPolicyRunFrequency.Minutes;
                }

                break;

            case BackupScheduleType.TimeBased:
                backupPolicy = new ScheduleBasedBackupPolicy();
                var scheduleBasedSchedulePolicy = (TimeBasedBackupSchedule)backupPolicyModel.BackupSchedule;
                backupPolicy.PolicyType = BackupPolicyType.ScheduleBased;

                var schdBackupPolicy = (ScheduleBasedBackupPolicy)backupPolicy;
                if (scheduleBasedSchedulePolicy.ScheduleFrequencyType == BackupScheduleFrequency.Daily)
                {
                    schdBackupPolicy.RunSchedule = BackupPolicyRunSchedule.Daily;
                }

                if (scheduleBasedSchedulePolicy.ScheduleFrequencyType == BackupScheduleFrequency.Weekly)
                {
                    schdBackupPolicy.RunSchedule = BackupPolicyRunSchedule.Weekly;
                }

                schdBackupPolicy.RunDays  = new List <DayOfWeek>(scheduleBasedSchedulePolicy.RunDays);
                schdBackupPolicy.RunTimes = new List <TimeSpan>(scheduleBasedSchedulePolicy.RunTimes);

                break;

            default:
                throw new FabricPeriodicBackupNotEnabledException();
            }

            backupPolicy.MaxIncrementalBackups = Convert.ToByte(backupPolicyModel.MaxIncrementalBackup);
            backupPolicy.Name     = backupPolicyModel.Name;
            backupPolicy.PolicyId = backupPolicyModel.UniqueId;

            switch (backupPolicyModel.Storage.BackupStorageType)
            {
            case BackupStorageType.FileShare:
                var fileShareStorage = (FileShareBackupStorageInfo)backupPolicyModel.Storage;
                backupPolicy.StoreInformation = new FileShareBackupStore
                {
                    AccessType          = String.IsNullOrEmpty(fileShareStorage.PrimaryUserName) ? FileShareAccessType.None : FileShareAccessType.DomainUser,
                    FileSharePath       = Path.Combine(fileShareStorage.Path, UtilityHelper.GetBaseDirectoryPathForPartition(serviceName, partitionId)),
                    PrimaryUserName     = fileShareStorage.PrimaryUserName,
                    PrimaryPassword     = fileShareStorage.PrimaryPassword,
                    SecondaryUserName   = fileShareStorage.SecondaryUserName,
                    SecondaryPassword   = fileShareStorage.SecondaryPassword,
                    IsPasswordEncrypted = fileShareStorage.IsPasswordEncrypted,
                };
                break;

            case BackupStorageType.AzureBlobStore:
                var azureStorage = (AzureBlobBackupStorageInfo)backupPolicyModel.Storage;
                backupPolicy.StoreInformation = new AzureBlobBackupStore
                {
                    ConnectionString      = azureStorage.ConnectionString,
                    ContainerName         = azureStorage.ContainerName,
                    FolderPath            = UtilityHelper.GetBaseDirectoryPathForPartition(serviceName, partitionId),             // TODO: This should be constructed
                    IsAccountKeyEncrypted = azureStorage.IsConnectionStringEncrypted,
                };
                break;

            case BackupStorageType.DsmsAzureBlobStore:
                var dsmsAzureStorage = (DsmsAzureBlobBackupStorageInfo)backupPolicyModel.Storage;
                backupPolicy.StoreInformation = new DsmsAzureBlobBackupStore
                {
                    StorageCredentialsSourceLocation = dsmsAzureStorage.StorageCredentialsSourceLocation,
                    ContainerName = dsmsAzureStorage.ContainerName,
                    FolderPath    = UtilityHelper.GetBaseDirectoryPathForPartition(serviceName, partitionId),                     // TODO: This should be constructed
                };
                break;
            }

            return(backupPolicy);
        }