public static void InitializeNew(bool cache, int nonencrypteddsts, int encrypteddsts) { MetadataNode vfsroot = CreateBasicVirtualFS(nonencrypteddsts + encrypteddsts); BPlusTree <byte[]> datastore = new(10); var vfsisrc = new VirtualFSInterop(vfsroot, datastore); List <ICoreDstDependencies> destinations = new(); for (int i = 0; i < nonencrypteddsts + encrypteddsts; i++) { IDstFSInterop vfsidst; if (i < nonencrypteddsts) { vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", i.ToString())); } else { vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", i.ToString()), "password"); } destinations.Add(CoreDstDependencies.InitializeNew("test", false, vfsidst, true)); } var vfsicache = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, "cache"); ICoreSrcDependencies srcdeps = FSCoreSrcDependencies.InitializeNew("test", "src", vfsisrc); if (cache) { ICoreDstDependencies cachedeps = CoreDstDependencies.InitializeNew("test", true, vfsicache, false); _ = new Core(srcdeps, destinations, cachedeps); } else { _ = new Core(srcdeps, destinations); } }
private static ICoreSrcDependencies CreateNewSrc(Random random) { DateTime dateTime = CoreTest.RandomDateTime(random); MetadataNode vfsroot = new(VirtualFSInterop.MakeNewDirectoryMetadata("src", dateTime), null); BPlusTree <byte[]> datastore = new(10); CoreTest.AddStandardVFSFiles(vfsroot, datastore, random); IFSInterop srcFSInterop = new VirtualFSInterop(vfsroot, datastore); return(FSCoreSrcDependencies.InitializeNew("test", "", srcFSInterop)); }
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)); }
/* * int Main(string[] args) * { * return CommandLine.Parser.Default.ParseArguments<AddOptions, CommitOptions, CloneOptions>(args) * .MapResult( * (AddOptions opts) => RunAddAndReturnExitCode(opts), * (CommitOptions opts) => RunCommitAndReturnExitCode(opts), * (CloneOptions opts) => RunCloneAndReturnExitCode(opts), * errs => 1); * }*/ private static void Initialize(InitOptions opts) { try { ICoreSrcDependencies srcdep = FSCoreSrcDependencies.InitializeNew(opts.BSName, cwd, new DiskFSInterop(), opts.Cache); if (opts.Cache != null) { var cachedep = CoreDstDependencies.InitializeNew(opts.BSName, true, DiskDstFSInterop.InitializeNew(opts.Cache), false); } } catch (Exception e) { Console.WriteLine(e.Message); } }
MetadataNode vfsroot, BPlusTree <byte[]> vfsdatastore) InitializeNewCoreWithStandardFiles( int nonencrypteddsts, int encrypteddsts, Random?random = null, bool cache = true, int regFileCount = 100) { MetadataNode vfsroot = CreateBasicVirtualFS(nonencrypteddsts + encrypteddsts); BPlusTree <byte[]> vfsdatastore = new(10); MetadataNode? vfsDirectory = vfsroot.GetDirectory("src"); if (vfsDirectory == null) { throw new NullReferenceException(); } Dictionary <string, byte[]> verifyfilepaths = AddStandardVFSFiles(vfsDirectory, vfsdatastore, random, regFileCount); var vfsisrc = new VirtualFSInterop(vfsroot, vfsdatastore); List <ICoreDstDependencies> destinations = new(); for (int i = 0; i < nonencrypteddsts + encrypteddsts; i++) { IDstFSInterop vfsidst; if (i < nonencrypteddsts) { vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, vfsdatastore, Path.Combine("dst", i.ToString())); } else { vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, vfsdatastore, Path.Combine("dst", i.ToString()), "password"); } ICoreDstDependencies dstdeps = CoreDstDependencies.InitializeNew("test", false, vfsidst, cache); destinations.Add(dstdeps); } var vfsicache = VirtualFSInterop.InitializeNewDst(vfsroot, vfsdatastore, "cache"); ICoreSrcDependencies srcdeps = FSCoreSrcDependencies.InitializeNew("test", "src", vfsisrc, "cache"); ICoreDstDependencies?cachedeps = null; if (cache) { cachedeps = CoreDstDependencies.InitializeNew("test", true, vfsicache, false); } Core core = new(srcdeps, destinations, cachedeps); return(core, verifyfilepaths, vfsroot, vfsdatastore); }
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)); }