I'm tasked to write c#.net code for Mysql Backup and Restore.
The Backup is taken from Server A and restored on Server B. The code written, It executes back up perfectly. But the Restore is not happening. I put the same command line from c# code to command prompt and execute it. It restores from there. But not c# program. Please help me in identifying the mistake I'm making.
static public void restore(string ip, string user, string password, string[] tblList, string sourcedb, string targetdb)
{
try
{
string basecmd;
basecmd = "/c mysql -h {0} -u {1} -p{2} {3} < {4}.sql";
foreach (string s in tblList)
{
string db_tbl = sourcedb + "_" + s;
string cmd = String.Format(basecmd, ip, user, pass, targetdb, db_tbl);
//cmd = cmd + " >error1234.txt";
System.Threading.Thread.Sleep(1000);
Console.WriteLine(cmd);
//System.Diagnostics.Process.Start("cmd.exe", cmd);
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", cmd);
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
//sendSuccesEmail();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine("pause");
}
}