public static void LoadCore_NewlyInitialized(bool encrypted, bool cache) { MetadataNode vfsroot = CreateBasicVirtualFS(1); BPlusTree <byte[]> datastore = new(10); var vfsisrc = new VirtualFSInterop(vfsroot, datastore); IDstFSInterop vfsidst; if (encrypted) { vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", "1"), "password"); } else { vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", "1")); } var vfsicache = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, "cache"); ICoreSrcDependencies srcdeps = FSCoreSrcDependencies.InitializeNew("test", "src", vfsisrc, "cache"); ICoreDstDependencies dstdeps = CoreDstDependencies.InitializeNew("test", false, vfsidst, true); ICoreDstDependencies?cachedeps = null; if (cache) { cachedeps = CoreDstDependencies.InitializeNew("test", true, vfsicache, false); } Core core = new(srcdeps, new List <ICoreDstDependencies>() { dstdeps }, cachedeps); Assert.IsTrue(core.DefaultDstDependencies.Count == 1); vfsisrc = new VirtualFSInterop(vfsroot, datastore); if (encrypted) { vfsidst = VirtualFSInterop.LoadDst(vfsroot, datastore, Path.Combine("dst", "1"), "password"); } else { vfsidst = VirtualFSInterop.LoadDst(vfsroot, datastore, Path.Combine("dst", "1")); } vfsicache = VirtualFSInterop.LoadDst(vfsroot, datastore, "cache"); srcdeps = FSCoreSrcDependencies.Load("src", vfsisrc); dstdeps = CoreDstDependencies.Load(vfsidst, true); cachedeps = null; if (cache) { cachedeps = CoreDstDependencies.Load(vfsicache, false); } _ = new Core(srcdeps, new List <ICoreDstDependencies>() { dstdeps }, cachedeps); }
private static void AddDestination(AddDestinationOptions opts) { var srcdep = FSCoreSrcDependencies.Load(cwd, new DiskFSInterop()); var settings = srcdep.ReadSettings(); bool cache_used = settings.ContainsKey(BackupSetting.cache); string bsname = GetBackupSetName(opts.BSName, srcdep); string?password = null; if (opts.PromptForPassword) { password = PasswordPrompt(); } string destination = opts.Destination.Trim(); if (destination.ToLower() == "backblaze") { destination = "backblaze"; if (opts.CloudConfigFile == null) { throw new ArgumentException("Cloud config file needed to initialize backblaze backup."); } CoreDstDependencies.InitializeNew(bsname, false, BackblazeDstInterop.InitializeNew(opts.CloudConfigFile, password), cache_used); } else { CoreDstDependencies.InitializeNew(bsname, false, DiskDstFSInterop.InitializeNew(destination, password), cache_used); } List <string> dstlistings; if (settings.ContainsKey(BackupSetting.dests)) { dstlistings = settings[BackupSetting.dests].Split(';', StringSplitOptions.RemoveEmptyEntries).Select(d => d.Trim()).ToList(); } else { dstlistings = new List <string>(); } List <string[]> dsts_passopts_cc = dstlistings.Select(dl => dl.Split('|')).ToList(); dsts_passopts_cc.Add(new string[] { destination, password != null ? "p" : "n", opts.CloudConfigFile ?? "" }); dstlistings = dsts_passopts_cc.Select(dpc => string.Join('|', dpc)).ToList(); srcdep.WriteSetting(BackupSetting.dests, string.Join(';', dstlistings)); }
public static Core LoadCore() { var srcdep = FSCoreSrcDependencies.Load(cwd, new DiskFSInterop()); string?cache; string?destinations; try { destinations = srcdep.ReadSetting(BackupSetting.dests); } catch (KeyNotFoundException) { destinations = null; } try { cache = srcdep.ReadSetting(BackupSetting.cache); } catch (KeyNotFoundException) { cache = null; } if (destinations == null) { string?destination = GetBUDestinationDir(); if (destination != null) // We are in a backup destination { try { // TODO: password support here return(Core.LoadDiskCore(null, new List <(string, string?)>(1) { (destination, null) }, null)); }