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);//d:\dbbackup\db.sql");
if (str.Equals("OK"))
{
ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\"还原成功!\");closeBackupList();", true);// common.popUpMessage(this.Page, );
string sql = string.Empty;
sql = "insert into prodoc_jc_dbbackuprestore(type,filePath,fileName,autoORmanu";
if (Session["userRealName"] != null)
sql += ",createPerson";
sql += ")";
sql += " values(1,'" + filePath + "','" + fileName + "',1";
if (Session["userRealName"] != null)
sql += ",'" + Session["userRealName"].ToString() + "'";
sql += ")";
common.executeNoQuery(sql);
bindData();
bindDataForBackupList();
}
}
else
//common.popUpMessage(this.Page, "没有找到备份文件!");
ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\"没有找到备份文件!\");", true);
}
}
}
#region backup button
protected void btnBackup_Click(object sender, EventArgs e)
{
if (Session.Count == 0)
{
common.execJavaScript(this.Page, "window.top.location.href='../login.aspx';");
return;
}
string filePath = string.Empty;
filePath = @"" + System.Configuration.ConfigurationManager.AppSettings["dbbackuppath"].ToString();
if (!Directory.Exists(filePath))
common.CallExe(@"mkdir " + filePath);
string fileName = "dbbackup" + System.DateTime.Today.ToString("yyyyMMdd") + System.DateTime.Now.ToLongTimeString().Replace(":", "") + ".sql";
string str = common.CallExe(@"mysqldump -uroot -p" + System.Configuration.ConfigurationManager.AppSettings["mysqlrootpwd"].ToString() + " " + System.Configuration.ConfigurationManager.AppSettings["mysqldbname"].ToString() + " --ignore-table=" + System.Configuration.ConfigurationManager.AppSettings["mysqldbname"].ToString() + ".prodoc_jc_dbbackuprestore>" + 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);
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
相关推荐
用C# 制作MySQL数据库批量备份还原工具
c#备份还原MySql数据库
在用c#开发程序时用到需要备份、还原mysql数据库。看到网上现成的例子不多,因此自己写了一个测试类。比较简单,不过照葫芦画瓢应该可以运行。
C#实现备份、还原MySql数据库,并且采用线程实现每天定时自动备份数据库的功能
该示例工具针对mysql数据备份恢复等问题,使用winform做了数据备份还原工具,简单易用,适合初学者,适合整合软件。
C#实现MySQL数据库的备份、还原和初始化,主要功能:1、数据库的初始化;2、数据库的备份|还原
自己写的mysql数据库备份还原小工具,附源码
C#+写的MySql数据库备份还原小工具(有代码) 京华志&精华志出品 希望大家互相学习,互相进步 支持CSDN 支持微软 主要包括C# ASP.NET SQLDBA 源码 毕业设计 开题报告 答辩PPT等
C#编写的MYSQL数据库备份恢复工具,包含源代码,实现winform图形界面下MYSQL数据库的备份和恢复
MySQL数据库的备份有很多工具可以使用,今天介绍一下使用C#调用MYSQL的mysqldump命令完成MySQL数据库的备份与恢复
MySqlBackup.Net 在C#/ VB.NET / ASP.NET中备份和还原MySQL数据库的工具。如何将此库添加到您的项目中阅读一键备份所有数据库一对一导出所有数据库以分离SQL转储文件。 这是一个使用MySqlBackup.NET的子项目扩展。 ...
使用MYSQL自带的SQL.DLL来对数据备份还原!
包括前提环境的配置,软件的原理&安装&使用,实验截图
进销存管理是企业日常经营管理中十分重要的一个组成部分,传统的手工管理方式呈现出越来越...(21)通过“系统维护/数据备份”菜单项:对数据库进行备份。 (22)通过“系统维护/数据还原”菜单项:对数据库进行还原。
这主要是为了让大家练手的,他使用C#代 码的方法实现了对数据的 备份,还原,分离,附加,添加和删除用户等操作 3.DbHelperMySQL类 数据访问抽象基础类 主要是访问Mysql数据库主要实现如下功能 1.得到最大值 2....
这主要是为了让大家练手的,他使用C#代 码的方法实现了对数据的 备份,还原,分离,附加,添加和删除用户等操作 3.DbHelperMySQL类 数据访问抽象基础类 主要是访问Mysql数据库主要实现如下功能 1.得到最大值 2....
1、asp.net 客户关系管理系统小小CRM,数据库备份文件在database,连接mysql还原此备份文件到 mysql中 2、网站布局:采用目前最先进的布局方式DIV+CSS、bootstrap 前端和后端完全分离可以分布式部署 ,符合W3C的...
1、asp.net 客户关系管理系统小小CRM,数据库备份文件在database,连接mysql还原此备份文件到 mysql中 2、网站布局:采用目前最先进的布局方式DIV+CSS、bootstrap 前端和后端完全分离可以分布式部署 ,符合W3C的...
技能: java,C#,html,js,oracle,mysql... 邮箱: ydh110100@163.com QQ: 380314706 工程中的应该会有很多不足之处,注释不清楚或设计逻辑混乱什么的,请多多谅解,麻烦大家替我找bug了. 如果各位有什么问题或是有好的...
7.2.4 备份数据库 7.2.5 还原数据库 7.2.6 创建表 7.2.7 删除表 7.2.8 创建数据库关系图 7.3 ADO.NET连接SQL数据库 7.3.1 ADO.NET基础 7.3.2 连接SQL数据库 7.3.3 ADO.NET过程 7.4 ADO与ADO.NET 7.4.1 ADO概述 7.4.2...