程式發布在公司服務器上,程式使用的是mysql資料庫,如何在頁面上點擊備份按鈕實作將服務器上的mysql資料庫備份下來,我目前的方式是:
public static void BackupOrRestoreDB(string HostName, string PWD, string DbName, string filename)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//指定MySql程式的bin 目錄
p.StartInfo.WorkingDirectory = GetMysqlPath() + "\\bin";
p.Start();
/*************
* 備份命令
**************/
//簡單格式
//string strSql = "mysqldump --quick --host=192.168.0.52 -u root -pdstest2011 dsrsksdb_v6 > d:\\test_20151227110010.sql";
if (Directory.Exists(AppSetting.GetConfig("AppSetting:DBBakpath")) == false)
{
Directory.CreateDirectory(AppSetting.GetConfig("AppSetting:DBBakpath"));
}
string strSql = "mysqldump --quick --host=" + HostName + " -u root -p" + PWD + " " + DbName + " > " + AppSetting.GetConfig("AppSetting:DBBakpath") + filename + ".sql";
p.StandardInput.WriteLine(strSql + " &exit");
p.StandardInput.AutoFlush = true;
//顯示方式2
string result = p.StandardOutput.ReadToEnd();
Console.WriteLine(result);
//回傳警告結果 --Warning: Using a password on the command line interface can be insecure.
string result2 = p.StandardError.ReadToEnd();
Console.WriteLine(result2);
//顯示方式3
ShowValue(p);
p.WaitForExit();
p.Close();
}
public static string GetMysqlPath()
{
string strPath = string.Empty;
string strsql = "select @@basedir as basePath from dual ";
DataSet dsLJ = DbHelperMySQL.Query(strsql);
if (!dsLJ.DsIsNullOrEmpty())
{
strPath = dsLJ.Tables[0].Rows[0]["basePath"].ToString();
}
strPath = strPath.Replace("/", "\\");
return strPath;
}
當資料庫在我本機上時使用該種方式能夠備份成功,當資料庫放在公司服務器上時進行備份就會提示“目錄名稱無效”,我改怎么解決呢?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/270129.html
標籤:C#
上一篇:System.PlatformNotSupportedException:“Secure binary serialization is not support
