From 3aa4f475453dab2f87bd46e9be426c4f1d7a0837 Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Fri, 29 Nov 2024 12:09:30 +0100 Subject: [PATCH] v1.29.3 - backup timeout megadható --- Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs | 34 +++++++++++++++++++++++++--------- Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index d47ed7b..419d2e2 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -1474,8 +1474,11 @@ GO ColorConsole.WriteLine(backupfilename, ConsoleColor.Yellow, prefix: " backupfilename:"); ColorConsole.WriteLine(backupFullName, ConsoleColor.Yellow, prefix: " backupFullName:"); ColorConsole.WriteLine(createzip.ToString(), ConsoleColor.Yellow, prefix: " createzip:"); - ColorConsole.WriteLine(ZIPbackupfilename, ConsoleColor.Yellow, prefix: " ZIPbackupfilename:"); - ColorConsole.WriteLine(ZIPbackupFullName, ConsoleColor.Yellow, prefix: " ZIPbackupFullName:"); + if (createzip) + { + ColorConsole.WriteLine(ZIPbackupfilename, ConsoleColor.Yellow, prefix: " ZIPbackupfilename:"); + ColorConsole.WriteLine(ZIPbackupFullName, ConsoleColor.Yellow, prefix: " ZIPbackupFullName:"); + } ColorConsole.WriteLine(usetranzit.ToString(), ConsoleColor.Yellow, prefix: " usetranzit:"); ColorConsole.WriteLine(tranzitFullName, ConsoleColor.Yellow, prefix: " tranzitFullName:"); ColorConsole.WriteLine(returnfilename, ConsoleColor.Yellow, prefix: " returnfilename:"); @@ -1507,11 +1510,19 @@ GO try { sqlserver = SQLServerConnect(sqld.SQLCS, "master"); if (sqlserver == null) { return null; } - smoBackup.SqlBackupAsync(sqlserver); - var startbackup = DateTime.Now; - smoBackup.Wait(); + sqlserver.ConnectionContext.StatementTimeout = sqld.Xml_BackupTimeout; + backupstarttime = DateTime.Now; + smoBackup.SqlBackup(sqlserver); + //smoBackup.Wait(); Console.WriteLine($""); - Console.WriteLine($"Backup completed. Backup time: {(int)(DateTime.Now.Subtract(startbackup).TotalSeconds)}sec."); + Console.WriteLine($"Backup completed. Backup time: {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec."); + } + catch (Exception ex) + { + ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red); + var errmsg = ""; while (ex != null) { errmsg += ";" + ex.Message;ex = ex.InnerException; } + ColorConsole.WriteLine(errmsg, ConsoleColor.Red); + return null; } finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } if (usetranzit && File.Exists(tranzitFullName)) @@ -1539,14 +1550,14 @@ GO } return returnfilename; } - + private static DateTime backupstarttime; private static void SmoBackupRestore_PercentComplete(object sender, PercentCompleteEventArgs e) { ColorConsole.SetCursorPosition(0, Console.CursorTop); - ColorConsole.Write($"Completed: {e.Percent}%. {e.Message}"); + ColorConsole.Write($"Completed: {e.Percent}%. {e.Message}. Backup time : {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec."); } - public static List GetBackupFilePathList(SQLDataBase sqld) + public static List GetBackupFilePathList(SQLDataBase sqld) { var filenamemask = Path.GetFileNameWithoutExtension(sqld.Xml_BackupFileNameMask); var vars = new Dictionary(); @@ -2313,6 +2324,7 @@ GO 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_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), }; var sqldatabasexmllist = GetAllXElements(nameof(SQLDataBase.XmlStructure.SQLDataBase)); if (sqldatabasexmllist != null && sqldatabasexmllist.Any()) @@ -2343,6 +2355,7 @@ GO 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; @@ -2460,6 +2473,7 @@ GO Xml_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.PhysicalFilesDirectoryPath), sqldatabasexml, common.Xml_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); Xml_SQLDataList = new List(); var sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); @@ -2515,6 +2529,7 @@ GO public static class PhysicalFilesDirectoryPath { public static class Values { public const string DEFAULT = ""; } } public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } + public static class BackupTimeout { public static class Values { public const int DEFAULT = 10000; } } public static class CreateZip{ public static class Values { public const bool DEFAULT = true; } } } @@ -2532,6 +2547,7 @@ GO public static class CreateZip { } public static class PhysicalFilesDirectoryPath { } public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } + public static class BackupTimeout { public static class Values { public const int DEFAULT = 10000; } } } public static class SQLData { diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index beb8e64..3262511 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.29.2.0")] -[assembly: AssemblyFileVersion("1.29.2.0")] +[assembly: AssemblyVersion("1.29.3.0")] +[assembly: AssemblyFileVersion("1.29.3.0")] -- libgit2 0.21.2