Exemplo n.º 1
0
 /// <summary>
 /// 备份
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BackUp(object sender, RoutedEventArgs e)
 {
     try
     {
         string DbUserName = ConfigUtil.GetEncrypt("DbUserName", "");
         string DbPassword = ConfigUtil.GetEncrypt("DbPassword", "");
         string DbUrl      = ConfigUtil.GetEncrypt("DbUrl", "");
         //指令
         string strAddress = string.Format("mysqldump -h{0} -u{1} -p{2} --default-character-set=utf8 --lock-tables --routines --force --quick ", DbUrl, DbUserName, DbPassword);
         //string strAddress = string.Format("mysqldump -h{0} -u{1} -p{2} --default-character-set=utf8 --lock-tables --routines --force --quick ", "127.0.0.1", "root", "53231323xjh");
         //数据库名称
         //string strDB = "bdl1";
         string strDB = ConfigUtil.GetEncrypt("DbName", "");
         //mysql的路径
         string mysqlPath = new SetterService().getPath() + @"\bin";
         //备份的路径(获取前端页面)
         //string filePath = System.AppDomain.CurrentDomain.BaseDirectory + @"\BackUp\";
         string filePath = textBox5.Text;
         if (!Directory.Exists(filePath))         //如果不存在就创建file文件夹                 
         {
             Directory.CreateDirectory(filePath); //创建该文件夹  
         }
         //判断是否含空格
         if (filePath.IndexOf(" ") != -1)
         {
             Console.WriteLine("保存路径中含空格");
             MessageBoxX.Warning(LanguageUtils.ConvertLanguage("备份路径不能含有空格", "Backup path cannot contain spaces"));
             return;
         }
         //执行的指令
         string cmd    = strAddress + strDB + " > " + filePath + "bdl.sql";
         string result = CommUtil.RunCmd(mysqlPath, cmd);
         //MessageBox.Show(result);
         //图片备份
         CommUtil.CopyDirectory(filePath);
         if (("mysqldump: [Warning] Using a password on the command line interface can be insecure.".Trim()).Contains(result.Trim()) ||
             ("Warning: Using a password on the command line interface can be insecure.".Trim()).Contains(result.Trim()))
         {
             MessageBoxX.Info(LanguageUtils.ConvertLanguage("数据备份成功", "Successful data backup"));
         }
         else
         {
             MessageBoxX.Error(LanguageUtils.ConvertLanguage("数据备份失败", " Data backup failed"));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("执行sql异常,备份异常" + ex.ToString());
     }
 }