当我尝试进行数据库备份或还原时,意味着它无法正常工作。因为我给出的路径包含“SPACE”
备份/恢复文件路径:“ C:\Documents and Settings\prabhu\Desktop\Backup.sql ”
(Documents and Settings包含“SPACE”)
我在 C# 中工作。
代码:
string directoryName = D:\\Shop Plan\\ERP Project\\Main Source\\OutPut\\Debug\\DBBackup;
string filePath = "C:\Documents and Settings\prabhu\Desktop\Backup.sql";
TextWriter textWriter = new StreamWriter(filePath);
textWriter.WriteLine("CD " + directoryName);
if (type == "Backup")
{
textWriter.WriteLine("mysqldump -h " + "SERVERNAME"+ " -u " + "USERNAME" + " -p" + "PASSWORD" + " -P " + "PORT" + " --routines " + "DATABASE_NAME" + " -B> " + filePath);
}
else if (type == "Restore")
{
textWriter.WriteLine("mysql -h " + "SERVERNAME" + " -u " + "USERNAME" + " -p" + "PASSWORD" +" -P " + "PORT" + " <" + filePath);
}
textWriter.Close();
Process processes = new Process();
processes.StartInfo.WorkingDirectory = directoryName ;
processes.StartInfo.FileName = "Backup.BAT";
processes.StartInfo.CreateNoWindow = true;
processes.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processes.Start();
processes.WaitForExit();