protected void btnCommit_Click(object sender, EventArgs e) { if (GridViewDBBackupList.SelectedIndex == -1) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(/"没有选择要恢复的备份!/");", true); } else { DataTable dt = common.getDataTable("select * from prodoc_jc_dbbackuprestore where id=" + GridViewDBBackupList.SelectedDataKey["id"].ToString()); if (dt != null && dt.Rows.Count > 0) { string filePath = @"" + System.Configuration.ConfigurationManager.AppSettings["dbbackuppath"].ToString(); string fileName = dt.Rows[0]["fileName"].ToString(); if (File.Exists(filePath + "//" + fileName))//d:/dbbackup/db.sql")) { string str = common.CallExe(@"mysql -uroot -p" + System.Configuration.ConfigurationManager.AppSettings["mysqlrootpwd"].ToString() + " " + System.Configuration.ConfigurationManager.AppSettings["mysqldbname"].ToString() + "" + filePath + "//" + fileName); if (str.Equals("OK")) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(/"备份成功!/");closeBackupList();", true); string sql = string.Empty; sql = "insert into prodoc_jc_dbbackuprestore(filePath,fileName,autoORmanu"; if (Session["userRealName"] != null) sql += ",createPerson"; sql += ")"; sql += " values('" + filePath + "','" + fileName + "',1"; if (Session["userRealName"] != null) sql += ",'" + Session["userRealName"] + "'"; sql += ")"; common.executeNoQuery(sql);
欢迎大家阅读《C# mysql 备份复原表》,跪求各位点评,by 搞代码
bindData(); } } #endregion #region 功能:执行dos命令;参数:一个,要执行的dos命令;返回值:成功,OK;失败,错误信息 public string CallExe(string argm) { Process p = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe"; //设定需要执行的命令
startInfo.Arguments = "/C " + argm; // 设定参数,其中的“/C”表示执行完命令后马上退出 startInfo.UseShellExecute = false; //不使用系统外壳程序启动 startInfo.RedirectStandardInput = false; //不重定向输入 startInfo.RedirectStandardOutput = true; //重定向输出 startInfo.CreateNoWindow = true; //不创建窗口 p.StartInfo = startInfo;
try { if (p.Start()) //开始进程 { //if (milliseconds == 0) p.WaitForExit(); //这里无限等待进程结束 //else //p.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒 } } catch (Exception ex) { return ex.ToString(); } finally { if (p != null) p.Close(); } return "OK"; } #endregion
mysqldump -uxxx -pxxx --ignore-table=database.table1 --ignore-table=database.table2 > backup.sql mysqldump -uxxx -pxxx table1 table2 … > backup.sql