博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET备份还原MySql数据库 Dump
阅读量:6239 次
发布时间:2019-06-22

本文共 2860 字,大约阅读时间需要 9 分钟。

1  protected void Page_Load(object sender, EventArgs e) 2     { 3         UILogic.ClearCache(); 4         VPUserInfo userinfo = UILogic.getSession() as VPUserInfo; 5         if (userinfo == null) 6         { 7             //Response.Write("
");10 }11 else12 {13 //if (!Page.IsPostBack)14 //{
15 System.IO.Directory.CreateDirectory("C://Program Files//MySQL//MySQL Server 5.0//data//vpdata");//在服务器mysql中创建vpdata数据库16 //}17 }18 }19 20 protected void Backup_Click(object sender, ImageClickEventArgs e)21 {22 try23 {24 //string filename = DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", "");25 26 string filePath = "D://web//App_Data";27 string fileName = filePath + "//vpdata.sql";//备份的文件名称和路径28 //判断目录是否存在29 if (!System.IO.File.Exists(fileName))30 {31 System.IO.Directory.CreateDirectory(filePath);32 }33 34 //构建执行的命令35 String command = string.Format("mysqldump --quick --host=localhost --default-character-set=latin1 --lock-all-tables --port=3306 --user=root --password=123456 --databases vpdata -R >D://web//App_Data//{0}.sql", "vpdata");36 37 //获取mysqldump.exe所在路径38 String appDirecroty = @"C:/Program Files/MySQL/MySQL Server 5.0/bin/";39 40 StartCmd(appDirecroty, command);41 ScriptManager.RegisterClientScriptBlock(Backup, GetType(), "yes", "alert('数据库已成功备份到D://web//App_Data//Vpdata文件中')", true);42 }43 catch (Exception ex)44 {45 ScriptManager.RegisterClientScriptBlock(Backup, GetType(), "no", "alert('数据库备份失败!')", true);46 }47 }48 protected void Restore_Click(object sender, ImageClickEventArgs e)49 {50 try51 {52 53 54 //构建执行的命令55 String command = string.Format("mysql --host=192.168.1.10 --default-character-set=latin1 --port=3306 --user=root --password=123456 vpdata
70 /// 执行Cmd命令71 /// 72 ///
要启动的进程的目录73 ///
要执行的命令74 public static void StartCmd(String workingDirectory, String command)75 {76 Process p = new Process();77 p.StartInfo.FileName = "cmd.exe";78 p.StartInfo.WorkingDirectory = workingDirectory;79 p.StartInfo.UseShellExecute = false;80 p.StartInfo.RedirectStandardInput = true;81 p.StartInfo.RedirectStandardOutput = true;82 p.StartInfo.RedirectStandardError = true;83 p.StartInfo.CreateNoWindow = true;84 p.Start();85 p.StandardInput.WriteLine(command);86 p.StandardInput.WriteLine("exit");87 }

 

转载于:https://www.cnblogs.com/tangzhengyue/archive/2012/04/12/2443907.html

你可能感兴趣的文章