/// <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); }
/// <summary> /// Reads the backup index from a target directory. /// </summary> /// <param name="targetPath">The target directory to read from.</param> /// <returns>The read backup index, or <c>null</c> if the index file does not exist.</returns> /// <exception cref="ApplicationRuntimeError">If the index file exists, but could not be read/parsed. /// </exception> /// <seealso cref="BackupMeta.ReadIndexFile(string)"/> private BackupIndex?ReadBackupIndex(string targetPath) { var indexFilePath = BackupMeta.IndexFilePath(targetPath); try { var index = BackupIndexReader.Read(indexFilePath); Logger.Info($"Read backup index \"{indexFilePath}\""); return(index); } catch (BackupIndexFileIOException e) when(e.InnerException is PathNotFoundException) { Logger.Info("No existing backup index found"); return(null); } catch (BackupIndexFileException e) { throw new ApplicationRuntimeError(e.Message); } }