Beispiel #1
0
 /// <summary>
 /// Writes information about backup results to the logs.
 /// </summary>
 /// <param name="results">The backup results to write.</param>
 public void LogResults(BackupResults results)
 {
     Logger.Info($"{results.DirectoriesBackedUp} directories backed up");
     Logger.Info($"{results.DirectoriesRemoved} directories removed");
     Logger.Info($"{results.FilesCopied} files copied");
     Logger.Info($"{results.FilesRemoved} individual files removed");
 }
Beispiel #2
0
        /// <summary>
        /// Generates the backup completion info file and adds the backup to the backup index.
        /// </summary>
        /// <param name="sourcePath">The path of the backup source directory.</param>
        /// <param name="targetPath">The path of the backup target directory.</param>
        /// <param name="backupName">The name of the backup directory.</param>
        /// <param name="results">The results of the backup.</param>
        /// <returns><c>true</c> if all the operations completed successfully, otherwise <c>false</c>.</returns>
        public bool CompleteBackup(string sourcePath, string targetPath, string backupName, BackupResults results)
        {
            var backupPath = BackupMeta.BackupPath(targetPath, backupName);

            bool success = true;

            BackupCompleteInfo completionInfo = new(DateTime.UtcNow, results.PathsSkipped, results.ManifestComplete);
            var completionInfoFilePath        = BackupMeta.CompleteInfoFilePath(backupPath);

            try {
                BackupCompleteInfoWriter.Write(completionInfoFilePath, completionInfo);
                Logger.Info($"Created backup completion info file \"{completionInfoFilePath}\"");
            }
            catch (BackupCompleteInfoFileIOException e) {
                Logger.Warning(
                    $"Failed to write backup completion info \"{completionInfoFilePath}\": {e.InnerException.Reason}");
                success = false;
            }

            var indexFilePath = BackupMeta.IndexFilePath(targetPath);

            try {
                BackupIndexWriter.AddEntry(indexFilePath, backupName, sourcePath);
                Logger.Info($"Added this backup to backup index");
            }
            catch (BackupIndexFileIOException e) {
                Logger.Warning($"Failed to add backup to backup index \"{indexFilePath}\": {e.InnerException.Reason}");
                success = false;
            }

            return(success);
        }