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); }
public async Task <RestorePointDetails> GetRestorePointDetailsAsync(BackupPartitionInfo backupPartitionInfo, TimeSpan timeout, CancellationToken cancellationToken) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "GetRestorePointDetailsAsync invoked for partition {0}", backupPartitionInfo.PartitionId); var restoreStore = await RestoreStore.CreateOrGetRestoreStatusStore(this.statefulService); var backupMappingStore = await BackupMappingStore.CreateOrGetBackupMappingStore(this.statefulService); var backupPolicyStore = await BackupPolicyStore.CreateOrGetBackupPolicyStore(this.statefulService); bool userInitiatedOperation; BackupStorage backupStorage; BackupStoreInformation backupStoreInformation = null; List <string> backupLocations; string brsServiceUri = await UtilityHelper.GetCustomServiceUri(backupPartitionInfo.ServiceName, timeout, cancellationToken); var fabricUri = UtilityHelper.GetBackupMappingKey(brsServiceUri, backupPartitionInfo.PartitionId.ToString()); var restoreStatus = await restoreStore.GetValueAsync(fabricUri); if (restoreStatus != null && ( restoreStatus.RestoreStatusState != RestoreState.Failure || restoreStatus.RestoreStatusState != RestoreState.Invalid || restoreStatus.RestoreStatusState != RestoreState.Success || restoreStatus.RestoreStatusState != RestoreState.Timeout)) { backupStorage = restoreStatus.BackupStorage; userInitiatedOperation = true; backupLocations = restoreStatus.BackupLocations.ToList(); } else { var backupMappingKey = UtilityHelper.GetBackupMappingKey(brsServiceUri, backupPartitionInfo.PartitionId.ToString()); var backupMappingModel = (await backupMappingStore.GetValueAsync(backupMappingKey) ?? await backupMappingStore.GetValueAsync(brsServiceUri)) ?? await backupMappingStore.GetValueAsync(UtilityHelper.GetApplicationNameFromService(brsServiceUri)); if (backupMappingModel == null) { throw new FabricPeriodicBackupNotEnabledException(); } var backupPolicy = await backupPolicyStore.GetValueAsync(backupMappingModel.BackupPolicyName); if (backupPolicy != null && backupPolicy.AutoRestore) { backupStorage = backupPolicy.Storage; userInitiatedOperation = false; string applicationName, serviceName; UtilityHelper.GetApplicationAndServiceNameFromServiceUri(brsServiceUri, out applicationName, out serviceName); // Get the latest backup now var backups = await backupStorage.GetBackupEnumerationsTask( applicationName, serviceName, backupPartitionInfo.PartitionId.ToString(), DateTime.MinValue, DateTime.MaxValue, true, cancellationToken); if (backups == null || backups.Count == 0) { throw new ArgumentException(); // TODO: Change this with appropriate exception } var backupDetail = backups.First(); var recoveryPointManager = RecoveryPointManagerFactory.GetRecoveryPointManager(backupStorage); backupLocations = await recoveryPointManager.GetBackupLocationsInBackupChainAsync(backupDetail.BackupLocation, cancellationToken); } else { throw new ArgumentException(); // TODO: Change with the OTher exception } } switch (backupStorage.BackupStorageType) { case BackupStorageType.FileShare: var fileShareStorage = (FileShareStorage)backupStorage; backupStoreInformation = new FileShareBackupStore { AccessType = String.IsNullOrEmpty(fileShareStorage.PrimaryUserName) ? FileShareAccessType.None : FileShareAccessType.DomainUser, FileSharePath = fileShareStorage.Path, PrimaryUserName = fileShareStorage.PrimaryUserName, PrimaryPassword = fileShareStorage.PrimaryPassword, SecondaryUserName = fileShareStorage.SecondaryUserName, SecondaryPassword = fileShareStorage.SecondaryPassword, IsPasswordEncrypted = fileShareStorage.IsPasswordEncrypted, }; break; case BackupStorageType.AzureBlobStore: var azureStorage = (AzureStorage)backupStorage; backupStoreInformation = new AzureBlobBackupStore { ConnectionString = azureStorage.ConnectionString, ContainerName = azureStorage.ContainerName, FolderPath = String.Empty, // TODO: This should be constructed IsAccountKeyEncrypted = azureStorage.IsConnectionStringEncrypted, }; break; case BackupStorageType.DsmsAzureBlobStore: var dsmsAzureStorage = (DsmsAzureStorage)backupStorage; backupStoreInformation = new DsmsAzureBlobBackupStore { StorageCredentialsSourceLocation = dsmsAzureStorage.StorageCredentialsSourceLocation, ContainerName = dsmsAzureStorage.ContainerName, FolderPath = String.Empty, // TODO: This should be constructed }; break; } Guid restoreOperationId = Guid.NewGuid(); if (userInitiatedOperation) { await UtilityHelper.InvokeWithRetry(async() => { using (ITransaction transaction = this.statefulService.StateManager.CreateTransaction()) { var currentRestoreStatus = await restoreStore.GetValueWithUpdateLockModeAsync(fabricUri, timeout, cancellationToken, transaction); restoreOperationId = currentRestoreStatus.RestoreRequestGuid; if (currentRestoreStatus.RestoreStatusState == RestoreState.Accepted) //TODO Check for Guid { var toUpdateRestoreStatus = currentRestoreStatus.ToBuilder().WithState(RestoreState.RestoreInProgress).Build(); await restoreStore.UpdateValueAsync(fabricUri, toUpdateRestoreStatus, timeout, cancellationToken, transaction); await transaction.CommitAsync(); } else { transaction.Abort(); } } }); } var restorePartitionDetails = new RestorePointDetails() { BackupLocations = backupLocations, UserInitiatedOperation = userInitiatedOperation, StoreInformation = backupStoreInformation, OperationId = restoreOperationId }; BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "GetRestorePointDetailsAsync invoked for partition {0} with Return Values {1}", backupPartitionInfo.PartitionId, restorePartitionDetails); return(restorePartitionDetails); }
private static IBackupStoreManager ConstuctFileShareBackupStoreManager(Dictionary <string, string> commandArgs) { FileShareBackupStore fileShareBackupStore = new FileShareBackupStore(); if (commandArgs.ContainsKey(StringConstants.FileShareAccessTypeKeyName)) { switch (commandArgs[StringConstants.FileShareAccessTypeKeyName]) { case StringConstants.FileShareAccessTypeValue_DomainUser: fileShareBackupStore.AccessType = FileShareAccessType.DomainUser; break; case StringConstants.FileShareAccessTypeValue_None: fileShareBackupStore.AccessType = FileShareAccessType.None; break; default: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument {0} with value {1} is not supported", StringConstants.FileShareAccessTypeKeyName, commandArgs[StringConstants.FileShareAccessTypeKeyName])); } } else { fileShareBackupStore.AccessType = FileShareAccessType.None; } fileShareBackupStore.FileSharePath = commandArgs[StringConstants.FileSharePathKeyName]; if (commandArgs.ContainsKey(StringConstants.PrimaryUserNameKeyName) != commandArgs.ContainsKey(StringConstants.PrimaryPasswordKeyName)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Arguments {0} & {1} should be present in pair", StringConstants.PrimaryUserNameKeyName, commandArgs[StringConstants.PrimaryPasswordKeyName])); } if (commandArgs.ContainsKey(StringConstants.PrimaryUserNameKeyName) && commandArgs.ContainsKey(StringConstants.PrimaryPasswordKeyName)) { // Ensure that IsPasswordEncrypted Argument is present. if (!commandArgs.ContainsKey(StringConstants.IsPasswordEncryptedKeyName)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument {0} is mandatory when passwords are specified.", StringConstants.IsPasswordEncryptedKeyName, commandArgs[StringConstants.IsPasswordEncryptedKeyName])); } else { if (string.Compare(commandArgs[StringConstants.IsPasswordEncryptedKeyName], StringConstants.BooleanStringValue_True, true) == 0) { fileShareBackupStore.IsPasswordEncrypted = true; } else if (string.Compare(commandArgs[StringConstants.IsPasswordEncryptedKeyName], StringConstants.BooleanStringValue_False, true) == 0) { fileShareBackupStore.IsPasswordEncrypted = false; } else { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument {0} with value {1} is not supported", StringConstants.IsPasswordEncryptedKeyName, commandArgs[StringConstants.IsPasswordEncryptedKeyName])); } } fileShareBackupStore.PrimaryUserName = commandArgs[StringConstants.PrimaryUserNameKeyName]; fileShareBackupStore.PrimaryPassword = commandArgs[StringConstants.PrimaryPasswordKeyName]; } if (commandArgs.ContainsKey(StringConstants.SecondaryUserNameKeyName) != commandArgs.ContainsKey(StringConstants.SecondaryPasswordKeyName)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Arguments {0} & {1} should be present in pair", StringConstants.SecondaryUserNameKeyName, commandArgs[StringConstants.SecondaryPasswordKeyName])); } if (commandArgs.ContainsKey(StringConstants.SecondaryUserNameKeyName)) { if (commandArgs.ContainsKey(StringConstants.PrimaryUserNameKeyName)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Primary user credentials are mandatory before specifying secondary user credentials.")); } fileShareBackupStore.SecondaryUserName = commandArgs[StringConstants.SecondaryUserNameKeyName]; fileShareBackupStore.SecondaryPassword = commandArgs[StringConstants.SecondaryPasswordKeyName]; } return(new FileShareBackupStoreManager(fileShareBackupStore)); }
public FileShareBackupStoreManager(FileShareBackupStore fileShareStoreInformation) { this._storeInformation = fileShareStoreInformation; }