private void SearchFiles(IBackup backup, string filterstring, RequestInfo info) { var filter = Library.Utility.Uri.UrlDecode(filterstring ?? "").Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries); var timestring = info.Request.QueryString["time"].Value; var allversion = Duplicati.Library.Utility.Utility.ParseBool(info.Request.QueryString["all-versions"].Value, false); if (string.IsNullOrWhiteSpace(timestring) && !allversion) { info.ReportClientError("Invalid or missing time"); return; } var prefixonly = Duplicati.Library.Utility.Utility.ParseBool(info.Request.QueryString["prefix-only"].Value, false); var foldercontents = Duplicati.Library.Utility.Utility.ParseBool(info.Request.QueryString["folder-contents"].Value, false); var time = new DateTime(); if (!allversion) time = Duplicati.Library.Utility.Timeparser.ParseTimeInterval(timestring, DateTime.Now); var r = Runner.Run(Runner.CreateListTask(backup, filter, prefixonly, allversion, foldercontents, time), false) as Duplicati.Library.Interface.IListResults; var result = new Dictionary<string, object>(); foreach(HttpServer.HttpInputItem n in info.Request.QueryString) result[n.Name] = n.Value; result["Filesets"] = r.Filesets; result["Files"] = r.Files; info.OutputOK(result); }
public void Save(string file, IBackup backup) { BinaryWriter bw = new BinaryWriter(new FileStream(file, FileMode.OpenOrCreate)); bw.Write(signature); bw.Write(backup.GetName()); bw.Write(backup.GetDescription()); bw.Write((backup as Backup_Jar).GetData()); }
private bool ExecuteHandler(object command, IBackup executor) { try { return executor.Backup(command); } finally { _container.Release(executor); } }
// Restore settings and registry keys of selected backup public string RestoreBackup(IBackup backup) { SteamController.ValidateSteamPath(); string errors = ""; string path = "Backups\\" + backup.Id + "\\"; List<string> regFiles = new List<string>() { "Backup_DefaultMouseKey.reg", "Backup_CapsLock.reg", "Backup_MouseKey.reg", "Backup_VisualThemes.reg" }; // Import registy files: foreach (string regFile in regFiles) { if (File.Exists(path + regFile)) { Process p = Process.Start("regedit.exe", " /s " + path + regFile); p.WaitForExit(); } else { errors += regFile + " was not found. \n"; } } // Copy configs to csgo\cfg folder: string[] cfgs = new string[] { "config.cfg", "autoexec.cfg", "video.txt" }; foreach (string cfg in cfgs) { if (File.Exists(path + cfg)) { File.Copy(path + cfg, SteamPaths.CfgFolder + cfg, true); } else { errors += cfg + " was not found \n"; } } // Copy localconfig (launchOptions) to steam folder: foreach (string localconfig in backup.Localconfigs) { if (File.Exists(path + localconfig)) { string accountNumber = localconfig.Split('_').First(); File.Copy(path + localconfig, SteamPaths.Steam + "\\userdata\\" + accountNumber + "\\config\\localconfig.vdf", true); } else { errors += localconfig + " was not found \n"; } } return errors + "Backup (" + backup.Id + ") succesfully restored.\nPlease reboot to apply the registry changes.\n"; }
private void ListFileSets(IBackup backup, RequestInfo info) { var input = info.Request.QueryString; var extra = new Dictionary<string, string>(); extra["list-sets-only"] = "true"; if (input["include-metadata"].Value != null) extra["list-sets-only"] = (!Library.Utility.Utility.ParseBool(input["include-metadata"].Value, false)).ToString(); if (input["from-remote-only"].Value != null) extra["no-local-db"] = Library.Utility.Utility.ParseBool(input["from-remote-only"].Value, false).ToString(); var r = Runner.Run(Runner.CreateTask(DuplicatiOperation.List, backup, extra), false) as Duplicati.Library.Interface.IListResults; info.OutputOK(r.Filesets); }
private void ListFileSets(IBackup backup, RequestInfo info) { var input = info.Request.QueryString; var extra = new Dictionary<string, string>(); extra["list-sets-only"] = "true"; if (input["include-metadata"].Value != null) extra["list-sets-only"] = (!Library.Utility.Utility.ParseBool(input["include-metadata"].Value, false)).ToString(); if (input["from-remote-only"].Value != null) extra["no-local-db"] = Library.Utility.Utility.ParseBool(input["from-remote-only"].Value, false).ToString(); var r = Runner.Run(Runner.CreateTask(DuplicatiOperation.List, backup, extra), false) as Duplicati.Library.Interface.IListResults; if (r.EncryptedFiles && backup.Settings.Any(x => string.Equals("--no-encryption", x.Name, StringComparison.InvariantCultureIgnoreCase))) info.ReportServerError("encrypted-storage"); else info.OutputOK(r.Filesets); }
private void RepairUpdate(IBackup backup, RequestInfo info) { DoRepair(backup, info, true); }
private void RestoreFiles(IBackup backup, RequestInfo info) { var input = info.Request.Form; var filters = input["paths"].Value.Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries); var time = Duplicati.Library.Utility.Timeparser.ParseTimeInterval(input["time"].Value, DateTime.Now); var restoreTarget = input["restore-path"].Value; var overwrite = Duplicati.Library.Utility.Utility.ParseBool(input["overwrite"].Value, false); var permissions = Duplicati.Library.Utility.Utility.ParseBool(input["permissions"].Value, false); var skip_metadata = Duplicati.Library.Utility.Utility.ParseBool(input["skip-metadata"].Value, false); var task = Runner.CreateRestoreTask(backup, filters, time, restoreTarget, overwrite, permissions, skip_metadata); Program.WorkThread.AddTask(task); info.OutputOK(new { TaskID = task.TaskID }); }
private void IsActive(IBackup backup, RequestInfo info) { var t = Program.WorkThread.CurrentTask; var bt = t == null ? null : t.Backup; if (bt != null && backup.ID == bt.ID) { info.OutputOK(new { Status = "OK", Active = true }); return; } else if (Program.WorkThread.CurrentTasks.Where(x => { var bn = x == null ? null : x.Backup; return bn == null || bn.ID == backup.ID; }).Any()) { info.OutputOK(new { Status = "OK", Active = true }); return; } else { info.OutputOK(new { Status = "OK", Active = false }); return; } }
private void Repair(IBackup backup, RequestInfo info) { DoRepair(backup, info, false); }
public void Save(string file, IBackup backup) { LoginInfo li = (backup as Backup_LoginInfo).GetLogin(); BinaryWriter bw = new BinaryWriter(new FileStream(file, FileMode.OpenOrCreate)); bw.Write(signature); bw.Write(backup.GetDescription()); byte[] ldata = li.SaveToMemory(); bw.Write(ldata.Length); bw.Write(ldata); bw.Close(); }
private void FetchRemoteLogData(IBackup backup, RequestInfo info) { using(var con = (System.Data.IDbConnection)Activator.CreateInstance(Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteConnectionType)) { con.ConnectionString = "Data Source=" + backup.DBPath; con.Open(); using(var cmd = con.CreateCommand()) { var dt = LogData.DumpTable(cmd, "RemoteOperation", "ID", info.Request.QueryString["offset"].Value, info.Request.QueryString["pagesize"].Value); // Unwrap raw data to a string foreach(var n in dt) try { n["Data"] = System.Text.Encoding.UTF8.GetString((byte[])n["Data"]); } catch { } info.OutputOK(dt); } } }
private void DoRepair(IBackup backup, RequestInfo info, bool repairUpdate) { var input = info.Request.Form; string[] filters = null; var extra = new Dictionary<string, string>(); if (input["only-paths"].Value != null) extra["repair-only-paths"] = (Library.Utility.Utility.ParseBool(input["only-paths"].Value, false)).ToString(); if (input["time"].Value != null) extra["time"] = input["time"].Value; if (input["version"].Value != null) extra["version"] = input["version"].Value; if (input["paths"].Value != null) filters = input["paths"].Value.Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries); var task = Runner.CreateTask(repairUpdate ? DuplicatiOperation.RepairUpdate : DuplicatiOperation.Repair, backup, extra, filters); Program.WorkThread.AddTask(task); Program.StatusEventNotifyer.SignalNewEvent(); info.OutputOK(new {Status = "OK", ID = task.TaskID}); }
public static void RemoveBackup(IBackup backup) { File.Delete(backups.Find(b => b.GetName() == backup.GetName()).GetFilePath()); backups.Remove(backup); }
public void Save(string file, IBackup backup) { byte[] jardata = (backup as Backup_Jar).GetData(); BinaryWriter bw = new BinaryWriter(new FileStream(file, FileMode.OpenOrCreate)); bw.Write(signature); bw.Write(backup.GetName()); bw.Write(backup.GetDescription()); bw.Write(jardata.Length); bw.Write(jardata); bw.Close(); }
// Delete selected backup public string DeleteBackup(IBackup backup) { Directory.Delete("Backups\\" + backup.Id, true); backups.Remove(backup); return "Backup (" + backup.Id + ") succesfully deleted. \n"; }
private void UpdateDatabasePath(IBackup backup, RequestInfo info, bool move) { var np = info.Request.Form["path"].Value; if (string.IsNullOrWhiteSpace(np)) info.ReportClientError("No target path supplied"); else if (!Path.IsPathRooted(np)) info.ReportClientError("Target path is relative, please supply a fully qualified path"); else { if (move && (File.Exists(np) || Directory.Exists(np))) info.ReportClientError("A file already exists at the new location"); else { if (move) File.Move(backup.DBPath, np); Program.DataConnection.UpdateBackupDBPath(backup, np); } } }
using Duplicati.Server.Serialization.Interface;
public void SetParentBackup(IBackup parentBackup) { if (!(parentBackup is ZipBackup)) throw new InvalidOperationException( "Parent backup must be a zip backup too and must be from the same repository"); if (parentBackup is IBackupPrototype) throw new InvalidOperationException("Parent backup must be saved first"); Info.ParentName = parentBackup.Name; }
private void RunBackup(IBackup backup, RequestInfo info) { var t = Program.WorkThread.CurrentTask; var bt = t == null ? null : t.Backup; if (bt != null && backup.ID == bt.ID) { // Already running } else if (Program.WorkThread.CurrentTasks.Where(x => { var bn = x == null ? null : x.Backup; return bn == null || bn.ID == backup.ID; }).Any()) { // Already in queue } else { Program.WorkThread.AddTask(Runner.CreateTask(DuplicatiOperation.Backup, backup)); Program.StatusEventNotifyer.SignalNewEvent(); } info.OutputOK(); }
private void Export(IBackup backup, RequestInfo info) { var cmdline = Library.Utility.Utility.ParseBool(info.Request.QueryString["cmdline"].Value, false); if (cmdline) { info.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, backup)) }); } else { var passphrase = info.Request.QueryString["passphrase"].Value; var ipx = Program.DataConnection.PrepareBackupForExport(backup); byte[] data; using(var ms = new System.IO.MemoryStream()) using(var sw = new System.IO.StreamWriter(ms)) { Serializer.SerializeJson(sw, ipx, true); if (!string.IsNullOrWhiteSpace(passphrase)) { ms.Position = 0; using(var ms2 = new System.IO.MemoryStream()) using(var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary<string, string>())) { m.Encrypt(ms, ms2); data = ms2.ToArray(); } } else data = ms.ToArray(); } var filename = Library.Utility.Uri.UrlEncode(backup.Name) + "-duplicati-config.json"; if (!string.IsNullOrWhiteSpace(passphrase)) filename += ".aes"; info.Response.ContentLength = data.Length; info.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename)); info.Response.ContentType = "application/octet-stream"; info.BodyWriter.SetOK(); info.Response.SendHeaders(); info.Response.SendBody(data); } }
private void Verify(IBackup backup, RequestInfo info) { var task = Runner.CreateTask(DuplicatiOperation.Verify, backup); Program.WorkThread.AddTask(task); Program.StatusEventNotifyer.SignalNewEvent(); info.OutputOK(new {Status = "OK", ID = task.TaskID}); }
private void FetchLogData(IBackup backup, RequestInfo info) { using(var con = (System.Data.IDbConnection)Activator.CreateInstance(Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteConnectionType)) { con.ConnectionString = "Data Source=" + backup.DBPath; con.Open(); using(var cmd = con.CreateCommand()) info.OutputOK(LogData.DumpTable(cmd, "LogData", "ID", info.Request.QueryString["offset"].Value, info.Request.QueryString["pagesize"].Value)); } }
public static void AddBackup(IBackup backup) { backups.Add(backup); }
public void SetParentBackup(IBackup parentBackup) { if (parentBackup != null && !(parentBackup is EntityBackup)) throw new InvalidOperationException("Parent backup must be an entity backup"); ParentBackup = parentBackup; }