From 4dbaf918df25fe4b56c818771ac3d8176729ead1 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 9 Mar 2023 18:48:45 +0800 Subject: [PATCH] MySql backup data base --- .../MySql/DbMaintenance/MySqlDbMaintenance.cs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index b3b49d471..7827be53a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Text.RegularExpressions; @@ -570,8 +571,33 @@ namespace SqlSugar } public override bool BackupDataBase(string databaseName, string fullFileName) { - Check.ThrowNotSupportedException("MySql BackupDataBase NotSupported"); - return false; + if (fullFileName == null) + { + fullFileName = $"c:\\{databaseName}.sql"; + } + var db = this.Context.CopyNew(); + using (db.Ado.OpenAlways()) + { + if (databaseName != null) + { + db.Ado.Connection.ChangeDatabase(databaseName); + } + // Load the MySqlBackup assembly + Assembly assembly = Assembly.LoadFrom("MySqlBackup.dll"); + + // Get the MySqlBackup type + Type mbType = assembly.GetType("MySqlConnector.MySqlBackup"); + + // Create an instance of the MySqlBackup class + object mb = Activator.CreateInstance(mbType, db.Ado.Connection.CreateCommand()); + + // Get the ExportToFile method + MethodInfo exportMethod = mbType.GetMethod("ExportToFile"); + + // Invoke the ExportToFile method + exportMethod.Invoke(mb, new object[] { fullFileName }); + } + return true; } #endregion