private BackupService(string sourcePath, IReadOnlyList <string> excludePaths, BackupSum previousBackupSum,
                       string backupPath, BackupManifestWriter manifestWriter, Logger logger)
 {
     SourcePath = sourcePath;
     // Trim trailing directory separator for efficient matching later.
     ExcludePaths      = excludePaths.Select(p => Utility.RemoveTrailingDirSep(p)).ToList();
     PreviousBackupSum = previousBackupSum;
     BackupPath        = backupPath;
     BackupDataPath    = BackupMeta.BackupDataPath(backupPath);
     ManifestWriter    = manifestWriter;
     Logger            = logger;
     Results           = new(false, true, 0, 0, 0, 0);
 }
Beispiel #2
0
        /// <summary>
        /// Runs the backup.
        /// </summary>
        /// <param name="config">The configuration of this backup.</param>
        /// <param name="previousBackupSum">Sum of the existing backup data for this source directory.</param>
        /// <param name="backupName">The name of the new backup directory.</param>
        /// <param name="manifestWriter">Writes the backup manifest. Must be in a newly-constructed state.</param>
        /// <returns>Results of the backup.</returns>
        /// <exception cref="ApplicationRuntimeError">If the backup fails.</exception>
        private BackupResults DoBackup(AppConfig config, BackupSum previousBackupSum, string backupName,
                                       BackupManifestWriter manifestWriter)
        {
            var backupPath = BackupMeta.BackupPath(config.TargetPath, backupName);

            Logger.Info("Running backup operation");
            try {
                return(BackupService.Run(config.SourcePath, config.ExcludePaths, previousBackupSum, backupPath,
                                         manifestWriter, Logger));
            }
            catch (BackupServiceException e) {
                throw new ApplicationRuntimeError(e.Message);
            }
        }
 /// <summary>
 /// Runs a backup instance. Backs up files from the source directory to the backup directory and records them
 /// in the backup manifest file.
 /// </summary>
 /// <param name="sourcePath">The path of the directory to back up.</param>
 /// <param name="excludePaths">Paths to exclude from the backup. Should be normalised.</param>
 /// <param name="previousBackupSum">Sum of the existing backups for this source directory.</param>
 /// <param name="backupPath">The path of the directory to contain the new backup.</param>
 /// <param name="manifestWriter">Writes the backup manifest. Must be in a newly-constructed state.</param>
 /// <param name="logger">For logging of info and warnings during the backup.</param>
 /// <returns>The results of the backup.</returns>
 /// <exception cref="BackupServiceException">If the source directory can't be accessed.</exception>
 public static BackupResults Run(string sourcePath, IReadOnlyList <string> excludePaths,
                                 BackupSum previousBackupSum, string backupPath, BackupManifestWriter manifestWriter, Logger logger) =>
 new BackupService(sourcePath, excludePaths, previousBackupSum, backupPath, manifestWriter, logger)
 .Run();