/// <summary> /// This will perform a full backup with some directory renaming if necessary. /// <para> /// If there is no existing backup, then no renaming will occur. /// Otherwise the full backup will be done into a temporary directory and renaming /// will occur if everything was successful. /// </para> /// </summary> /// <param name="onlineBackupContext"> command line arguments, config etc. </param> /// <returns> outcome of full backup </returns> private Fallible <BackupStageOutcome> FullBackupWithTemporaryFolderResolutions(OnlineBackupContext onlineBackupContext) { Path userSpecifiedBackupLocation = onlineBackupContext.ResolvedLocationFromName; Path temporaryFullBackupLocation = _backupCopyService.findAnAvailableLocationForNewFullBackup(userSpecifiedBackupLocation); OptionalHostnamePort address = onlineBackupContext.RequiredArguments.Address; Fallible <BackupStageOutcome> state = _backupStrategy.performFullBackup(DatabaseLayout.of(temporaryFullBackupLocation.toFile()), _config, address); // NOTE temporaryFullBackupLocation can be equal to desired bool backupWasMadeToATemporaryLocation = !userSpecifiedBackupLocation.Equals(temporaryFullBackupLocation); if (BackupStageOutcome.Success.Equals(state.State)) { _backupRecoveryService.recoverWithDatabase(temporaryFullBackupLocation, _pageCache, _config); if (backupWasMadeToATemporaryLocation) { try { RenameTemporaryBackupToExpected(temporaryFullBackupLocation, userSpecifiedBackupLocation); } catch (IOException e) { return(new Fallible <BackupStageOutcome>(BackupStageOutcome.UnrecoverableFailure, e)); } } ClearIdFiles(userSpecifiedBackupLocation); } return(state); }
private Fallible <BackupStrategyOutcome> PerformBackupWithoutLifecycle(OnlineBackupContext onlineBackupContext) { Path backupLocation = onlineBackupContext.ResolvedLocationFromName; OptionalHostnamePort userSpecifiedAddress = onlineBackupContext.RequiredArguments.Address; _log.debug("User specified address is %s:%s", userSpecifiedAddress.Hostname.ToString(), userSpecifiedAddress.Port.ToString()); Config config = onlineBackupContext.Config; bool previousBackupExists = _backupCopyService.backupExists(DatabaseLayout.of(backupLocation.toFile())); if (previousBackupExists) { _log.info("Previous backup found, trying incremental backup."); Fallible <BackupStageOutcome> state = _backupStrategy.performIncrementalBackup(DatabaseLayout.of(backupLocation.toFile()), config, userSpecifiedAddress); bool fullBackupWontWork = BackupStageOutcome.WrongProtocol.Equals(state.State); bool incrementalWasSuccessful = BackupStageOutcome.Success.Equals(state.State); if (incrementalWasSuccessful) { _backupRecoveryService.recoverWithDatabase(backupLocation, _pageCache, config); } if (fullBackupWontWork || incrementalWasSuccessful) { ClearIdFiles(backupLocation); return(DescribeOutcome(state)); } if (!onlineBackupContext.RequiredArguments.FallbackToFull) { return(DescribeOutcome(state)); } } if (onlineBackupContext.RequiredArguments.FallbackToFull) { if (!previousBackupExists) { _log.info("Previous backup not found, a new full backup will be performed."); } return(DescribeOutcome(FullBackupWithTemporaryFolderResolutions(onlineBackupContext))); } return(new Fallible <BackupStrategyOutcome>(BackupStrategyOutcome.IncorrectStrategy, null)); }
public override Fallible <BackupStageOutcome> PerformFullBackup(DatabaseLayout targetDatabaseLayout, Config config, OptionalHostnamePort userProvidedAddress) { HostnamePort fromAddress = _addressResolver.resolveCorrectHAAddress(config, userProvidedAddress); _log.info("Resolved address for backup protocol is " + fromAddress); ConsistencyCheck consistencyCheck = ConsistencyCheck.NONE; bool forensics = false; try { string host = fromAddress.Host; int port = fromAddress.Port; _backupProtocolService.doFullBackup(host, port, targetDatabaseLayout, consistencyCheck, config, _timeout, forensics); return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Success, null)); } catch (ComException e) { return(new Fallible <BackupStageOutcome>(BackupStageOutcome.WrongProtocol, e)); } }
public override Fallible <BackupStageOutcome> PerformIncrementalBackup(DatabaseLayout targetDatabaseLayout, Config config, OptionalHostnamePort fromAddress) { HostnamePort resolvedAddress = _addressResolver.resolveCorrectHAAddress(config, fromAddress); _log.info("Resolved address for backup protocol is " + resolvedAddress); try { string host = resolvedAddress.Host; int port = resolvedAddress.Port; _backupProtocolService.doIncrementalBackup(host, port, targetDatabaseLayout, ConsistencyCheck.NONE, _timeout, config); return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Success, null)); } catch (MismatchingStoreIdException e) { return(new Fallible <BackupStageOutcome>(BackupStageOutcome.UnrecoverableFailure, e)); } catch (Exception e) { return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Failure, e)); } }