public static int Backup(List <string> args, Dictionary <string, string> options, Library.Utility.IFilter filter) { if (args.Count < 2) { return(PrintWrongNumberOfArguments(args, 2)); } var backend = args[0]; args.RemoveAt(0); var dirs = args.ToArray(); var output = new ConsoleOutput(options); Library.Interface.IBackupResults result; using (var periodicOutput = new PeriodicOutput(output, TimeSpan.FromSeconds(5))) { output.MessageEvent(string.Format("Backup started at {0}", DateTime.Now)); output.PhaseChanged += (phase, previousPhase) => { if (previousPhase == Duplicati.Library.Main.OperationPhase.Backup_PostBackupTest) { output.MessageEvent("Remote backup verification completed"); } if (phase == Duplicati.Library.Main.OperationPhase.Backup_ProcessingFiles) { output.MessageEvent("Scanning local files ..."); periodicOutput.SetReady(); } else if (phase == Duplicati.Library.Main.OperationPhase.Backup_Finalize) { periodicOutput.SetFinished(); } else if (phase == Duplicati.Library.Main.OperationPhase.Backup_PreBackupVerify) { output.MessageEvent("Checking remote backup ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Backup_PostBackupVerify) { output.MessageEvent("Checking remote backup ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Backup_PostBackupTest) { output.MessageEvent("Verifying remote backup ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Backup_Compact) { output.MessageEvent("Compacting remote backup ..."); } }; periodicOutput.WriteOutput += (progress, files, size, counting) => { output.MessageEvent(string.Format(" {0} files need to be examined ({1}){2}", files, Library.Utility.Utility.FormatSizeString(size), counting ? " (still counting)" : "")); }; using (var i = new Library.Main.Controller(backend, options, output)) result = i.Backup(dirs, filter); } if (output.VerboseOutput) { Library.Utility.Utility.PrintSerializeObject(result, Console.Out); } else { var parsedStats = result.BackendStatistics as Duplicati.Library.Interface.IParsedBackendStatistics; output.MessageEvent(string.Format(" Duration of backup: {0:hh\\:mm\\:ss}", result.Duration)); if (parsedStats != null && parsedStats.KnownFileCount > 0) { output.MessageEvent(string.Format(" Remote files: {0}", parsedStats.KnownFileCount)); output.MessageEvent(string.Format(" Remote size: {0}", Library.Utility.Utility.FormatSizeString(parsedStats.KnownFileSize))); } output.MessageEvent(string.Format(" Files added: {0}", result.AddedFiles)); output.MessageEvent(string.Format(" Files deleted: {0}", result.DeletedFiles)); output.MessageEvent(string.Format(" Files changed: {0}", result.ModifiedFiles)); output.MessageEvent(string.Format(" Data uploaded: {0}", Library.Utility.Utility.FormatSizeString(result.BackendStatistics.BytesUploaded))); output.MessageEvent(string.Format(" Data downloaded: {0}", Library.Utility.Utility.FormatSizeString(result.BackendStatistics.BytesDownloaded))); } if (result.ExaminedFiles == 0 && (filter != null || !filter.Empty)) { output.MessageEvent("No files were processed. If this was not intentional you may want to use the \"test-filter\" command"); } output.MessageEvent("Backup completed successfully!"); //Interrupted = 50 if (result.PartialBackup) { return(50); } //Completed with warnings = 2 if (result.Warnings.Count() > 0 || result.Errors.Count() > 0) { return(2); } //Success, but no upload = 1 if (result.BackendStatistics.BytesUploaded == 0) { return(1); } return(0); }
public static int Backup(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter) { if (args.Count < 2) return PrintWrongNumberOfArguments(args, 2); var backend = args[0]; args.RemoveAt(0); var dirs = args.ToArray(); var output = new ConsoleOutput(options); Library.Interface.IBackupResults result; using(var periodicOutput = new PeriodicOutput(output, TimeSpan.FromSeconds(5))) { output.MessageEvent(string.Format("Backup started at {0}", DateTime.Now)); output.PhaseChanged += (phase, previousPhase) => { if (previousPhase == Duplicati.Library.Main.OperationPhase.Backup_PostBackupTest) output.MessageEvent("Remote backup verification completed"); if (phase == Duplicati.Library.Main.OperationPhase.Backup_ProcessingFiles) { output.MessageEvent("Scanning local files ..."); periodicOutput.SetReady(); } else if (phase == Duplicati.Library.Main.OperationPhase.Backup_Finalize) periodicOutput.SetFinished(); else if (phase == Duplicati.Library.Main.OperationPhase.Backup_PreBackupVerify) output.MessageEvent("Checking remote backup ..."); else if (phase == Duplicati.Library.Main.OperationPhase.Backup_PostBackupVerify) output.MessageEvent("Checking remote backup ..."); else if (phase == Duplicati.Library.Main.OperationPhase.Backup_PostBackupTest) output.MessageEvent("Verifying remote backup ..."); else if (phase == Duplicati.Library.Main.OperationPhase.Backup_Compact) output.MessageEvent("Compacting remote backup ..."); }; periodicOutput.WriteOutput += (progress, files, size, counting) => { output.MessageEvent(string.Format(" {0} files need to be examined ({1}){2}", files, Library.Utility.Utility.FormatSizeString(size), counting ? " (still counting)" : "")); }; using(var i = new Library.Main.Controller(backend, options, output)) result = i.Backup(dirs, filter); } if (output.VerboseOutput) { Library.Utility.Utility.PrintSerializeObject(result, Console.Out); } else { var parsedStats = result.BackendStatistics as Duplicati.Library.Interface.IParsedBackendStatistics; output.MessageEvent(string.Format(" Duration of backup: {0:hh\\:mm\\:ss}", result.Duration)); if (parsedStats != null && parsedStats.KnownFileCount > 0) { output.MessageEvent(string.Format(" Remote files: {0}", parsedStats.KnownFileCount)); output.MessageEvent(string.Format(" Remote size: {0}", Library.Utility.Utility.FormatSizeString(parsedStats.KnownFileSize))); } output.MessageEvent(string.Format(" Files added: {0}", result.AddedFiles)); output.MessageEvent(string.Format(" Files deleted: {0}", result.DeletedFiles)); output.MessageEvent(string.Format(" Files changed: {0}", result.ModifiedFiles)); output.MessageEvent(string.Format(" Data uploaded: {0}", Library.Utility.Utility.FormatSizeString(result.BackendStatistics.BytesUploaded))); output.MessageEvent(string.Format(" Data downloaded: {0}", Library.Utility.Utility.FormatSizeString(result.BackendStatistics.BytesDownloaded))); } if (result.ExaminedFiles == 0 && (filter != null || !filter.Empty)) output.MessageEvent("No files were processed. If this was not intentional you may want to use the \"test-filters\" command"); output.MessageEvent("Backup completed successfully!"); //Interrupted = 50 if (result.PartialBackup) return 50; //Completed with warnings = 2 if (result.Warnings.Count() > 0 || result.Errors.Count() > 0) return 2; //Success, but no upload = 1 if (result.BackendStatistics.BytesUploaded == 0) return 1; return 0; }
public static int Restore(List <string> args, Dictionary <string, string> options, Library.Utility.IFilter filter) { if (args.Count < 1) { return(PrintWrongNumberOfArguments(args, 1)); } string backend = args[0]; args.RemoveAt(0); bool controlFiles = Library.Utility.Utility.ParseBoolOption(options, "control-files"); options.Remove("control-files"); // Prefix all filenames with "*/" so we search all folders for (var ix = 0; ix < args.Count; ix++) { if (args[ix].IndexOfAny(new char[] { '*', '?', System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }) < 0 && !args[ix].StartsWith("[")) { args[ix] = "*" + System.IO.Path.DirectorySeparatorChar.ToString() + args[ix]; } } var output = new ConsoleOutput(options); output.MessageEvent(string.Format("Restore started at {0}", DateTime.Now)); using (var i = new Library.Main.Controller(backend, options, output)) if (controlFiles) { var res = i.RestoreControlFiles(args.ToArray(), filter); output.MessageEvent("Restore control files completed:"); foreach (var s in res.Files) { Console.WriteLine(s); } } else { using (var periodicOutput = new PeriodicOutput(output, TimeSpan.FromSeconds(5))) { output.PhaseChanged += (phase, previousPhase) => { if (phase == Duplicati.Library.Main.OperationPhase.Restore_PreRestoreVerify) { output.MessageEvent("Checking remote backup ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Restore_ScanForExistingFiles) { output.MessageEvent("Checking existing target files ..."); } /*else if (phase == Duplicati.Library.Main.OperationPhase.Restore_DownloadingRemoteFiles) * output.MessageEvent("Downloading remote files ..."); */ else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PatchWithLocalBlocks) { output.MessageEvent("Updating target files with local data ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PostRestoreVerify) { periodicOutput.SetFinished(); periodicOutput.Join(TimeSpan.FromMilliseconds(100)); output.MessageEvent("Verifying restored files ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Restore_ScanForLocalBlocks) { output.MessageEvent("Scanning local files for needed data ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Restore_CreateTargetFolders) { periodicOutput.SetReady(); } }; periodicOutput.WriteOutput += (progress, files, size, counting) => { output.MessageEvent(string.Format(" {0} files need to be restored ({1})", files, Library.Utility.Utility.FormatSizeString(size))); }; var res = i.Restore(args.ToArray(), filter); string restorePath; options.TryGetValue("restore-path", out restorePath); output.MessageEvent(string.Format("Restored {0} ({1}) files to {2}", res.FilesRestored, Library.Utility.Utility.FormatSizeString(res.SizeOfRestoredFiles), string.IsNullOrEmpty(restorePath) ? "original path" : restorePath)); output.MessageEvent(string.Format("Duration of restore: {0:hh\\:mm\\:ss}", res.Duration)); if (res.FilesRestored > 0) { output.MessageEvent("***********************************************"); output.MessageEvent("Did we help save your files? If so, please support Duplicati with a donation. We suggest 10€ for private use and 100€ for commercial use."); output.MessageEvent(""); output.MessageEvent("Paypal: http://goo.gl/P4XJ6S"); output.MessageEvent("Bitcoin: 1L74qa1n5SFKwwyHhECTHBJgcf6WT2rJKf"); output.MessageEvent("***********************************************"); } if (output.VerboseOutput) { Library.Utility.Utility.PrintSerializeObject(res, Console.Out); } } } return(0); }
public static int Restore(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter) { if (args.Count < 1) return PrintWrongNumberOfArguments(args, 1); string backend = args[0]; args.RemoveAt(0); bool controlFiles = Library.Utility.Utility.ParseBoolOption(options, "control-files"); options.Remove("control-files"); // Prefix all filenames with "*/" so we search all folders for (var ix = 0; ix < args.Count; ix++) if (args[ix].IndexOfAny(new char[] { '*', '?', System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }) < 0 && !args[ix].StartsWith("[")) args[ix] = "*" + System.IO.Path.DirectorySeparatorChar.ToString() + args[ix]; // suffix all folders with "*" so we restore all contents in the folder for (var ix = 0; ix < args.Count; ix++) if (args[ix].IndexOfAny(new char[] { '*', '?' }) < 0 && !args[ix].StartsWith("[") && args[ix].EndsWith(System.IO.Path.DirectorySeparatorChar.ToString())) args[ix] += "*"; var output = new ConsoleOutput(options); output.MessageEvent(string.Format("Restore started at {0}", DateTime.Now)); using(var i = new Library.Main.Controller(backend, options, output)) if (controlFiles) { var res = i.RestoreControlFiles(args.ToArray(), filter); output.MessageEvent("Restore control files completed:"); foreach(var s in res.Files) Console.WriteLine(s); } else { using(var periodicOutput = new PeriodicOutput(output, TimeSpan.FromSeconds(5))) { output.PhaseChanged += (phase, previousPhase) => { if (phase == Duplicati.Library.Main.OperationPhase.Restore_PreRestoreVerify) output.MessageEvent("Checking remote backup ..."); else if (phase == Duplicati.Library.Main.OperationPhase.Restore_ScanForExistingFiles) output.MessageEvent("Checking existing target files ..."); /*else if (phase == Duplicati.Library.Main.OperationPhase.Restore_DownloadingRemoteFiles) output.MessageEvent("Downloading remote files ..."); */ else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PatchWithLocalBlocks) output.MessageEvent("Updating target files with local data ..."); else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PostRestoreVerify) { periodicOutput.SetFinished(); periodicOutput.Join(TimeSpan.FromMilliseconds(100)); output.MessageEvent("Verifying restored files ..."); } else if (phase == Duplicati.Library.Main.OperationPhase.Restore_ScanForLocalBlocks) output.MessageEvent("Scanning local files for needed data ..."); else if (phase == Duplicati.Library.Main.OperationPhase.Restore_CreateTargetFolders) periodicOutput.SetReady(); }; periodicOutput.WriteOutput += (progress, files, size, counting) => { output.MessageEvent(string.Format(" {0} files need to be restored ({1})", files, Library.Utility.Utility.FormatSizeString(size))); }; var res = i.Restore(args.ToArray(), filter); string restorePath; options.TryGetValue("restore-path", out restorePath); output.MessageEvent(string.Format("Restored {0} ({1}) files to {2}", res.FilesRestored, Library.Utility.Utility.FormatSizeString(res.SizeOfRestoredFiles), string.IsNullOrEmpty(restorePath) ? "original path" : restorePath)); output.MessageEvent(string.Format("Duration of restore: {0:hh\\:mm\\:ss}", res.Duration)); if (res.FilesRestored > 0 && !Library.Main.Utility.SuppressDonationMessages) { output.MessageEvent("***********************************************"); output.MessageEvent("Did we help save your files? If so, please support Duplicati with a donation. We suggest 10€ for private use and 100€ for commercial use."); output.MessageEvent(""); output.MessageEvent("Paypal: http://goo.gl/P4XJ6S"); output.MessageEvent("Bitcoin: 1L74qa1n5SFKwwyHhECTHBJgcf6WT2rJKf"); output.MessageEvent("***********************************************"); } if (output.VerboseOutput) Library.Utility.Utility.PrintSerializeObject(res, Console.Out); if (res.Warnings.Count() > 0) return 2; } } return 0; }