test backup & restore

This commit is contained in:
Samuele Locatelli
2023-07-27 07:53:00 +02:00
parent 2ae08165f4
commit b279a287ec
8 changed files with 151 additions and 55 deletions
+28 -6
View File
@@ -1,5 +1,5 @@
using System.Diagnostics;
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
@@ -72,12 +72,14 @@ namespace EgtBEAMWALL.DataLayer
// esecuzione script di install locale
return Controllers.DbController.man.refreshViews(DATABASE_NAME);
}
/// <summary>
/// Effettua DUMP del DB dato utente admin + percorso salvataggio
/// </summary>
/// <param name="mysqlDumpPath">Percorso eseguibile mysqldump</param>
/// <param name="outFilePath">Percorso di salvataggio del dump (*.sql)</param>
/// <returns></returns>
public static bool DumpDB(string mysqlDumpPath, string outFilePath)
public static bool DataBaseDumpToFile(string mysqlDumpPath, string outFilePath)
{
bool fatto = false;
// aggiungo sql finale
@@ -97,10 +99,31 @@ namespace EgtBEAMWALL.DataLayer
File.Delete(outFilePath);
}
// chiamo script esterno...
string callScript = $"\"{mysqlDumpPath}\" -u{DATABASE_USER} -p{DATABASE_PWD} {DATABASE_NAME} > {outFilePath}";
string callScript = $"\"{mysqlDumpPath}\" -u{DATABASE_USER} -p{DATABASE_PWD} {DATABASE_NAME} --skip-extended-insert > {outFilePath}";
ExecuteCommand(callScript);
return fatto;
}
/// <summary>
/// Effettua restore come overwrite del DB di DEFAULT... irreversibile
/// </summary>
/// <param name="mysqlPath">Percorso eseguibile mysql</param>
/// <param name="inFilePath">Percorso di lettura del dump (*.sql)</param>
/// <returns></returns>
public static bool DataBaseRestoreFromFile(string mysqlPath, string inFilePath)
{
bool fatto = false;
// aggiungo sql finale
if (!inFilePath.EndsWith(".sql"))
{
inFilePath = $"{inFilePath}.sql";
}
// chiamo script esterno...
string callScript = $"\"{mysqlPath}\" -u{DATABASE_USER} -p{DATABASE_PWD} {DATABASE_NAME} < {inFilePath}";
ExecuteCommand(callScript);
return fatto;
}
/// <summary>
/// Esecuzione di un comando esterno
/// </summary>
@@ -134,13 +157,12 @@ namespace EgtBEAMWALL.DataLayer
process.Close();
}
/// <summary>
/// Metodo di init standard per DB in rete con Master_Key
/// </summary>
/// <param name="server">Indirizzo del server (tipicamente indirizzo di rete)</param>
/// <param name="nKey">Numero chiave</param>
/// <param name="sKey">Codice/pwd associato a chaive</param>
/// <param name="sKey">Codice/pwd associato a chiave</param>
/// <param name="masterKey">Numero di chiave master con cui è creato il DB</param>
public static void InitDb(string server, string nKey, string sKey, string masterKey = "")
{
+1 -1
View File
@@ -28,4 +28,4 @@
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>EgtBEAMWALL.StressTest</RootNamespace>
<AssemblyName>EgtBEAMWALL.StressTest</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
+1 -1
View File
@@ -19,7 +19,7 @@ namespace EgtBEAMWALL.StressTest.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
+1 -1
View File
@@ -12,7 +12,7 @@ namespace EgtBEAMWALL.StressTest.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+40 -42
View File
@@ -1,25 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace EgtBEAMWALL.StressTest
{
public class Simulator
{
#region Protected Fields
protected DataLayer.Controllers.BTLPartController BtlPartCtr = new DataLayer.Controllers.BTLPartController();
protected DataLayer.Controllers.MachGroupController MachGroupCtr = new DataLayer.Controllers.MachGroupController();
protected SimParams MaxParams = new SimParams();
protected DataLayer.Controllers.PartController PartCtr = new DataLayer.Controllers.PartController();
protected DataLayer.Controllers.ProdController ProdCtr = new DataLayer.Controllers.ProdController();
protected DataLayer.Controllers.ProjController ProjCtr = new DataLayer.Controllers.ProjController();
#endregion Protected Fields
#region Public Fields
public List<Core.BTLPartM> BtlPartList = new List<Core.BTLPartM>();
@@ -30,30 +16,6 @@ namespace EgtBEAMWALL.StressTest
#endregion Public Fields
#region Protected Properties
/// <summary>
/// restituisce un set di parametri simulazione generando a caso dal set di base
/// </summary>
protected SimParams RandomParamSet
{
get
{
Random rndGen = new Random();
SimParams answ = new SimParams()
{
BtlPart2Proj = rndGen.Next(MaxParams.BtlPart2Proj) + 1,
BtlRepeat = rndGen.Next(MaxParams.BtlRepeat) + 1,
Part2MachGroup = rndGen.Next(MaxParams.Part2MachGroup) + 1,
Proj2Prod = rndGen.Next(MaxParams.Proj2Prod) + 1
};
return answ;
}
}
#endregion Protected Properties
#region Public Methods
/// <summary>
@@ -79,7 +41,7 @@ namespace EgtBEAMWALL.StressTest
List<DataLayer.DatabaseModels.BTLPartModel> currPartList = new List<DataLayer.DatabaseModels.BTLPartModel>();
List<Core.MyMachGroupM> currMachGroupList = new List<Core.MyMachGroupM>();
List<Core.PartM> currMGPartList = new List<Core.PartM>();
ProjCtr.UpdateInfo(currProjId, $"{DateTime.Now:yyyyMMdd_HHmmssfff}", $"LN_{DateTime.Now:yyyyMMdd_HHmm}", DateTime.Now.AddSeconds(15), Core.ConstBeam.BWType.BEAM, "SIM01");
ProjCtr.UpdateInfo(currProjId, "TestBTL", $"{DateTime.Now:yyyyMMdd_HHmmssfff}", $"LN_{DateTime.Now:yyyyMMdd_HHmm}", DateTime.Now.AddSeconds(15), Core.ConstBeam.BWType.BEAM, "SIM01");
// genero le BTLParts ed assegno..
for (int j = 0; j < currRandom.BtlPart2Proj; j++)
{
@@ -107,8 +69,8 @@ namespace EgtBEAMWALL.StressTest
{
for (int l = 0; l < currRandom.Part2MachGroup; l++)
{
// FixME!!! non può creare x loop in CreateBeamDL che vuole nParentMachGroup
// genero le Part x MachGroup ed assegno
// FixME!!! non può creare x loop in CreateBeamDL che vuole
// nParentMachGroup genero le Part x MachGroup ed assegno
Core.PartM currPart = Core.PartM.CreatePart(Core.ConstBeam.BWType.BEAM, currMachGroupList.FirstOrDefault(), currPartList[BPIdx].PartId, 1);
currMGPartList.Add(currPart);
//currMGPartList.Add(new DataLayer.DatabaseModels.PartModel() { BTLPartDbId = currBTLPart.BTLPartDbId, PDN = l * k * currRandom.Part2MachGroup, PartId = l, H = 10 * l, L = 50 * l, W = 5 * l });
@@ -138,9 +100,45 @@ namespace EgtBEAMWALL.StressTest
public void initDb()
{
var firstData = ProjCtr.GetLastDesc(1);
var firstData = ProjCtr.GetLastDesc(1, true);
}
#endregion Public Methods
#region Protected Fields
protected DataLayer.Controllers.BTLPartController BtlPartCtr = new DataLayer.Controllers.BTLPartController();
protected DataLayer.Controllers.MachGroupController MachGroupCtr = new DataLayer.Controllers.MachGroupController();
protected SimParams MaxParams = new SimParams();
protected DataLayer.Controllers.PartController PartCtr = new DataLayer.Controllers.PartController();
protected DataLayer.Controllers.ProdController ProdCtr = new DataLayer.Controllers.ProdController();
protected DataLayer.Controllers.ProjController ProjCtr = new DataLayer.Controllers.ProjController();
#endregion Protected Fields
#region Protected Properties
/// <summary>
/// restituisce un set di parametri simulazione generando a caso dal set di base
/// </summary>
protected SimParams RandomParamSet
{
get
{
Random rndGen = new Random();
SimParams answ = new SimParams()
{
BtlPart2Proj = rndGen.Next(MaxParams.BtlPart2Proj) + 1,
BtlRepeat = rndGen.Next(MaxParams.BtlRepeat) + 1,
Part2MachGroup = rndGen.Next(MaxParams.Part2MachGroup) + 1,
Proj2Prod = rndGen.Next(MaxParams.Proj2Prod) + 1
};
return answ;
}
}
#endregion Protected Properties
}
}
+38 -1
View File
@@ -35,6 +35,9 @@ namespace EgtBEAMWALL.StressTest
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonDataSeed = new System.Windows.Forms.Button();
this.labelResult = new System.Windows.Forms.Label();
this.btnDbDump = new System.Windows.Forms.Button();
this.btnDbRestore = new System.Windows.Forms.Button();
this.txtDumpFile = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
@@ -92,17 +95,48 @@ namespace EgtBEAMWALL.StressTest
// labelResult
//
this.labelResult.AutoSize = true;
this.labelResult.Location = new System.Drawing.Point(479, 91);
this.labelResult.Location = new System.Drawing.Point(250, 75);
this.labelResult.Name = "labelResult";
this.labelResult.Size = new System.Drawing.Size(35, 13);
this.labelResult.TabIndex = 4;
this.labelResult.Text = "label2";
//
// btnDbDump
//
this.btnDbDump.Location = new System.Drawing.Point(18, 136);
this.btnDbDump.Name = "btnDbDump";
this.btnDbDump.Size = new System.Drawing.Size(75, 23);
this.btnDbDump.TabIndex = 5;
this.btnDbDump.Text = "DB Dump";
this.btnDbDump.UseVisualStyleBackColor = true;
this.btnDbDump.Click += new System.EventHandler(this.btnDbDump_Click);
//
// btnDbRestore
//
this.btnDbRestore.Location = new System.Drawing.Point(338, 136);
this.btnDbRestore.Name = "btnDbRestore";
this.btnDbRestore.Size = new System.Drawing.Size(75, 23);
this.btnDbRestore.TabIndex = 6;
this.btnDbRestore.Text = "DB Restore";
this.btnDbRestore.UseVisualStyleBackColor = true;
this.btnDbRestore.Click += new System.EventHandler(this.btnDbRestore_Click);
//
// txtDumpFile
//
this.txtDumpFile.Location = new System.Drawing.Point(118, 136);
this.txtDumpFile.Name = "txtDumpFile";
this.txtDumpFile.Size = new System.Drawing.Size(186, 20);
this.txtDumpFile.TabIndex = 3;
this.txtDumpFile.Text = "C:\\Temp\\MyDbDump.sql";
//
// StressTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.txtDumpFile);
this.Controls.Add(this.btnDbRestore);
this.Controls.Add(this.btnDbDump);
this.Controls.Add(this.labelResult);
this.Controls.Add(this.groupBox1);
this.Name = "StressTest";
@@ -122,6 +156,9 @@ namespace EgtBEAMWALL.StressTest
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button buttonDataSeed;
private System.Windows.Forms.Label labelResult;
private System.Windows.Forms.Button btnDbDump;
private System.Windows.Forms.Button btnDbRestore;
private System.Windows.Forms.TextBox txtDumpFile;
}
}
+41 -2
View File
@@ -4,7 +4,9 @@ using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
@@ -26,8 +28,10 @@ namespace EgtBEAMWALL.StressTest
public StressTest()
{
InitializeComponent();
// warm up DB
CurrSim.initDb();
// init cablato sul mio DB
DataLayer.DbConfig.InitDb("127.0.0.1", "000470", "36311", "000470");
//// warm up DB
//CurrSim.initDb();
}
#endregion Public Constructors
@@ -69,5 +73,40 @@ namespace EgtBEAMWALL.StressTest
}
#endregion Private Methods
private void btnDbDump_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Sicuro di voler generare il dump del DB corrente?", "DB Dump", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
labelResult.Text = "...";
//string binPath = "C:\\Program Files\\MariaDB 10.5\\bin";
//string myDumpPath = Path.Combine(binPath, "mysqldump.exe");
string myDumpPath = "mysqldump";
string outPath = txtDumpFile.Text.Trim();
if (!string.IsNullOrEmpty(outPath))
{
// effettua dump
DataLayer.DbConfig.DataBaseDumpToFile(myDumpPath, outPath);
labelResult.Text = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} | Dump Done!";
}
}
}
private void btnDbRestore_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Sicuro di voler ripristinare il file dump sul DB corrente?", "DB Restore", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
labelResult.Text = "...";
//string binPath = "C:\\Program Files\\MariaDB 10.5\\bin";
//string mysqlPath = Path.Combine(binPath, "mysql.exe");
string mysqlPath = "mysql";
string inPath = txtDumpFile.Text.Trim();
// effettua restore
DataLayer.DbConfig.DataBaseRestoreFromFile(mysqlPath, inPath);
labelResult.Text = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} | Restore Done!";
}
}
}
}