private static void Backup(DBUtils dbu) { if (!dbu.GetCurrentVersion().Equals("none", StringComparison.InvariantCultureIgnoreCase)) { dbu.BackupDBS(); } }
private static void Restore(DBUtils dbu) { ICollection <BackupInfo> biColl = new System.Collections.ObjectModel.Collection <BackupInfo>(dbu.GetLocalBackups()); var toVersion = string.Empty; if (ArgsDict.Keys.Contains("ver")) { toVersion = ArgsDict["ver"]; } var tsFilter = string.Empty; if (ArgsDict.Keys.Contains("ts")) { tsFilter = ArgsDict["ts"]; } while (string.IsNullOrEmpty(toVersion)) { Console.Out.WriteLine("Local versions:"); foreach (var i in biColl.Select(p => p.Version).Distinct()) { Console.Out.WriteLine("\t{0}", i); } Console.Out.Write("Enter version to restore (or \"exit\" to exit):"); var res = Console.ReadLine(); if (res == "exit") { return; } var bi = biColl.Where(c => c.Version.Equals(res)).FirstOrDefault(); if (bi != null) { toVersion = bi.Version; } } DateTime ts = DateTime.MinValue; Dictionary <int, DateTime> tss = new Dictionary <int, DateTime>(); int num = 0; foreach (var bi in biColl.Where(c => c.Version.Equals(toVersion)).OrderByDescending(p => p.Timestamp)) { if (string.IsNullOrWhiteSpace(tsFilter) || bi.Timestamp.ToString(BaseUtils.TimestampFormatString).StartsWith(tsFilter, StringComparison.InvariantCultureIgnoreCase)) { tss.Add(num++, bi.Timestamp); } } while (ts == DateTime.MinValue) { Console.Out.WriteLine("Local backups for version {0}:", toVersion); foreach (var k in tss.Keys) { Console.Out.WriteLine("{0,3:D}\t{1}", k, tss[k]); } Console.Out.Write("Enter backup number to restore (or \"exit\" to exit):"); var res = Console.ReadLine(); if (res == "exit") { return; } num = -1; if (int.TryParse(res, out num) && tss.Keys.Contains(num)) { ts = tss[num]; } } if (!dbu.GetCurrentVersion().Equals("none", StringComparison.InvariantCultureIgnoreCase)) { Console.Out.Write("You are going to replace current version \"{0}\" with version \"{1} ({2})\".\nContinue(Y/N)?", dbu.GetCurrentVersion(), toVersion, ts); var ans = Console.ReadLine(); if (ans != "Y" && ans != "y") { return; } Console.Out.Write("Backup current version \"{0}\" before(Y/N)?", dbu.GetCurrentVersion()); ans = Console.ReadLine(); if (ans == "Y" || ans == "y") { dbu.BackupDBS(); } } dbu.RestoreDBS(toVersion, ts); }