From 066d5d55548f5843f3e5570f23664f47a5a9d3e9 Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Mon, 5 May 2025 17:41:23 +0200 Subject: [PATCH] v1.32.0 - MoveSQLDB from PRIMARY to SECONDARY rendbehozása --- Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs | 366 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 194 insertions(+), 176 deletions(-) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index 76a37ef..a017486 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -64,7 +64,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.CreateLoginAndUser.KEY, "Create Server login", CreateServerLogin, ep)) .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.AddUserForLogin.KEY, "Create DB user", CreateDBUser, ep)) .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.CreateLastUpdatedTrigger.KEY, "Add/remove LastUpdated trigger to a datatable column", ManageLastUpdatedTrigger, ep)) - .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.MoveDbToRemoteServer.KEY, "Move DB from local to remote server", MoveDbToRemoteServer, ep)) + .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.MoveDbToRemoteServer.KEY, "Move DB from local to remote server", MoveDbFromPrimaryToSecondary, ep)) .SetSelectionMode(Menu.SelectionMode.Single) .SetMenuHeaderDisplayer(DataBaseListDisplayer); menufunctions.ExecuteMenu(functionkey); @@ -186,7 +186,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS try { if (NoDBNameSpecified(sqld)) { return o; } - var targetdirectorypath = sqld.Xml_PhysicalFilesDirectoryPath; + var targetdirectorypath = sqld.Xml_PrimaryDB_PhysicalFilesDirectoryPath; var targetdbname = sqld.DBName; bool restorefromzip = sqld.Xml_CreateZip; var backupfilelist = SQLDataBaseManagerCore.GetBackupFilePathList(sqld); @@ -338,7 +338,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS bool allconfirmed = false; foreach (var SrvrLoginToExecute in ServerLoginsToExecuteList) { - var retcode = ExecuteOneServerLogin(sqld.SQLCS, SrvrLoginToExecute, allconfirmed); + var retcode = ExecuteOneServerLogin(sqld.SQLCS_Primary, SrvrLoginToExecute, allconfirmed); if (retcode == "EX") return o; else if (retcode == "ALL") { allconfirmed = true; } else if (retcode != null) goto getparametersloop; @@ -554,7 +554,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS bool allconfirmed = false; foreach (var DbusrToExecute in DbusrToExecuteList) { - var retcode = ExecuteOneDBUser(sqld.SQLCS, DbusrToExecute, allconfirmed); + var retcode = ExecuteOneDBUser(sqld.SQLCS_Primary, DbusrToExecute, allconfirmed); if (retcode == "EX") return o; else if (retcode == "ALL") { allconfirmed = true; } else if (retcode != null) goto getparametersloop; @@ -616,10 +616,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS catch (Exception e) { ColorConsole.WriteLine("FATAL ERROR! " + e.MessageNested(), ConsoleColor.Red); returntext = null; } return returntext; } - #endregion CreateDBUser + #endregion CreateDBUser - #region MoveDbToRemoteServer - private static object MoveDbToRemoteServer(object parameter, object o) + #region MoveDbFromPrimaryToSecondary + private static object MoveDbFromPrimaryToSecondary(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); var args = (parameter as Menu.ExecutorParameter).Args; @@ -629,122 +629,113 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS while (true) { var DateTimeNow = DateTime.Now; - SQLDataBase dbfrom = null; - SQLDataBase dbto = null; + SQLDataBase dbtomove = null; movedatabaseloop: (Menu.SelectionResult selectionresult, bool yes) yesornoanswer = YesOrNo(new List() { $"Do You want to move ANY database from local server to remote server?" }); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - var dbselection = SelectToDbAndFromDb(config, selectedsqldbindexes, $"Select the SQL database(s) to move the first to the second.!"); + var dbselection = SelectDbToMove(config, selectedsqldbindexes, $"Select the SQL database to move from its PRIMARY to SECONDARY location!"); if (dbselection.selection == Menu.SelectionResult.Exit) { return o; } if (dbselection.selection != Menu.SelectionResult.Ok) { goto movedatabaseloop; } - dbfrom = dbselection.dbfrom; - dbto = dbselection.dbto; - if (NoDBNameSpecified(dbfrom) || NoDBNameSpecified(dbto)) { continue; } + dbtomove = dbselection.dbtomove; + if (NoDBNameSpecified(dbtomove)) { continue; } + var dbnameSecondary = SQLDataBaseManagerCore.GetDBName(dbtomove.SQLCS_Secondary); - var todbname = ColorConsole.ReadLine($"Enter the name of the target DB. EMPTY={dbto.DBName}, EX=exit."); + var todbname = ColorConsole.ReadLine($"Enter the name of the target DB. EMPTY={dbnameSecondary}, EX=exit."); if (todbname.ToUpper() == "EX") { return o; } - else if (string.IsNullOrWhiteSpace(todbname)) todbname = dbto.DBName; + else if (string.IsNullOrWhiteSpace(todbname)) todbname = dbnameSecondary; confirmloop:; var confirmtext = ColorConsole.ReadLine("Enter CONFIRM to start, EX to exit, SKIP to skip."); if (confirmtext.ToUpper() == "EX") { return o; } else if (confirmtext.ToUpper() == "CONFIRM") { - var movesuccess = SQLDataBaseManagerCore.MoveDbToRemoteServer(dbfrom, dbto, todbname, false); + var movesuccess = SQLDataBaseManagerCore.MoveDbFromPrimaryToSecondary(dbtomove, todbname, false); if (!movesuccess) continue; } else if (confirmtext.ToUpper() != "SKIP") { goto confirmloop; }; } serverloginloop: - yesornoanswer = YesOrNo(new List() { $"Do You want to create server and DB logins for local and/or remote server/database?", }); + yesornoanswer = YesOrNo(new List() { $"Do You want to create server and DB logins for the server/database PRIMARY and/or SECONDARY locations?", }); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - if (dbfrom == null || dbto == null) + if (dbtomove == null) { - var dbselection = SelectToDbAndFromDb(config, selectedsqldbindexes, $"Select the SQL database(s) to add server and DB logins!"); + var dbselection = SelectDbToMove(config, selectedsqldbindexes, $"Select the SQL database to add server and DB logins to its PRIMARY and its SECONDARY location!"); if (dbselection.selection == Menu.SelectionResult.Exit) { return o; } if (dbselection.selection != Menu.SelectionResult.Ok) { goto serverloginloop; } - dbfrom = dbselection.dbfrom; - dbto = dbselection.dbto; + dbtomove = dbselection.dbtomove; } var usernamelist = new string[] { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; - string l1 = $"Do You want to create the following mandatory server and DB logins for SOURCE server and DB?"; - string l2 = $" SQL connection string: {dbfrom.SQLCS}"; + string l1 = $"Do You want to create the following mandatory server/database logins for the PRIMARY location?"; + string l2 = $" SQL connection string: {dbtomove.SQLCS_Primary}"; string l3 = $" Username list: " + string.Join(",", usernamelist); yesornoanswer = YesOrNo(new List() { l1, l2, l3, }); if (yesornoanswer.selectionresult== Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbfrom.SQLCS, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); + SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbtomove.SQLCS_Primary, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); } - string l13 = $"Do You want to create the following mandatory server and DB logins for TARGET server and DB?"; - string l23 = $" SQL connection string: {dbto.SQLCS}"; + string l13 = $"Do You want to create the following mandatory server/database logins for SECONDARY location?"; + string l23 = $" SQL connection string: {dbtomove.SQLCS_Secondary}"; string l33 = $" Username list: " + string.Join(",", usernamelist); yesornoanswer = YesOrNo(new List() { l13,l23,l33,}); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbto.SQLCS, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); + SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbtomove.SQLCS_Secondary, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); } } - yesornoanswer = YesOrNo(new List() { $"Do You want to set database '{SQLDataBaseManagerCore.GetDBName(dbfrom.SQLCS)}' OFFLINE on server '{SQLDataBaseManagerCore.GetDataSource(dbfrom.SQLCS)}'?", }); + yesornoanswer = YesOrNo(new List() { $"Do You want to set database '{SQLDataBaseManagerCore.GetDBName(dbtomove.SQLCS_Primary)}' OFFLINE on server '{SQLDataBaseManagerCore.GetDataSource(dbtomove.SQLCS_Primary)}'?", }); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - SQLDataBaseManagerCore.SetDatabaseOffline(dbfrom.SQLCS); + SQLDataBaseManagerCore.SetDatabaseOffline(dbtomove.SQLCS_Primary); } ColorConsole.WriteLine($"Process completed. Required time: {(int)(DateTime.Now.Subtract(DateTimeNow).TotalSeconds)} seconds.", ConsoleColor.Green); } } - private static (Menu.SelectionResult selection,SQLDataBase dbfrom,SQLDataBase dbto) SelectToDbAndFromDb(SQLDataBaseManagerXmlProcessor config, string selectedsqldbindexes, string databaseselectionheadertext) + private static (Menu.SelectionResult selection,SQLDataBase dbtomove) SelectDbToMove(SQLDataBaseManagerXmlProcessor config, string selectedsqldbindexes, string databaseselectionheadertext) { - var menufolders = DisplaySQLDataBaseMenu(config, $"{databaseselectionheadertext} Format:FROMLOCALDB,TOREMOTEDB", silent: true, selectionmode: Menu.SelectionMode.Multi); + var menufolders = DisplaySQLDataBaseMenu(config, $"{databaseselectionheadertext} Format:DB", silent: true, selectionmode: Menu.SelectionMode.Single); Menu.Selection sr = menufolders.Select(selectedsqldbindexes); - if (sr.Result == Menu.SelectionResult.Exit) { return (Menu.SelectionResult.Exit, null,null); } - else if (sr.Result == Menu.SelectionResult.None) { return (Menu.SelectionResult.None, null,null); } - else if (sr.Result == Menu.SelectionResult.Error) { return (Menu.SelectionResult.Error, null, null); } - else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.FirstOrDefault() == null) { return (Menu.SelectionResult.Error, null, null); } - else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.Count() != 2) + if (sr.Result == Menu.SelectionResult.Exit) { return (Menu.SelectionResult.Exit, null); } + else if (sr.Result == Menu.SelectionResult.None) { return (Menu.SelectionResult.None, null); } + else if (sr.Result == Menu.SelectionResult.Error) { return (Menu.SelectionResult.Error, null); } + else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.FirstOrDefault() == null) { return (Menu.SelectionResult.Error, null); } + else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.Count() != 1) { - ColorConsole.WriteLine($"Select exactly 2 DB. Format:FROMLOCALDB,TOREMOTEDB", ConsoleColor.Red); - return (Menu.SelectionResult.Error, null, null); + ColorConsole.WriteLine($"Select only one DB. Format:DB", ConsoleColor.Red); + return (Menu.SelectionResult.Error, null); } else if (sr.Result == Menu.SelectionResult.Ok) { } else { } - var spfrom = sr.SelectedParameterList.First(); - var spto = sr.SelectedParameterList.ElementAt(1); - SQLDataBase dbfrom = spfrom.Parameters as SQLDataBase; - SQLDataBase dbto = spto.Parameters as SQLDataBase; - if (!dbto.Xml_IsRemoteDB) + var spdb = sr.SelectedParameterList.First(); + SQLDataBase dbtomove = spdb.Parameters as SQLDataBase; + if (string.IsNullOrWhiteSpace(dbtomove.Xml_SecondaryDB_SQLConnectionString)) { - ColorConsole.WriteLine($"TOREMOTEDB '{dbto.SQLCS}' has to be remote!", ConsoleColor.Red); - return (Menu.SelectionResult.Error, null, null); + ColorConsole.WriteLine($"No SECONDARY db is specified!", ConsoleColor.Red); + return (Menu.SelectionResult.Error, null); } - if (dbfrom.Xml_IsRemoteDB) - { - ColorConsole.WriteLine($"FROMLOCALDB '{dbfrom.SQLCS}' has to be local!", ConsoleColor.Red); - return (Menu.SelectionResult.Error, null, null); - } - return (Menu.SelectionResult.Ok, dbfrom,dbto); + return (Menu.SelectionResult.Ok, dbtomove); } private static (Menu.SelectionResult selectionresult, bool yes) YesOrNo(List questiontextLines) { if (questiontextLines!=null) foreach(string l in questiontextLines) { ColorConsole.WriteLine(l, ConsoleColor.Yellow); } var yesorno = ColorConsole.ReadLine("Do action?", ConsoleColor.Yellow, validitylist: new List { "yes", "no" }, defaultvalue: "yes"); if (yesorno.ToUpper() == "EX") return (Menu.SelectionResult.Exit, false); - else if (yesorno.ToUpper() == "yes") return (Menu.SelectionResult.Ok, true); + else if (yesorno.ToUpper() == "YES") return (Menu.SelectionResult.Ok, true); else return (Menu.SelectionResult.Ok, false); } - #endregion MoveDbToRemoteServer + #endregion MoveDbFromPrimaryToSecondary #region ManageLastUpdatedTrigger private static object ManageLastUpdatedTrigger(object parameter, object o) { return _ManageLastUpdatedTrigger(parameter, o, null); } @@ -908,7 +899,7 @@ GO bool allconfirmed = false; foreach (var triggertoexecute in TriggerToExecuteList) { - var retcode = ExecuteOneLastUpdateTrigger(sqld.SQLCS, triggertoexecute, allconfirmed); + var retcode = ExecuteOneLastUpdateTrigger(sqld.SQLCS_Primary, triggertoexecute, allconfirmed); if (retcode == "EX") return o; else if (retcode == "ALL") { allconfirmed = true; } else if (retcode != null) goto getparametersloop; @@ -1118,7 +1109,7 @@ GO } if (string.IsNullOrWhiteSpace(dbnamemask)) { dbnamemask = ""; } - var dbdescriptordict = SQLDataBaseManagerCore.GetDatabases(sqld.SQLCS, dbnamemask, userid, password); + var dbdescriptordict = SQLDataBaseManagerCore.GetDatabases(sqld.SQLCS_Primary, dbnamemask, userid, password); ColorConsole.WriteLine(text: "Available DBs", f: ConsoleColor.Yellow,suffix: $" (name masked with:'{dbnamemask}')"); foreach (var (dbdescriptor,ix) in dbdescriptordict.Select((text,ix)=> (text, ix))) { @@ -1140,7 +1131,7 @@ GO if (string.IsNullOrWhiteSpace(dbname)) { dbname = sqld.DBName; } ColorConsole.WriteLine($"Dropping DB..."); - ColorConsole.WriteLine(prefix: " connection string to server:", text: sqld.SQLCS, bracket: "[]", f: ConsoleColor.Yellow); + ColorConsole.WriteLine(prefix: " connection string to server:", text: sqld.SQLCS_Primary, bracket: "[]", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " DB name to drop:", text: dbname, bracket: "[]", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " userid:", text: userid ?? "-", bracket: "[]", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " user psw:", text: password ?? "-", bracket: "[]", f: ConsoleColor.Yellow); @@ -1148,7 +1139,7 @@ GO if (confirmation.ToUpper() == "EX") { continue; } else if (confirmation.ToUpper() != "CONFIRM") { continue; } - var success = SQLDataBaseManagerCore.DropDatabase(sqld.SQLCS, dbname, userid, password); + var success = SQLDataBaseManagerCore.DropDatabase(sqld.SQLCS_Primary, dbname, userid, password); if (success) { ColorConsole.WriteLine($"SUCCESS! Database dropped. Name:{dbname}", ConsoleColor.Green); } else { ColorConsole.WriteLine($"FAILURE! Database is NOT dropped. Name:{dbname}", ConsoleColor.Red); } } @@ -1193,7 +1184,7 @@ GO var shrinkmethod = (ShrinkMethod)Enum.Parse(typeof(ShrinkMethod), option); if (string.IsNullOrWhiteSpace(fsp) || !int.TryParse(fsp, out fspint)) { fspint = 10; } - SQLDataBaseManagerCore.ShrinkDB(sqld.SQLCS, shrinkmethod, fspint); + SQLDataBaseManagerCore.ShrinkDB(sqld.SQLCS_Primary, shrinkmethod, fspint); ColorConsole.WriteLine($"Database shrinked. Name:{sqld.DBName}", ConsoleColor.Green); } catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } @@ -1225,15 +1216,15 @@ GO if (restoredbname.ToUpper() == "EX") { continue; } else if (string.IsNullOrWhiteSpace(restoredbname)) { restoredbname = sqld.DBName; } ColorConsole.WriteLine("Enter the path for the DB physical files.", ConsoleColor.Yellow); - var PhysicalFilesDirectoryPathcolor = sqld.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; - ColorConsole.WriteLine(sqld.PhysicalFilesDirectoryPath, PhysicalFilesDirectoryPathcolor, prefix: $" Empty=current location of source DB: ", bracket: "[]"); - ColorConsole.WriteLine(SQLDataBaseManagerCore.GetServerDefaultPhysicalDATFileLocation(sqld.SQLCS)??"???", ConsoleColor.Yellow,prefix: $" DEFAULT= sql server default location.",bracket:"[]"); + var PhysicalFilesDirectoryPathcolor = sqld.PrimaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.WriteLine(sqld.PrimaryDB_PhysicalFilesDirectoryPath, PhysicalFilesDirectoryPathcolor, prefix: $" Empty=current location of source DB: ", bracket: "[]"); + ColorConsole.WriteLine(SQLDataBaseManagerCore.GetServerDefaultPhysicalDATFileLocation(sqld.SQLCS_Primary)??"???", ConsoleColor.Yellow,prefix: $" DEFAULT= sql server default location.",bracket:"[]"); var targetdirectory = ColorConsole.ReadLine($"Enter the target path.EX=exit.", ConsoleColor.Yellow, suffix: " --> "); if (targetdirectory.ToUpper() == "EX") { continue; } else if (targetdirectory == "DEFAULT") { targetdirectory = null; ; } - else if (string.IsNullOrWhiteSpace(targetdirectory)) { targetdirectory = sqld.PhysicalFilesDirectoryPath; } + else if (string.IsNullOrWhiteSpace(targetdirectory)) { targetdirectory = sqld.PrimaryDB_PhysicalFilesDirectoryPath; } - if (restoredbname == sqld.DBName && targetdirectory == sqld.PhysicalFilesDirectoryPath) { continue; } + if (restoredbname == sqld.DBName && targetdirectory == sqld.PrimaryDB_PhysicalFilesDirectoryPath) { continue; } SQLDataBaseManagerCore.RelocatePhysicalFiles(sqld, targetdirectory, restoredbname); ColorConsole.WriteLine($"Database physical files relocated. Name:{sqld.DBName}", ConsoleColor.Green); @@ -1248,7 +1239,7 @@ GO private static bool NoDBNameSpecified(SQLDataBase ssqldb) { const string FUNNOTAVAILTXT = "Function is not available for server connection strings wit no DB name specified!"; - if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); ssqldb.DBName = "master"; return true; } + if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS_Primary))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); ssqldb.DBName = "master"; return true; } return false; } public static void Execute(string key, bool enabledbbackup, bool enablescriptbackup, bool enabletabledatabackup, string targetfolder=null,DateTime? timestamp = null) @@ -1259,7 +1250,7 @@ GO if (origsqld != null) { var sqld = new SQLDataBase(origsqld); - var dbname = SQLDataBaseManagerCore.GetDBName(sqld.SQLCS); + var dbname = SQLDataBaseManagerCore.GetDBName(sqld.SQLCS_Primary); ColorConsole.WriteLine($"Database backup process started. DB key:'{key}', name:'{dbname}'...", ConsoleColor.Yellow); if (!string.IsNullOrWhiteSpace(targetfolder)) { sqld.Xml_BackupTargetDirectoryPath = targetfolder; } if (enabledbbackup) { SQLDataBaseManagerCore.CreateBackup(sqld,null, timestamp); } @@ -1303,7 +1294,7 @@ GO if (st.Status != SQLDataBase.SQLDBStatus.NoAccess) { } - if (st.Xml_IsRemoteDB) { ColorConsole.Write("REMOTE", ConsoleColor.Cyan, bracket: "[]", prefix: "", suffix: ""); } + if (st.Xml_PrimaryDB_IsUseTranzit) { ColorConsole.Write("REMOTE", ConsoleColor.Cyan, bracket: "[]", prefix: "", suffix: ""); } ColorConsole.WriteLine(); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } @@ -1316,16 +1307,16 @@ GO } else if (lineix == 2) { - if (!st.isSQLCSselected) { return Menu.MenuItemDisplayerReturnValue.SAMELINE; } - ColorConsole.Write($"{st.SQLCS}", ConsoleColor.Yellow, prefix: "SQL DB connection:", suffix: ", "); + if (!st.is_PrimaryDB_SQLCSselected) { return Menu.MenuItemDisplayerReturnValue.SAMELINE; } + ColorConsole.Write($"{st.SQLCS_Primary}", ConsoleColor.Yellow, prefix: "SQL DB connection:", suffix: ", "); ColorConsole.WriteLine(" "); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } else if (lineix == 3) { if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; - var PhysicalFilesDirectoryPathcolor = st.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; - ColorConsole.Write($"{st.PhysicalFilesDirectoryPath}", PhysicalFilesDirectoryPathcolor, prefix: "DB files physical location:", suffix: " "); + var PhysicalFilesDirectoryPathcolor = st.PrimaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write($"{st.PrimaryDB_PhysicalFilesDirectoryPath}", PhysicalFilesDirectoryPathcolor, prefix: "DB files physical location:", suffix: " "); ColorConsole.WriteLine(" "); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } @@ -1374,45 +1365,45 @@ GO /// /// Egy adatbázis átmozgatása egy távoli szerverre /// - /// + /// /// /// /// /// - public static bool MoveDbToRemoteServer(SQLDataBase dbfrom, SQLDataBase dbto, string selecteddbname, bool emulation) + public static bool MoveDbFromPrimaryToSecondary(SQLDataBase dbtomove, string selecteddbname, bool emulation) { //backup dbfrom var DateTimeNow = DateTime.Now; - var backupfileFullname = SQLDataBaseManagerCore.CreateBackup(dbfrom, false, DateTimeNow, emulation); - //move dbfrom to tranit area + var backupfileFullname = SQLDataBaseManagerCore.CreateBackup(dbtomove, false, DateTimeNow, emulation); if (!emulation && !File.Exists(backupfileFullname)) { return false; } - string backupfileFilename = null; - string tranzitfileFullname = null; - try + string tranzitfileFullname = backupfileFullname; + if (dbtomove.Xml_SecondaryDB_IsUseTranzit) { - backupfileFilename = Path.GetFileName(backupfileFullname); - tranzitfileFullname = Path.Combine(dbto.Xml_TranzitDirectoryPath, backupfileFilename); - ColorConsole.WriteLine($"Moving backup file {backupfileFullname} to tranzit location: {dbto.Xml_TranzitDirectoryPath}", ConsoleColor.Yellow); - if (!emulation) - { - if (File.Exists(tranzitfileFullname)) { File.Delete(tranzitfileFullname); } - File.Move(backupfileFullname, tranzitfileFullname); - ColorConsole.WriteLine($"...completed...", ConsoleColor.Yellow); - } - } - catch (Exception ex) - { - ColorConsole.WriteLine($"Moving file FAILED!", ConsoleColor.Red); - ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); - return false; - } - if (!emulation && !File.Exists(tranzitfileFullname)) { return false; } + try + { + string backupfileFilename = Path.GetFileName(backupfileFullname); + tranzitfileFullname = Path.Combine(dbtomove.Xml_SecondaryDB_TranzitDirectoryPath, backupfileFilename); + ColorConsole.WriteLine($"Moving backup file {backupfileFullname} to tranzit location: {dbtomove.Xml_SecondaryDB_TranzitDirectoryPath}", ConsoleColor.Yellow); + if (!emulation) + { + if (File.Exists(tranzitfileFullname)) { File.Delete(tranzitfileFullname); } + File.Move(backupfileFullname, tranzitfileFullname); + ColorConsole.WriteLine($"...completed...", ConsoleColor.Yellow); + } + } + catch (Exception ex) + { + ColorConsole.WriteLine($"Moving file FAILED!", ConsoleColor.Red); + ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); + return false; + } + } + if (!emulation && !File.Exists(tranzitfileFullname)) { return false; } //restore backup to dbto - tranzitfileFullname = Path.Combine(dbto.Xml_TranzitDirectoryPath, backupfileFilename); - SQLDataBaseManagerCore.RestoreBackup(dbto, tranzitfileFullname, dbto.Xml_PhysicalFilesDirectoryPath, false, selecteddbname, emulation); + SQLDataBaseManagerCore.RestoreBackup(dbtomove, tranzitfileFullname, dbtomove.Xml_SecondaryDB_PhysicalFilesDirectoryPath, false, selecteddbname, emulation); return true; } @@ -1427,13 +1418,13 @@ GO /// public static void RestoreBackup(SQLDataBase sqldb, string sourcesqlbackupfilepath, string targetdbphysicalfilesdirectorypath, bool restorefromZIP = false, string restoretodbname = null,bool emulate=false) { - string sqlcs = sqldb.SQLCS; //sqlcs = sqlcs.Replace("LearALM2", "master"); + string sqlcs = sqldb.SQLCS_Primary; //sqlcs = sqlcs.Replace("LearALM2", "master"); string zippedbackupfilepath = restorefromZIP? sourcesqlbackupfilepath:Path.Combine(Path.GetDirectoryName(sourcesqlbackupfilepath), Path.GetFileNameWithoutExtension(sourcesqlbackupfilepath) + ".zip"); string normalbackupfilepath = !restorefromZIP? sourcesqlbackupfilepath : Path.Combine(Path.GetDirectoryName(sourcesqlbackupfilepath), Path.GetFileNameWithoutExtension(sourcesqlbackupfilepath) + ".bak"); ColorConsole.WriteLine(nameof(RestoreBackup), ConsoleColor.Yellow, prefix: "running...."); ColorConsole.WriteLine(restoretodbname, ConsoleColor.Yellow, prefix: " restoretodbname:"); - ColorConsole.WriteLine(sqldb.SQLCS, ConsoleColor.Yellow, prefix: " sqldb.SQLCS:"); + ColorConsole.WriteLine(sqldb.SQLCS_Primary, ConsoleColor.Yellow, prefix: " sqldb.SQLCS:"); ColorConsole.WriteLine(sourcesqlbackupfilepath, ConsoleColor.Yellow, prefix: " sourcesqlbackupfilepath:"); ColorConsole.WriteLine(normalbackupfilepath, ConsoleColor.Yellow, prefix: " backupfilepath:"); ColorConsole.WriteLine(restorefromZIP.ToString(), ConsoleColor.Yellow, prefix: " restorefromZIP:"); @@ -1520,16 +1511,15 @@ GO public static string CreateBackup(SQLDataBase sqld,bool? forcecreatezip, DateTime? timestamp,bool emulate=false) { string backupdirectorypath = sqld.Xml_BackupTargetDirectoryPath; - string tranzitdirectorypath = sqld.Xml_TranzitDirectoryPath; - bool usetranzit = sqld.Xml_IsRemoteDB; + string tranzitdirectorypath = sqld.Xml_PrimaryDB_TranzitDirectoryPath; string backupfilenamemask = sqld.Xml_BackupFileNameMask; bool createzip = forcecreatezip ?? sqld.Xml_CreateZip; //tranzitdirectorypathlocal = @"F:\ALM"; //tranzitdirectorypathnetwork = @"\\matng-sql01\ALM"; string returnfilename = null; - var dbname = GetDBName(sqld.SQLCS); - var datasource = GetDataSource(sqld.SQLCS); + var dbname = GetDBName(sqld.SQLCS_Primary); + var datasource = GetDataSource(sqld.SQLCS_Primary); var backupts = (timestamp.HasValue ? timestamp.Value : DateTime.Now).ToString("yyyyMMddHHmmss"); @@ -1547,7 +1537,7 @@ GO string backupfilename = backupfileNameOnly + ".bak"; string backupFullName = Path.Combine(backupdirectorypath, backupfilename); - string tranzitFullName = usetranzit ? Path.Combine(tranzitdirectorypath, backupfilename) : null; + string tranzitFullName = sqld.Xml_PrimaryDB_IsUseTranzit ? Path.Combine(tranzitdirectorypath, backupfilename) : null; string ZIPbackupfilename = backupfileNameOnly + ".zip"; string ZIPbackupFullName = Path.Combine(backupdirectorypath, ZIPbackupfilename); @@ -1555,7 +1545,7 @@ GO ColorConsole.WriteLine(nameof(CreateBackup), ConsoleColor.Yellow, prefix: "running...."); ColorConsole.WriteLine(dbname, ConsoleColor.Yellow, prefix: " dbname:"); - ColorConsole.WriteLine(sqld.SQLCS, ConsoleColor.Yellow, prefix: " sqld.SQLCS:"); + ColorConsole.WriteLine(sqld.SQLCS_Primary, ConsoleColor.Yellow, prefix: " sqld.SQLCS:"); ColorConsole.WriteLine(backupdirectorypath, ConsoleColor.Yellow, prefix: " backupdirectorypath:"); ColorConsole.WriteLine(backupfilename, ConsoleColor.Yellow, prefix: " backupfilename:"); ColorConsole.WriteLine(backupFullName, ConsoleColor.Yellow, prefix: " backupFullName:"); @@ -1565,7 +1555,7 @@ GO ColorConsole.WriteLine(ZIPbackupfilename, ConsoleColor.Yellow, prefix: " ZIPbackupfilename:"); ColorConsole.WriteLine(ZIPbackupFullName, ConsoleColor.Yellow, prefix: " ZIPbackupFullName:"); } - ColorConsole.WriteLine(usetranzit.ToString(), ConsoleColor.Yellow, prefix: " usetranzit:"); + ColorConsole.WriteLine(sqld.Xml_PrimaryDB_IsUseTranzit.ToString(), ConsoleColor.Yellow, prefix: " usetranzit:"); ColorConsole.WriteLine(tranzitFullName, ConsoleColor.Yellow, prefix: " tranzitFullName:"); ColorConsole.WriteLine(returnfilename, ConsoleColor.Yellow, prefix: " returnfilename:"); @@ -1580,12 +1570,12 @@ GO smoBackup.BackupSetDescription = $"Full Backup of {smoBackup.Database}"; smoBackup.MediaDescription = "Disk"; Console.WriteLine($"Backup set: {smoBackup.BackupSetName} ({smoBackup.BackupSetDescription}) to media: {smoBackup.MediaDescription}"); - string dummystring = usetranzit ? " REMOTE SQL SERVER!" : ""; + string dummystring = sqld.Xml_PrimaryDB_IsUseTranzit ? " REMOTE SQL SERVER!" : ""; Console.WriteLine($"Database name: {smoBackup.Database}{dummystring}"); - Console.WriteLine($"Connection string: {sqld.SQLCS}"); - smoBackup.Devices.AddDevice(usetranzit ? tranzitFullName : backupFullName, DeviceType.File); + Console.WriteLine($"Connection string: {sqld.SQLCS_Primary}"); + smoBackup.Devices.AddDevice(sqld.Xml_PrimaryDB_IsUseTranzit ? tranzitFullName : backupFullName, DeviceType.File); Console.WriteLine($"Backup full name:{backupFullName}"); - if (usetranzit) + if (sqld.Xml_PrimaryDB_IsUseTranzit) { Console.WriteLine($" ...will be created through tranzit: {tranzitFullName}"); } @@ -1595,7 +1585,7 @@ GO Server sqlserver = null; try { - sqlserver = SQLServerConnect(sqld.SQLCS, "master"); if (sqlserver == null) { return null; } + sqlserver = SQLServerConnect(sqld.SQLCS_Primary, "master"); if (sqlserver == null) { return null; } sqlserver.ConnectionContext.StatementTimeout = sqld.Xml_BackupTimeout; backupstarttime = DateTime.Now; smoBackup.SqlBackup(sqlserver); @@ -1611,7 +1601,7 @@ GO return null; } finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } - if (usetranzit && File.Exists(tranzitFullName)) + if (sqld.Xml_PrimaryDB_IsUseTranzit && File.Exists(tranzitFullName)) { File.Move(tranzitFullName, backupFullName); Console.WriteLine($"Moving backup file..."); @@ -2336,14 +2326,14 @@ GO #region BackupSqlScripts public static void BackupSqlScripts(SQLDataBase sqld, DateTime? timestamp=null) { - if (sqld.Xml_IsRemoteDB) + if (sqld.Xml_PrimaryDB_IsUseTranzit) { ColorConsole.WriteLine(text:$" {nameof(BackupSqlScripts)}: scrip backup is not available for remote SQL Servers! DBname:'{sqld.DBName}'.",prefix:$"WARNING!",f: ConsoleColor.Yellow); return; } string backupdirectorypath = sqld.Xml_BackupTargetDirectoryPath; string backupfilenamemask = sqld.Xml_BackupFileNameMask; - string sqlcs = sqld.SQLCS; + string sqlcs = sqld.SQLCS_Primary; bool createZip = sqld.Xml_CreateZip; var dbname = GetDBName(sqlcs); @@ -2458,12 +2448,12 @@ GO #region BackupSqlData public static void BackupSqlData(SQLDataBase sqld,DateTime? timestamp=null) { - if (sqld.Xml_IsRemoteDB) + if (sqld.Xml_PrimaryDB_IsUseTranzit) { ColorConsole.WriteLine(text: $" {nameof(BackupSqlData)}: data backup as scripts is not available for remote SQL Servers! DBname:'{sqld.DBName}'.", prefix: $"WARNING!", f:ConsoleColor.Yellow); return; } - string sqlcs = sqld.SQLCS; + string sqlcs = sqld.SQLCS_Primary; var dbname = GetDBName(sqlcs); string backupts = (timestamp.HasValue ? timestamp.Value : DateTime.Now).ToString("yyyyMMddHHmmss"); @@ -2613,8 +2603,8 @@ GO Xml_BackupFileNameMask = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.BackupFileNameMask), this.RootElement, SQLDataBase.XmlStructure.Attributes.BackupFileNameMask.Values.DEFAULT), Xml_RestoreFileNameMask = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.RestoreFileNameMask), this.RootElement, SQLDataBase.XmlStructure.Attributes.RestoreFileNameMask.Values.DEFAULT), Xml_BackupTargetDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.BackupTargetDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.BackupTargetDirectoryPath.Values.DEFAULT), - Xml_TranzitDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.TranzitDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.TranzitDirectoryPath.Values.DEFAULT), - Xml_PhysicalFilesDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath.Values.DEFAULT), + Xml_PrimaryDB_TranzitDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.TranzitDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.TranzitDirectoryPath.Values.DEFAULT), + Xml_PrimaryDB_PhysicalFilesDirectoryPath = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath), this.RootElement, SQLDataBase.XmlStructure.Attributes.PhysicalFilesDirectoryPath.Values.DEFAULT), Xml_ScriptCommandTimeout = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.ScriptCommandTimeout), this.RootElement, SQLDataBase.XmlStructure.Attributes.ScriptCommandTimeout.Values.DEFAULT), Xml_BackupTimeout = GetValue(nameof(SQLDataBase.XmlStructure.Attributes.BackupTimeout), this.RootElement, SQLDataBase.XmlStructure.Attributes.BackupTimeout.Values.DEFAULT), }; @@ -2642,59 +2632,73 @@ GO public string Xml_BackupFileNameMask; public string Xml_RestoreFileNameMask; public string Xml_BackupTargetDirectoryPath; - public bool Xml_IsRemoteDB { get { return !string.IsNullOrWhiteSpace(Xml_TranzitDirectoryPath); } } - public string Xml_TranzitDirectoryPath; - public string Xml_SQLConnectionString; - public string Xml_PhysicalFilesDirectoryPath; - public int Xml_ScriptCommandTimeout; - public int Xml_BackupTimeout; - public List Xml_SQLDataList; - public List Xml_SQLLastUpdatedTriggerList; - public List Xml_SQLDbUserList; - public List Xml_SQLServerLoginList; - public List Xml_SQLScriptList; - - public string DBName; - public string DataSource; - public SQLDBStatus Status; - public string PhysicalFilesDirectoryPath; - public string SizeString; - public bool isSQLCSselected + public int Xml_ScriptCommandTimeout; + public int Xml_BackupTimeout; + + public string Xml_PrimaryDB_SQLConnectionString; + public string Xml_PrimaryDB_TranzitDirectoryPath; + public bool Xml_PrimaryDB_IsUseTranzit { get { return !string.IsNullOrWhiteSpace(Xml_PrimaryDB_TranzitDirectoryPath); } } + public string Xml_PrimaryDB_PhysicalFilesDirectoryPath; + public bool is_PrimaryDB_SQLCSselected { get { - var sqlcsList = this.Xml_SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); - return sqlcsList.Count() == 1 || !string.IsNullOrWhiteSpace(this.Xml_SQLConnectionStringSelected); + var sqlcsList = this.Xml_PrimaryDB_SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); + return sqlcsList.Count() == 1 || !string.IsNullOrWhiteSpace(this.Xml_PrimaryDB_SQLConnectionStringSelected); } } - public string SQLCS + public string SQLCS_Primary { get { - if (string.IsNullOrWhiteSpace(this.Xml_SQLConnectionStringSelected)) { SelectSQLConnectionString(); } - if (string.IsNullOrWhiteSpace(this.Xml_SQLConnectionStringSelected)) { return null; } - return XmlProcessing.ConnectionStringStore.GetSQL(this.Xml_SQLConnectionStringSelected); + if (string.IsNullOrWhiteSpace(this.Xml_PrimaryDB_SQLConnectionStringSelected)) { Select_PrimaryDB_SQLConnectionString(); } + if (string.IsNullOrWhiteSpace(this.Xml_PrimaryDB_SQLConnectionStringSelected)) { return null; } + return XmlProcessing.ConnectionStringStore.GetSQL(this.Xml_PrimaryDB_SQLConnectionStringSelected); } } - private string Xml_SQLConnectionStringSelected; - - public void SelectSQLConnectionString(int? forceselection=null) + private string Xml_PrimaryDB_SQLConnectionStringSelected; + public void Select_PrimaryDB_SQLConnectionString(int? forceselection=null) { - this.Xml_SQLConnectionStringSelected = null; - var sqlcsList = this.Xml_SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); - if (forceselection.HasValue) + this.Xml_PrimaryDB_SQLConnectionStringSelected = null; + var sqlcsList = this.Xml_PrimaryDB_SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); + if (forceselection.HasValue) { - if (forceselection.Value >=0 && sqlcsList.Count() > forceselection.Value) { this.Xml_SQLConnectionStringSelected = sqlcsList[forceselection.Value]; } - return; + if (forceselection.Value >=0 && sqlcsList.Count() > forceselection.Value) { this.Xml_PrimaryDB_SQLConnectionStringSelected = sqlcsList[forceselection.Value]; } + return; } else { - if (sqlcsList.Count() == 1) { this.Xml_SQLConnectionStringSelected = sqlcsList[0]; return; } + if (sqlcsList.Count() == 1) { this.Xml_PrimaryDB_SQLConnectionStringSelected = sqlcsList[0]; return; } var selection = ColorConsole.ReadLine("Select SQL connection string to use:", bracket: "[]", suffix: "ENTER==first", validitylist: sqlcsList); if (selection == "EX") return; - if (string.IsNullOrWhiteSpace(selection)) { this.Xml_SQLConnectionStringSelected = sqlcsList[0]; } else { this.Xml_SQLConnectionStringSelected = selection; } + if (string.IsNullOrWhiteSpace(selection)) { this.Xml_PrimaryDB_SQLConnectionStringSelected = sqlcsList[0]; } else { this.Xml_PrimaryDB_SQLConnectionStringSelected = selection; } } } + + public string Xml_SecondaryDB_SQLConnectionString; + public string Xml_SecondaryDB_TranzitDirectoryPath; + public bool Xml_SecondaryDB_IsUseTranzit { get { return !string.IsNullOrWhiteSpace(Xml_SecondaryDB_TranzitDirectoryPath); } } + public string Xml_SecondaryDB_PhysicalFilesDirectoryPath; + public string SQLCS_Secondary + { + get + { + if (string.IsNullOrWhiteSpace(this.Xml_SecondaryDB_SQLConnectionString)) { return null; } + return XmlProcessing.ConnectionStringStore.GetSQL(this.Xml_SecondaryDB_SQLConnectionString); + } + } + + public List Xml_SQLDataList; + public List Xml_SQLLastUpdatedTriggerList; + public List Xml_SQLDbUserList; + public List Xml_SQLServerLoginList; + public List Xml_SQLScriptList; + + public string DBName; + public string DataSource; + public SQLDBStatus Status; + public string PrimaryDB_PhysicalFilesDirectoryPath; + public string SizeString; #endregion fields public enum SQLDBStatus { NoAccess, OK, } @@ -2703,42 +2707,42 @@ GO { try { - if (!this.isSQLCSselected) + if (!this.is_PrimaryDB_SQLCSselected) { this.Status = SQLDBStatus.OK; this.DBName = ""; - this.DataSource = this.Xml_SQLConnectionString; + this.DataSource = this.Xml_PrimaryDB_SQLConnectionString; } else { - string dbname = SQLDataBaseManagerCore.GetDBName(this.SQLCS); + string dbname = SQLDataBaseManagerCore.GetDBName(this.SQLCS_Primary); if (string.IsNullOrWhiteSpace(dbname)) { - var sqlc = ServerConnectionPool.GetSqlConnection(this.SQLCS, open: true); + var sqlc = ServerConnectionPool.GetSqlConnection(this.SQLCS_Primary, open: true); this.Status = SQLDBStatus.OK; this.DBName = ""; - this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS_Primary); } else { - GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath); - this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; - this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); - this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); + GetPhysicalFilesLocationAndSize(this.SQLCS_Primary, out this.SizeString, out this.PrimaryDB_PhysicalFilesDirectoryPath); + this.Status = this.PrimaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; + this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS_Primary); + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS_Primary); } } } catch { this.Status = SQLDBStatus.NoAccess; - this.PhysicalFilesDirectoryPath = ""; + this.PrimaryDB_PhysicalFilesDirectoryPath = ""; this.DBName = ""; this.DataSource = ""; this.SizeString = ""; try { - this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); - this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); + this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS_Primary); + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS_Primary); } catch { } } @@ -2816,11 +2820,16 @@ GO Xml_BackupFileNameMask = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupFileNameMask), sqldatabasexml, common.Xml_BackupFileNameMask); Xml_RestoreFileNameMask = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.RestoreFileNameMask), sqldatabasexml, common.Xml_RestoreFileNameMask); Xml_BackupTargetDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTargetDirectoryPath), sqldatabasexml, common.Xml_BackupTargetDirectoryPath); - Xml_TranzitDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.TranzitDirectoryPath), sqldatabasexml, common.Xml_TranzitDirectoryPath); - Xml_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.SQLConnectionString), sqldatabasexml, XmlStructure.SQLDataBase.Attributes.SQLConnectionString.Values.DEFAULT); + Xml_PrimaryDB_TranzitDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.TranzitDirectoryNetworkPath), sqldatabasexml, common.Xml_PrimaryDB_TranzitDirectoryPath); + Xml_PrimaryDB_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.SQLConnectionString), sqldatabasexml, XmlStructure.SQLDataBase.Attributes.SQLConnectionString.Values.DEFAULT); - Xml_CreateZip = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.CreateZip), sqldatabasexml, common.Xml_CreateZip); - Xml_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.PhysicalFilesDirectoryPath), sqldatabasexml, common.Xml_PhysicalFilesDirectoryPath); + var secdbxml = GetXElement(sqldatabasexml,nameof(XmlStructure.SQLDataBase.SecondaryDB)); + Xml_SecondaryDB_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.SQLConnectionString), secdbxml, ""); + Xml_SecondaryDB_TranzitDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.TranzitDirectoryNetworkPath), secdbxml, ""); + Xml_SecondaryDB_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.PhysicalFilesDirectoryPath), secdbxml, ""); + + Xml_CreateZip = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.CreateZip), sqldatabasexml, common.Xml_CreateZip); + Xml_PrimaryDB_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.PhysicalFilesDirectoryPath), sqldatabasexml, common.Xml_PrimaryDB_PhysicalFilesDirectoryPath); Xml_ScriptCommandTimeout = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.ScriptCommandTimeout), sqldatabasexml, common.Xml_ScriptCommandTimeout); Xml_BackupTimeout = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTimeout), sqldatabasexml, common.Xml_BackupTimeout); @@ -2848,7 +2857,7 @@ GO Xml_SQLScriptList = new List(); var sqlscriptsXml = GetXElement(sqldatabasexml, nameof(XmlStructure.SQLDataBase.Scripts)); var sqlscriptXmlList = GetAllXElements(sqlscriptsXml, nameof(XmlStructure.SQLDataBase.Scripts.Script)); - if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_SQLConnectionString,Xml_ScriptCommandTimeout, scriptindex++)); } } + if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_PrimaryDB_SQLConnectionString,Xml_ScriptCommandTimeout, scriptindex++)); } } } #endregion xml constructor #region cloner constructor @@ -2861,9 +2870,9 @@ GO Xml_BackupFileNameMask = sqld.Xml_BackupFileNameMask; Xml_RestoreFileNameMask = sqld.Xml_RestoreFileNameMask; Xml_BackupTargetDirectoryPath = sqld.Xml_BackupTargetDirectoryPath; - Xml_TranzitDirectoryPath = sqld.Xml_TranzitDirectoryPath; - Xml_SQLConnectionString = sqld.Xml_SQLConnectionString; - Xml_PhysicalFilesDirectoryPath = sqld.Xml_PhysicalFilesDirectoryPath; + Xml_PrimaryDB_TranzitDirectoryPath = sqld.Xml_PrimaryDB_TranzitDirectoryPath; + Xml_PrimaryDB_SQLConnectionString = sqld.Xml_PrimaryDB_SQLConnectionString; + Xml_PrimaryDB_PhysicalFilesDirectoryPath = sqld.Xml_PrimaryDB_PhysicalFilesDirectoryPath; Xml_SQLDataList = sqld.Xml_SQLDataList.Select(x => new SQLData(x)).ToList(); Xml_SQLScriptList = sqld.Xml_SQLScriptList.Select(x => new SQLScript(x)).ToList(); } @@ -2894,7 +2903,7 @@ GO public static class BackupFileNameMask { } public static class RestoreFileNameMask { } public static class BackupTargetDirectoryPath { } - public static class TranzitDirectoryPath { } + public static class TranzitDirectoryNetworkPath { } public static class CreateZip { } public static class PhysicalFilesDirectoryPath { } public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } @@ -2963,8 +2972,17 @@ GO } } } - } - } + public static class SecondaryDB + { + public static class Attributes + { + public static class TranzitDirectoryNetworkPath { public static class Values { public const string DEFAULT = ""; } } + public static class PhysicalFilesDirectoryPath { public static class Values { public const string DEFAULT = ""; } } + public static class SQLConnectionString { public static class Values { public const string DEFAULT = null; } } + } + } + } + } #endregion XmlStructure #region SQLScript class public class SQLScript : XmlLinqBase diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 1bad1e6..cce0e24 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.31.8.0")] -[assembly: AssemblyFileVersion("1.31.8.0")] +[assembly: AssemblyVersion("1.32.0.0")] +[assembly: AssemblyFileVersion("1.32.0.0")] -- libgit2 0.21.2