MySQL backup/Restore:

- nota sui parametri da impiegare
- update eseguibili x call default
- stopwatch esempio tempi esecuzione
This commit is contained in:
Samuele Locatelli
2023-07-27 08:50:59 +02:00
parent b279a287ec
commit 531da47cbc
2 changed files with 58 additions and 57 deletions
+5 -5
View File
@@ -76,10 +76,10 @@ namespace EgtBEAMWALL.DataLayer
/// <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>
/// <param name="mysqlDumpPath">Nome o Percorso Eseguibile mysqldump (opzionale)</param>
/// <returns></returns>
public static bool DataBaseDumpToFile(string mysqlDumpPath, string outFilePath)
public static bool DataBaseDumpToFile(string outFilePath, string mysqlDumpPath = "mysqldump")
{
bool fatto = false;
// aggiungo sql finale
@@ -98,7 +98,7 @@ namespace EgtBEAMWALL.DataLayer
{
File.Delete(outFilePath);
}
// chiamo script esterno...
// chiamo script esterno... importante parametro "--skip-extended-insert" altrimenti problemi con restore (anche se + verboso e lento in backup...)
string callScript = $"\"{mysqlDumpPath}\" -u{DATABASE_USER} -p{DATABASE_PWD} {DATABASE_NAME} --skip-extended-insert > {outFilePath}";
ExecuteCommand(callScript);
return fatto;
@@ -107,10 +107,10 @@ namespace EgtBEAMWALL.DataLayer
/// <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>
/// <param name="mysqlPath">Nome o Percorso Eseguibile mysql (opzionale)</param>
/// <returns></returns>
public static bool DataBaseRestoreFromFile(string mysqlPath, string inFilePath)
public static bool DataBaseRestoreFromFile(string inFilePath, string mysqlPath="mysql")
{
bool fatto = false;
// aggiungo sql finale
+53 -52
View File
@@ -1,28 +1,11 @@
using System;
using System.Collections.Generic;
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;
namespace EgtBEAMWALL.StressTest
{
public partial class StressTest : Form
{
#region Protected Fields
/// <summary>
/// Controller dati simulati x provare procedure
/// </summary>
protected Simulator CurrSim = new Simulator();
#endregion Protected Fields
#region Public Constructors
public StressTest()
@@ -36,6 +19,15 @@ namespace EgtBEAMWALL.StressTest
#endregion Public Constructors
#region Protected Fields
/// <summary>
/// Controller dati simulati x provare procedure
/// </summary>
protected Simulator CurrSim = new Simulator();
#endregion Protected Fields
#region Protected Properties
protected int numProj
@@ -56,6 +48,50 @@ namespace EgtBEAMWALL.StressTest
#region 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 = "...";
Stopwatch sw = new Stopwatch();
sw.Start();
//string binPath = "C:\\Program Files\\MariaDB 10.5\\bin";
//string myDumpPath = Path.Combine(binPath, "mysqldump.exe");
string outPath = txtDumpFile.Text.Trim();
if (!string.IsNullOrEmpty(outPath))
{
// effettua dump
//DataLayer.DbConfig.DataBaseDumpToFile(outPath, "mysqldump");
DataLayer.DbConfig.DataBaseDumpToFile(outPath);
sw.Stop();
var elapsed = sw.Elapsed;
labelResult.Text = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} | Dump Done in {elapsed.TotalSeconds:N3} sec!";
}
}
}
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 = "...";
Stopwatch sw = new Stopwatch();
sw.Start();
//string binPath = "C:\\Program Files\\MariaDB 10.5\\bin";
//string mysqlPath = Path.Combine(binPath, "mysql.exe");
string inPath = txtDumpFile.Text.Trim();
// effettua restore
//DataLayer.DbConfig.DataBaseRestoreFromFile(inPath, "mysql");
DataLayer.DbConfig.DataBaseRestoreFromFile(inPath); sw.Stop();
var elapsed = sw.Elapsed;
labelResult.Text = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} | Restore Done in {elapsed.TotalSeconds:N3} sec!";
}
}
private void buttonDataSeed_Click(object sender, EventArgs e)
{
// genero dati col SIM
@@ -73,40 +109,5 @@ 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!";
}
}
}
}