private void DoUpdate(KeyValuePair <string, BackupAction> path, ref RestoreStatistics statistics) { switch (path.Value.ActionType) { case ActionType.FileOld: Console.WriteLine($"Deleting: '{path.Key}'"); if (!TryDeleteFile(path.Key)) { Console.WriteLine("...failed"); } break; case ActionType.FileNew: Console.WriteLine($"Restore: '{path.Key}' StorageName: {path.Value.StorageName}"); if (!this.Storage.Restore(path.Value.StorageName, path.Key)) { Console.WriteLine("...failed"); } break; case ActionType.DirOld: Console.WriteLine($"Deleting: '{path.Key}' if empty"); if (!TryDeleteDir(path.Key)) { Console.WriteLine("...failed"); } break; case ActionType.DirNew: Console.WriteLine($"Creating: '{path.Key}' if not exists"); if (!TryCreateDir(path.Key)) { Console.WriteLine("...failed"); } break; default: break; } }
private PathsCollector CollectPaths(long targetTime, out RestoreStatistics logStatistics) { var pathsCollector = new PathsCollector(); logStatistics = new RestoreStatistics(forActionTimeCount: true); this.Log.Reset(); while (!this.Log.EndOfStream) { var line = this.Log.ReadLine(excludeComments: true); if (line == string.Empty) { continue; } var action = new BackupAction(line); logStatistics.Register(action); if (!action.ParseIsValid) { continue; } if (action.ActionTime <= targetTime) { switch (action.ActionType) { case ActionType.FileNewIgnored: case ActionType.FileNewErrorSaving: break; default: pathsCollector.InsertForUpdate(action.FullPath, action); break; } } else { pathsCollector.InsertForDelete(action.FullPath); } } return(pathsCollector); }
public void Rollback(DateTime targetTime, out RestoreStatistics statistics) { Console.WriteLine($"\nStart rollback at moment {targetTime.ToShortDateString()} {targetTime.TimeOfDay}"); var time = targetTime.Ticks; var paths = this.CollectPaths(time, out statistics); foreach (var path in paths.ForUpdate) { this.DoUpdate(path, ref statistics); } foreach (var path in paths.ForDelete) { Console.WriteLine($"Deleting: '{path}' if empty"); if (!TryDeletePath(path)) { Console.WriteLine("...failed"); } } }
public void WriteLogToConsole(out RestoreStatistics statistics) { statistics = new RestoreStatistics(forActionTimeCount: true); this.Log.Reset(); while (!this.Log.EndOfStream) { var line = this.Log.ReadLine(excludeComments: true); if (line == string.Empty) { continue; } var action = new BackupAction(line); statistics.Register(action); if (action.ParseIsValid) { var time = new DateTime(action.ActionTime); Console.WriteLine($"*** {statistics.ValidRecords}: {time.ToShortDateString()} {time.TimeOfDay} {action.Comment}"); } } }