Commit 31cca8095fdfee6fcccba81b77f75a74fc5b7d3e
1 parent
34b4dbe8
v1.31.8.0
- Move DB to remote server letisztázása
Showing
2 changed files
with
150 additions
and
136 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
| @@ -32,6 +32,7 @@ using System.Security.Cryptography; | @@ -32,6 +32,7 @@ using System.Security.Cryptography; | ||
| 32 | using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; | 32 | using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; |
| 33 | using System.Windows.Controls; | 33 | using System.Windows.Controls; |
| 34 | using Menu = Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu; | 34 | using Menu = Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu; |
| 35 | +using static Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu; | ||
| 35 | 36 | ||
| 36 | namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | 37 | namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
| 37 | { | 38 | { |
| @@ -69,25 +70,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -69,25 +70,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
| 69 | menufunctions.ExecuteMenu(functionkey); | 70 | menufunctions.ExecuteMenu(functionkey); |
| 70 | return o2; | 71 | return o2; |
| 71 | } | 72 | } |
| 72 | - public static void Execute(string key, bool enabledbbackup, bool enablescriptbackup, bool enabletabledatabackup, string targetfolder=null,DateTime? timestamp = null) | ||
| 73 | - { | ||
| 74 | - var packagets = (timestamp.HasValue ? timestamp.Value : DateTime.Now).ToString("yyyyMMddHHmmss"); | ||
| 75 | - var config = new SQLDataBaseManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); | ||
| 76 | - var origsqld = config.GetDefinitionList().FirstOrDefault(x => x.Xml_Key == key); | ||
| 77 | - if (origsqld != null) | ||
| 78 | - { | ||
| 79 | - var sqld = new SQLDataBase(origsqld); | ||
| 80 | - var dbname = SQLDataBaseManagerCore.GetDBName(sqld.SQLCS); | ||
| 81 | - ColorConsole.WriteLine($"Database backup process started. DB key:'{key}', name:'{dbname}'...", ConsoleColor.Yellow); | ||
| 82 | - if (!string.IsNullOrWhiteSpace(targetfolder)) { sqld.Xml_BackupTargetDirectoryPath = targetfolder; } | ||
| 83 | - if (enabledbbackup) { SQLDataBaseManagerCore.CreateBackup(sqld,null, timestamp); } | ||
| 84 | - if (enablescriptbackup) { SQLDataBaseManagerCore.BackupSqlScripts(sqld, timestamp); } | ||
| 85 | - if (enabletabledatabackup) { SQLDataBaseManagerCore.BackupSqlData(sqld, timestamp); } | ||
| 86 | - ColorConsole.WriteLine($"Database backup process finished!", ConsoleColor.DarkGreen); | ||
| 87 | - } | ||
| 88 | - else { ColorConsole.WriteLine($"Database backup process error. DB key incorrect:'{key}'...", ConsoleColor.Red); } | ||
| 89 | - } | ||
| 90 | - #endregion Execute | 73 | + #endregion Execute |
| 91 | 74 | ||
| 92 | #region First level Executors with UI | 75 | #region First level Executors with UI |
| 93 | private static object CreateDataScripts(object parameter, object o) | 76 | private static object CreateDataScripts(object parameter, object o) |
| @@ -180,12 +163,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -180,12 +163,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
| 180 | } | 163 | } |
| 181 | return o; | 164 | return o; |
| 182 | } | 165 | } |
| 183 | - private static bool NoDBNameSpecified(SQLDataBase ssqldb) | ||
| 184 | - { | ||
| 185 | - const string FUNNOTAVAILTXT = "Function is not available for server connection strings wit no DB name specified!"; | ||
| 186 | - if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); ssqldb.DBName = "master"; return true; } | ||
| 187 | - return false; | ||
| 188 | - } | ||
| 189 | private static object RestoreDataBase(object parameter, object o) | 166 | private static object RestoreDataBase(object parameter, object o) |
| 190 | { | 167 | { |
| 191 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | 168 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); |
| @@ -482,9 +459,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -482,9 +459,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
| 482 | 459 | ||
| 483 | #region CreateDBUser | 460 | #region CreateDBUser |
| 484 | private static string[] selectablerolelist = new string[] { "FULLACCESS", "DATAREADER", "db_accessadmin", "db_backupoperator", "db_datareader", "db_datawriter", "db_ddladmin", "db_denydatareader", "db_denydatawriter", "db_owner", "db_securityadmin", }; | 461 | private static string[] selectablerolelist = new string[] { "FULLACCESS", "DATAREADER", "db_accessadmin", "db_backupoperator", "db_datareader", "db_datawriter", "db_ddladmin", "db_denydatareader", "db_denydatawriter", "db_owner", "db_securityadmin", }; |
| 485 | - private static string[] fullaccessrolelist = new string[] { "db_accessadmin", "db_backupoperator", "db_datareader", "db_datawriter", "db_ddladmin", "db_owner", "db_securityadmin", }; | 462 | + private static string[] fullaccessdbloginrolelist = new string[] { "db_accessadmin", "db_backupoperator", "db_datareader", "db_datawriter", "db_ddladmin", "db_owner", "db_securityadmin", }; |
| 486 | private static string[] datareaderrolelist = new string[] { "db_datareader", }; | 463 | private static string[] datareaderrolelist = new string[] { "db_datareader", }; |
| 487 | - private static string[] loginrolelist = new string[] { "dbcreator", "securityadmin", }; | 464 | + private static string[] serverloginrolelist = new string[] { "dbcreator", "securityadmin", }; |
| 488 | private const string COMMA = ","; | 465 | private const string COMMA = ","; |
| 489 | private static object CreateDBUser(object parameter, object o) | 466 | private static object CreateDBUser(object parameter, object o) |
| 490 | { | 467 | { |
| @@ -602,7 +579,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -602,7 +579,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
| 602 | if (selectedrolelistnum > 1 && specialselectionactive) { ColorConsole.WriteLine($"ERROR! FULLACCESS or DATAREADER has to be selected alone!", ConsoleColor.Red); return null; } | 579 | if (selectedrolelistnum > 1 && specialselectionactive) { ColorConsole.WriteLine($"ERROR! FULLACCESS or DATAREADER has to be selected alone!", ConsoleColor.Red); return null; } |
| 603 | if (badrolenames.Count > 0) { ColorConsole.WriteLine($"ERROR! {string.Join(COMMA, badrolenames)} are not available!", ConsoleColor.Red); return null; } | 580 | if (badrolenames.Count > 0) { ColorConsole.WriteLine($"ERROR! {string.Join(COMMA, badrolenames)} are not available!", ConsoleColor.Red); return null; } |
| 604 | var effectiverolelist = | 581 | var effectiverolelist = |
| 605 | - enablefullaccess ? fullaccessrolelist | 582 | + enablefullaccess ? fullaccessdbloginrolelist |
| 606 | : enabledatareader ? datareaderrolelist | 583 | : enabledatareader ? datareaderrolelist |
| 607 | : selectedrolelist; | 584 | : selectedrolelist; |
| 608 | return string.Join(",", effectiverolelist); | 585 | return string.Join(",", effectiverolelist); |
| @@ -649,116 +626,128 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | @@ -649,116 +626,128 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS | ||
| 649 | 626 | ||
| 650 | var selectedsqldbindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.SQLDataBaseManager.Function.CMD_DATABASES); | 627 | var selectedsqldbindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.SQLDataBaseManager.Function.CMD_DATABASES); |
| 651 | 628 | ||
| 652 | - (bool Exit, bool Yes) yesornoanswer; | ||
| 653 | - (bool Exit, bool Yes, SQLDataBase Dbfrom, SQLDataBase Dbto, string Selecteddbname, bool Emulation) movedbanswer; | ||
| 654 | - while (true) | ||
| 655 | - { | 629 | + while (true) |
| 630 | + { | ||
| 656 | var DateTimeNow = DateTime.Now; | 631 | var DateTimeNow = DateTime.Now; |
| 632 | + SQLDataBase dbfrom = null; | ||
| 633 | + SQLDataBase dbto = null; | ||
| 657 | 634 | ||
| 658 | - movedbanswer = YesOrNo_MoveDbToRemoteServer(config, selectedsqldbindexes); | ||
| 659 | - if (NoDBNameSpecified(movedbanswer.Dbfrom)) { continue; } | ||
| 660 | - if (NoDBNameSpecified(movedbanswer.Dbto)) { continue; } | ||
| 661 | - if (movedbanswer.Exit) break; | ||
| 662 | - if (movedbanswer.Yes) | 635 | + movedatabaseloop: |
| 636 | + (Menu.SelectionResult selectionresult, bool yes) yesornoanswer = YesOrNo(new List<string>() { $"Do You want to move ANY database from local server to remote server?" }); | ||
| 637 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; | ||
| 638 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) | ||
| 663 | { | 639 | { |
| 664 | - var movesuccess = SQLDataBaseManagerCore.MoveDbToRemoteServer(movedbanswer.Dbfrom, movedbanswer.Dbto, movedbanswer.Selecteddbname, movedbanswer.Emulation); | ||
| 665 | - if (!movesuccess) continue; | ||
| 666 | - } | ||
| 667 | - | ||
| 668 | - var usernamelist = new string[] { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; | 640 | + var dbselection = SelectToDbAndFromDb(config, selectedsqldbindexes, $"Select the SQL database(s) to move the first to the second.!"); |
| 641 | + if (dbselection.selection == Menu.SelectionResult.Exit) { return o; } | ||
| 642 | + if (dbselection.selection != Menu.SelectionResult.Ok) { goto movedatabaseloop; } | ||
| 643 | + dbfrom = dbselection.dbfrom; | ||
| 644 | + dbto = dbselection.dbto; | ||
| 645 | + if (NoDBNameSpecified(dbfrom) || NoDBNameSpecified(dbto)) { continue; } | ||
| 646 | + | ||
| 647 | + var todbname = ColorConsole.ReadLine($"Enter the name of the target DB. EMPTY={dbto.DBName}, EX=exit."); | ||
| 648 | + if (todbname.ToUpper() == "EX") { return o; } | ||
| 649 | + else if (string.IsNullOrWhiteSpace(todbname)) todbname = dbto.DBName; | ||
| 650 | + | ||
| 651 | + confirmloop:; | ||
| 652 | + var confirmtext = ColorConsole.ReadLine("Enter CONFIRM to start, EX to exit, SKIP to skip."); | ||
| 653 | + if (confirmtext.ToUpper() == "EX") { return o; } | ||
| 654 | + else if (confirmtext.ToUpper() == "CONFIRM") | ||
| 655 | + { | ||
| 656 | + var movesuccess = SQLDataBaseManagerCore.MoveDbToRemoteServer(dbfrom, dbto, todbname, false); | ||
| 657 | + if (!movesuccess) continue; | ||
| 658 | + } | ||
| 659 | + else if (confirmtext.ToUpper() != "SKIP") { goto confirmloop; }; | ||
| 660 | + } | ||
| 669 | 661 | ||
| 670 | - yesornoanswer = YesOrNo_ServerLogin(movedbanswer.Dbfrom.SQLCS, usernamelist); | ||
| 671 | - if (yesornoanswer.Exit) return o; | ||
| 672 | - if (yesornoanswer.Yes) SQLDataBaseManagerCore.CreateServerLogins(movedbanswer.Emulation, movedbanswer.Dbfrom.SQLCS, usernamelist, loginrolelist,fullaccessrolelist); | 662 | + serverloginloop: |
| 663 | + yesornoanswer = YesOrNo(new List<string>() { $"Do You want to create server and DB logins for local and/or remote server/database?", }); | ||
| 664 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; | ||
| 665 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) | ||
| 666 | + { | ||
| 667 | + if (dbfrom == null || dbto == null) | ||
| 668 | + { | ||
| 669 | + var dbselection = SelectToDbAndFromDb(config, selectedsqldbindexes, $"Select the SQL database(s) to add server and DB logins!"); | ||
| 670 | + if (dbselection.selection == Menu.SelectionResult.Exit) { return o; } | ||
| 671 | + if (dbselection.selection != Menu.SelectionResult.Ok) { goto serverloginloop; } | ||
| 672 | + dbfrom = dbselection.dbfrom; | ||
| 673 | + dbto = dbselection.dbto; | ||
| 674 | + } | ||
| 675 | + var usernamelist = new string[] { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; | ||
| 676 | + | ||
| 677 | + string l1 = $"Do You want to create the following mandatory server and DB logins for SOURCE server and DB?"; | ||
| 678 | + string l2 = $" SQL connection string: {dbfrom.SQLCS}"; | ||
| 679 | + string l3 = $" Username list: " + string.Join(",", usernamelist); | ||
| 680 | + yesornoanswer = YesOrNo(new List<string>() { l1, l2, l3, }); | ||
| 681 | + if (yesornoanswer.selectionresult== Menu.SelectionResult.Exit) return o; | ||
| 682 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) | ||
| 683 | + { | ||
| 684 | + SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbfrom.SQLCS, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); | ||
| 685 | + } | ||
| 673 | 686 | ||
| 674 | - yesornoanswer = YesOrNo_ServerLogin(movedbanswer.Dbto.SQLCS, usernamelist); | ||
| 675 | - if (yesornoanswer.Exit) return o; | ||
| 676 | - if (yesornoanswer.Yes) SQLDataBaseManagerCore.CreateServerLogins(movedbanswer.Emulation, movedbanswer.Dbto.SQLCS, usernamelist, loginrolelist, fullaccessrolelist); | 687 | + string l13 = $"Do You want to create the following mandatory server and DB logins for TARGET server and DB?"; |
| 688 | + string l23 = $" SQL connection string: {dbto.SQLCS}"; | ||
| 689 | + string l33 = $" Username list: " + string.Join(",", usernamelist); | ||
| 690 | + yesornoanswer = YesOrNo(new List<string>() { l13,l23,l33,}); | ||
| 691 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; | ||
| 692 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) | ||
| 693 | + { | ||
| 694 | + SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbto.SQLCS, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); | ||
| 695 | + } | ||
| 696 | + } | ||
| 677 | 697 | ||
| 678 | - yesornoanswer = YesOrNo_SetDbOffline(movedbanswer.Dbfrom.SQLCS, null); | ||
| 679 | - if (yesornoanswer.Exit) return o; | ||
| 680 | - if (yesornoanswer.Yes) SQLDataBaseManagerCore.SetDatabaseOffline(movedbanswer.Dbfrom.SQLCS); | 698 | + yesornoanswer = YesOrNo(new List<string>() { $"Do You want to set database '{SQLDataBaseManagerCore.GetDBName(dbfrom.SQLCS)}' OFFLINE on server '{SQLDataBaseManagerCore.GetDataSource(dbfrom.SQLCS)}'?", }); |
| 699 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; | ||
| 700 | + if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) | ||
| 701 | + { | ||
| 702 | + SQLDataBaseManagerCore.SetDatabaseOffline(dbfrom.SQLCS); | ||
| 703 | + } | ||
| 681 | 704 | ||
| 682 | - ColorConsole.WriteLine($"Moving DB to remote server completed. Required time: {(int)(DateTime.Now.Subtract(DateTimeNow).TotalSeconds)} seconds.", ConsoleColor.Green); | 705 | + ColorConsole.WriteLine($"Process completed. Required time: {(int)(DateTime.Now.Subtract(DateTimeNow).TotalSeconds)} seconds.", ConsoleColor.Green); |
| 683 | } | 706 | } |
| 684 | - return o; | ||
| 685 | } | 707 | } |
| 686 | - private static (bool,bool,SQLDataBase, SQLDataBase, string, bool) YesOrNo_MoveDbToRemoteServer(SQLDataBaseManagerXmlProcessor config,string selectedsqldbindexes) | 708 | + private static (Menu.SelectionResult selection,SQLDataBase dbfrom,SQLDataBase dbto) SelectToDbAndFromDb(SQLDataBaseManagerXmlProcessor config, string selectedsqldbindexes, string databaseselectionheadertext) |
| 709 | + { | ||
| 710 | + var menufolders = DisplaySQLDataBaseMenu(config, $"{databaseselectionheadertext} Format:FROMLOCALDB,TOREMOTEDB", silent: true, selectionmode: Menu.SelectionMode.Multi); | ||
| 711 | + Menu.Selection sr = menufolders.Select(selectedsqldbindexes); | ||
| 712 | + if (sr.Result == Menu.SelectionResult.Exit) { return (Menu.SelectionResult.Exit, null,null); } | ||
| 713 | + else if (sr.Result == Menu.SelectionResult.None) { return (Menu.SelectionResult.None, null,null); } | ||
| 714 | + else if (sr.Result == Menu.SelectionResult.Error) { return (Menu.SelectionResult.Error, null, null); } | ||
| 715 | + else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.FirstOrDefault() == null) { return (Menu.SelectionResult.Error, null, null); } | ||
| 716 | + else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.Count() != 2) | ||
| 717 | + { | ||
| 718 | + ColorConsole.WriteLine($"Select exactly 2 DB. Format:FROMLOCALDB,TOREMOTEDB", ConsoleColor.Red); | ||
| 719 | + return (Menu.SelectionResult.Error, null, null); | ||
| 720 | + } | ||
| 721 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | ||
| 722 | + else { } | ||
| 723 | + var spfrom = sr.SelectedParameterList.First(); | ||
| 724 | + var spto = sr.SelectedParameterList.ElementAt(1); | ||
| 725 | + SQLDataBase dbfrom = spfrom.Parameters as SQLDataBase; | ||
| 726 | + SQLDataBase dbto = spto.Parameters as SQLDataBase; | ||
| 727 | + if (!dbto.Xml_IsRemoteDB) | ||
| 728 | + { | ||
| 729 | + ColorConsole.WriteLine($"TOREMOTEDB '{dbto.SQLCS}' has to be remote!", ConsoleColor.Red); | ||
| 730 | + return (Menu.SelectionResult.Error, null, null); | ||
| 731 | + } | ||
| 732 | + if (dbfrom.Xml_IsRemoteDB) | ||
| 733 | + { | ||
| 734 | + ColorConsole.WriteLine($"FROMLOCALDB '{dbfrom.SQLCS}' has to be local!", ConsoleColor.Red); | ||
| 735 | + return (Menu.SelectionResult.Error, null, null); | ||
| 736 | + } | ||
| 737 | + return (Menu.SelectionResult.Ok, dbfrom,dbto); | ||
| 738 | + } | ||
| 739 | + private static (Menu.SelectionResult selectionresult, bool yes) YesOrNo(List<string> questiontextLines) | ||
| 687 | { | 740 | { |
| 688 | - (bool, bool, SQLDataBase, SQLDataBase, string, bool) returnvalueexit = (true, false, null, null, null, false); | ||
| 689 | - | ||
| 690 | - selectionloop: | ||
| 691 | - | ||
| 692 | - ColorConsole.WriteLine($"Do You want to move ANY database from local server to remote server?", ConsoleColor.Yellow); | ||
| 693 | - var yesorno = ColorConsole.ReadLine("Move?", ConsoleColor.Yellow, validitylist: new List<string> { "yes", "no" }, defaultvalue: "yes"); | ||
| 694 | - if (yesorno.ToUpper() == "EX") return returnvalueexit; | ||
| 695 | - | ||
| 696 | - var menufolders = DisplaySQLDataBaseMenu(config, $"Select the SQL database(s) to manage with function. '{nameof(MoveDbToRemoteServer)}'! Format:FROMLOCALDB,TOREMOTEDB", silent: true, selectionmode: Menu.SelectionMode.Multi); | ||
| 697 | - | ||
| 698 | - Menu.Selection sr = menufolders.Select(selectedsqldbindexes); | ||
| 699 | - if (sr.Result == Menu.SelectionResult.Exit) { return returnvalueexit; } | ||
| 700 | - else if (sr.Result == Menu.SelectionResult.None) { goto selectionloop; } | ||
| 701 | - else if (sr.Result == Menu.SelectionResult.Error) { goto selectionloop; } | ||
| 702 | - else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.FirstOrDefault() == null) { goto selectionloop; } | ||
| 703 | - else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.Count() != 2) | ||
| 704 | - { | ||
| 705 | - ColorConsole.WriteLine($"Select exactly 2 DB. Format:FROMLOCALDB,TOREMOTEDB", ConsoleColor.Red); | ||
| 706 | - goto selectionloop; | ||
| 707 | - } | ||
| 708 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | ||
| 709 | - else { } | ||
| 710 | - var spfrom = sr.SelectedParameterList.First(); | ||
| 711 | - var spto = sr.SelectedParameterList.ElementAt(1); | ||
| 712 | - SQLDataBase dbfrom = spfrom.Parameters as SQLDataBase; | ||
| 713 | - SQLDataBase dbto = spto.Parameters as SQLDataBase; | ||
| 714 | - if (!dbto.Xml_IsRemoteDB) | ||
| 715 | - { | ||
| 716 | - ColorConsole.WriteLine($"TOREMOTEDB '{dbto.SQLCS}' has to be remote!", ConsoleColor.Red); | ||
| 717 | - goto selectionloop; | ||
| 718 | - } | ||
| 719 | - if (dbfrom.Xml_IsRemoteDB) | ||
| 720 | - { | ||
| 721 | - ColorConsole.WriteLine($"FROMLOCALDB '{dbfrom.SQLCS}' has to be local!", ConsoleColor.Red); | ||
| 722 | - goto selectionloop; | ||
| 723 | - } | ||
| 724 | - if (yesorno.ToUpper() != "YES") return (false, false,dbfrom,dbto, null,false); | ||
| 725 | - | ||
| 726 | - bool emulation = false; | ||
| 727 | - var selecteddbname = ColorConsole.ReadLine($"Enter the name of the restored DB. EMPTY={dbto.DBName}, EX=exit."); | ||
| 728 | - if (selecteddbname.ToUpper() == "EX") return returnvalueexit; | ||
| 729 | - else if (string.IsNullOrWhiteSpace(selecteddbname)) selecteddbname = dbto.DBName; | 741 | + if (questiontextLines!=null) foreach(string l in questiontextLines) { ColorConsole.WriteLine(l, ConsoleColor.Yellow); } |
| 742 | + var yesorno = ColorConsole.ReadLine("Do action?", ConsoleColor.Yellow, validitylist: new List<string> { "yes", "no" }, defaultvalue: "yes"); | ||
| 743 | + if (yesorno.ToUpper() == "EX") return (Menu.SelectionResult.Exit, false); | ||
| 744 | + else if (yesorno.ToUpper() == "yes") return (Menu.SelectionResult.Ok, true); | ||
| 745 | + else return (Menu.SelectionResult.Ok, false); | ||
| 746 | + } | ||
| 747 | + #endregion MoveDbToRemoteServer | ||
| 730 | 748 | ||
| 731 | - confirmloop:; | ||
| 732 | - var selection = ColorConsole.ReadLine("Enter CONFIRM to start, EMU to emulate, EX to exit."); | ||
| 733 | - if (selection.ToUpper() == "EX") return returnvalueexit; | ||
| 734 | - else if (selection.ToUpper() == "EMU") emulation = true; | ||
| 735 | - else if (selection.ToUpper() == "CONFIRM") { } | ||
| 736 | - else goto confirmloop; | ||
| 737 | - return (false,true,dbfrom,dbto, selecteddbname,emulation); | ||
| 738 | - } | ||
| 739 | - private static (bool,bool) YesOrNo_SetDbOffline(string sqlcs, string dbname) | ||
| 740 | - { | ||
| 741 | - dbname = dbname ?? SQLDataBaseManagerCore.GetDBName(sqlcs); | ||
| 742 | - var servername = SQLDataBaseManagerCore.GetDataSource(sqlcs); | ||
| 743 | - ColorConsole.WriteLine($"Do You want to set database '{dbname}' OFFLINE on server '{servername}'?", ConsoleColor.Yellow); | ||
| 744 | - ColorConsole.WriteLine($" SQL connection string: {sqlcs}", ConsoleColor.Yellow); | ||
| 745 | - ColorConsole.WriteLine($" Server/database: {servername}/{dbname}", ConsoleColor.Yellow); | ||
| 746 | - var yesorno = ColorConsole.ReadLine("Set offline?", ConsoleColor.Yellow, validitylist: new List<string> { "yes", "no" }, defaultvalue: "yes"); | ||
| 747 | - return (yesorno.ToUpper() == "EX", yesorno.ToUpper() == "YES"); | ||
| 748 | - } | ||
| 749 | - private static (bool,bool) YesOrNo_ServerLogin(string sqlcs,string[] usernamelist) | ||
| 750 | - { | ||
| 751 | - ColorConsole.WriteLine($"Do You want to create the following mandatory server logins?", ConsoleColor.Yellow); | ||
| 752 | - ColorConsole.WriteLine($" SQL connection string: {sqlcs}", ConsoleColor.Yellow); | ||
| 753 | - ColorConsole.WriteLine($" Server: {SQLDataBaseManagerCore.GetDataSource(sqlcs)}", ConsoleColor.Yellow); | ||
| 754 | - ColorConsole.WriteLine($" Username list: " + string.Join(",", usernamelist), ConsoleColor.Yellow); | ||
| 755 | - var yesorno = ColorConsole.ReadLine("Create login?", ConsoleColor.Yellow, validitylist: new List<string> { "yes", "no" }, defaultvalue: "yes"); | ||
| 756 | - return (yesorno.ToUpper() == "EX", yesorno.ToUpper() == "YES"); | ||
| 757 | - } | ||
| 758 | - #endregion MoveDbToRemoteServer | ||
| 759 | - | ||
| 760 | - #region ManageLastUpdatedTrigger | ||
| 761 | - private static object ManageLastUpdatedTrigger(object parameter, object o) { return _ManageLastUpdatedTrigger(parameter, o, null); } | 749 | + #region ManageLastUpdatedTrigger |
| 750 | + private static object ManageLastUpdatedTrigger(object parameter, object o) { return _ManageLastUpdatedTrigger(parameter, o, null); } | ||
| 762 | #region script texts for _RemoveAndCreateLastUpdatedTrigger | 751 | #region script texts for _RemoveAndCreateLastUpdatedTrigger |
| 763 | const string Header_Script = | 752 | const string Header_Script = |
| 764 | @"USE [{DBNAME}] | 753 | @"USE [{DBNAME}] |
| @@ -977,6 +966,7 @@ GO | @@ -977,6 +966,7 @@ GO | ||
| 977 | } | 966 | } |
| 978 | #endregion ManageLastUpdatedTrigger | 967 | #endregion ManageLastUpdatedTrigger |
| 979 | 968 | ||
| 969 | + #region ExecuteScript | ||
| 980 | private static object ExecuteScript(object parameter, object o) | 970 | private static object ExecuteScript(object parameter, object o) |
| 981 | { | 971 | { |
| 982 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | 972 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); |
| @@ -1079,7 +1069,7 @@ GO | @@ -1079,7 +1069,7 @@ GO | ||
| 1079 | } | 1069 | } |
| 1080 | return returnkey != null; | 1070 | return returnkey != null; |
| 1081 | } | 1071 | } |
| 1082 | - | 1072 | + #endregion ExecuteScript |
| 1083 | private static object DropDB(object parameter, object o) | 1073 | private static object DropDB(object parameter, object o) |
| 1084 | { | 1074 | { |
| 1085 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | 1075 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); |
| @@ -1255,6 +1245,30 @@ GO | @@ -1255,6 +1245,30 @@ GO | ||
| 1255 | #endregion First level Executors with UI | 1245 | #endregion First level Executors with UI |
| 1256 | 1246 | ||
| 1257 | #region private methods | 1247 | #region private methods |
| 1248 | + private static bool NoDBNameSpecified(SQLDataBase ssqldb) | ||
| 1249 | + { | ||
| 1250 | + const string FUNNOTAVAILTXT = "Function is not available for server connection strings wit no DB name specified!"; | ||
| 1251 | + if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); ssqldb.DBName = "master"; return true; } | ||
| 1252 | + return false; | ||
| 1253 | + } | ||
| 1254 | + public static void Execute(string key, bool enabledbbackup, bool enablescriptbackup, bool enabletabledatabackup, string targetfolder=null,DateTime? timestamp = null) | ||
| 1255 | + { | ||
| 1256 | + var packagets = (timestamp.HasValue ? timestamp.Value : DateTime.Now).ToString("yyyyMMddHHmmss"); | ||
| 1257 | + var config = new SQLDataBaseManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); | ||
| 1258 | + var origsqld = config.GetDefinitionList().FirstOrDefault(x => x.Xml_Key == key); | ||
| 1259 | + if (origsqld != null) | ||
| 1260 | + { | ||
| 1261 | + var sqld = new SQLDataBase(origsqld); | ||
| 1262 | + var dbname = SQLDataBaseManagerCore.GetDBName(sqld.SQLCS); | ||
| 1263 | + ColorConsole.WriteLine($"Database backup process started. DB key:'{key}', name:'{dbname}'...", ConsoleColor.Yellow); | ||
| 1264 | + if (!string.IsNullOrWhiteSpace(targetfolder)) { sqld.Xml_BackupTargetDirectoryPath = targetfolder; } | ||
| 1265 | + if (enabledbbackup) { SQLDataBaseManagerCore.CreateBackup(sqld,null, timestamp); } | ||
| 1266 | + if (enablescriptbackup) { SQLDataBaseManagerCore.BackupSqlScripts(sqld, timestamp); } | ||
| 1267 | + if (enabletabledatabackup) { SQLDataBaseManagerCore.BackupSqlData(sqld, timestamp); } | ||
| 1268 | + ColorConsole.WriteLine($"Database backup process finished!", ConsoleColor.DarkGreen); | ||
| 1269 | + } | ||
| 1270 | + else { ColorConsole.WriteLine($"Database backup process error. DB key incorrect:'{key}'...", ConsoleColor.Red); } | ||
| 1271 | + } | ||
| 1258 | #region private DisplaySQLDataBaseMenu | 1272 | #region private DisplaySQLDataBaseMenu |
| 1259 | private static void DataBaseListDisplayer() { DisplaySQLDataBaseMenu(); } | 1273 | private static void DataBaseListDisplayer() { DisplaySQLDataBaseMenu(); } |
| 1260 | private static Menu DisplaySQLDataBaseMenu(SQLDataBaseManagerXmlProcessor config = null, string prompt = null, bool silent = false, Menu.SelectionMode selectionmode = Menu.SelectionMode.Multi) | 1274 | private static Menu DisplaySQLDataBaseMenu(SQLDataBaseManagerXmlProcessor config = null, string prompt = null, bool silent = false, Menu.SelectionMode selectionmode = Menu.SelectionMode.Multi) |
| @@ -1778,14 +1792,14 @@ GO | @@ -1778,14 +1792,14 @@ GO | ||
| 1778 | } | 1792 | } |
| 1779 | finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } | 1793 | finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } |
| 1780 | } | 1794 | } |
| 1781 | - public static void CreateServerLogins(bool emulation, string sqlcs, string[] usernamelist,string[] loginrolelist, string[] fullaccessrolelist) | 1795 | + public static void CreateServerAndDBLogins(bool emulation, string sqlcs, string[] usernamelist,string[] serverloginrolelist, string[] dbloginrolelist) |
| 1782 | { | 1796 | { |
| 1783 | foreach (var username in usernamelist) | 1797 | foreach (var username in usernamelist) |
| 1784 | { | 1798 | { |
| 1785 | - ColorConsole.WriteLine(username, ConsoleColor.Yellow, prefix: nameof(SQLDataBaseManagerCore.CreateUser) + ":"); | ||
| 1786 | - try { if (!emulation) SQLDataBaseManagerCore.CreateLogin(sqlcs, username, null, "master", LoginType.WindowsUser, loginrolelist); } | 1799 | + ColorConsole.WriteLine(username, ConsoleColor.Yellow, prefix: nameof(SQLDataBaseManagerCore.CreateServerAndDBLogins) + ":"); |
| 1800 | + try { if (!emulation) SQLDataBaseManagerCore.CreateLogin(sqlcs, username, null, "master", LoginType.WindowsUser, serverloginrolelist); } | ||
| 1787 | catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateLogin) + ">>>: " + ex.MessageNested(), ConsoleColor.Red); } | 1801 | catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateLogin) + ">>>: " + ex.MessageNested(), ConsoleColor.Red); } |
| 1788 | - try { if (!emulation) SQLDataBaseManagerCore.CreateUser(sqlcs, username, string.Join(",", fullaccessrolelist), "w"); } | 1802 | + try { if (!emulation) SQLDataBaseManagerCore.CreateUser(sqlcs, username, string.Join(",", dbloginrolelist), "w"); } |
| 1789 | catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateUser) + "\n" + ex.MessageNested(), ConsoleColor.Red); } | 1803 | catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateUser) + "\n" + ex.MessageNested(), ConsoleColor.Red); } |
| 1790 | } | 1804 | } |
| 1791 | } | 1805 | } |
| @@ -2060,7 +2074,7 @@ GO | @@ -2060,7 +2074,7 @@ GO | ||
| 2060 | sqltxt = Tools.KvpString.Substitute($"{RUNNINGMODE}={RUNNINGMODE_ONERUN};{RUNNINGMODE_ONERUN_PARAMETER_DELETEBEFOREDATE}={limitdatefornextrun:s};", sqltxtalmostresolved); | 2074 | sqltxt = Tools.KvpString.Substitute($"{RUNNINGMODE}={RUNNINGMODE_ONERUN};{RUNNINGMODE_ONERUN_PARAMETER_DELETEBEFOREDATE}={limitdatefornextrun:s};", sqltxtalmostresolved); |
| 2061 | if (sqltxt == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... | 2075 | if (sqltxt == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... |
| 2062 | ret1 = ExecuteSQLScript(sqlc, sqltxt, sqlscript.CommandTimeout, null); | 2076 | ret1 = ExecuteSQLScript(sqlc, sqltxt, sqlscript.CommandTimeout, null); |
| 2063 | - Add(loople, $"LIMITDATE", limitdatefornextrun.ToString()); | 2077 | + Add(loople, $"LIMITDATE", limitdatefornextrun.ToString("yyyy-MM-ddTHH:mm:ss.fff")); |
| 2064 | Add(loople, $"RETCODE", ret1.ReturnValue.ToString()); | 2078 | Add(loople, $"RETCODE", ret1.ReturnValue.ToString()); |
| 2065 | Add(loople, $"RETMSG", ret1.ReturnMessage); | 2079 | Add(loople, $"RETMSG", ret1.ReturnMessage); |
| 2066 | Add(loople, $"PROCESSINGTIME", DateTime.Now.Subtract(loopstart).ToString()); | 2080 | Add(loople, $"PROCESSINGTIME", DateTime.Now.Subtract(loopstart).ToString()); |
| @@ -2098,7 +2112,7 @@ GO | @@ -2098,7 +2112,7 @@ GO | ||
| 2098 | 2112 | ||
| 2099 | Add(multirunresult, $"NUMOFRUNS", deleteruncounter.ToString()); | 2113 | Add(multirunresult, $"NUMOFRUNS", deleteruncounter.ToString()); |
| 2100 | Add(multirunresult, $"DBRECORDS", $"{numoftotaldbrecords_before}-->{numoftotaldbrecords_after} (total:{numoftotaldbrecords_after-numoftotaldbrecords_before})"); | 2114 | Add(multirunresult, $"DBRECORDS", $"{numoftotaldbrecords_before}-->{numoftotaldbrecords_after} (total:{numoftotaldbrecords_after-numoftotaldbrecords_before})"); |
| 2101 | - Add(multirunresult, $"MINDATE", $"{mindateTS_before}-->{mindateTS_after}"); | 2115 | + Add(multirunresult, $"MINDATE", $"{mindateTS_before.ToString("yyyy-MM-ddTHH:mm:ss.fff")}-->{mindateTS_after.ToString("yyyy-MM-ddTHH:mm:ss.fff")}"); |
| 2102 | Add(multirunresult, $"PROCESSINGTIME", $"{DateTime.Now.Subtract(starttime)}"); | 2116 | Add(multirunresult, $"PROCESSINGTIME", $"{DateTime.Now.Subtract(starttime)}"); |
| 2103 | return Finalize(0, multirunresult); | 2117 | return Finalize(0, multirunresult); |
| 2104 | } | 2118 | } |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | ||
| 32 | // You can specify all the values or you can default the Build and Revision Numbers | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | // by using the '*' as shown below: | 33 | // by using the '*' as shown below: |
| 34 | // [assembly: AssemblyVersion("1.0.*")] | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.31.7.0")] | ||
| 36 | -[assembly: AssemblyFileVersion("1.31.7.0")] | 35 | +[assembly: AssemblyVersion("1.31.8.0")] |
| 36 | +[assembly: AssemblyFileVersion("1.31.8.0")] |