Advertisement
RuBeRto

program

Sep 21st, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1.  case "@backup":
  2.                     {
  3.                         string a = @"C:\AppServ";
  4.                         string user = "root";
  5.                         string pass = "12345678";
  6.                         string database = "hard";
  7.                         string filename = "databackup.sql";
  8.                         try
  9.                         {
  10.                             if (File.Exists(@"C:\AppServ\databackup.sql"))
  11.                             {
  12.                                 Console.WriteLine("Deleting old file");
  13.                                 File.Delete(@"C:\AppServ\databackup.sql");
  14.                                 StreamWriter MySWriter;
  15.                                 StreamReader MySReader;
  16.                                 Process myp = new Process();
  17.                                 myp.StartInfo.FileName = "cmd.exe";
  18.                                 myp.StartInfo.UseShellExecute = false;
  19.                                 myp.StartInfo.WorkingDirectory = a;
  20.                                 myp.StartInfo.RedirectStandardInput = true;
  21.                                 myp.StartInfo.RedirectStandardOutput = true;
  22.                                 myp.Start();
  23.  
  24.                                 MySWriter = myp.StandardInput;
  25.                                 MySReader = myp.StandardOutput;
  26.                                 MySWriter.WriteLine("mysqldump --no-defaults -u "+user+" -p"+pass+" "+database+" >" + filename + "");
  27.                                 MySWriter.Close();
  28.                                 myp.WaitForExit();
  29.                                 myp.Close();
  30.                                 Console.WriteLine("database backedup at " + DateTime.Now.Date);
  31.                             }
  32.                             else
  33.                             {
  34.                                 StreamWriter MySWriter;
  35.                                 StreamReader MySReader;
  36.                                 Process myp = new Process();
  37.                                 myp.StartInfo.FileName = "cmd.exe";
  38.                                 myp.StartInfo.UseShellExecute = false;
  39.                                 myp.StartInfo.WorkingDirectory = a;
  40.                                 myp.StartInfo.RedirectStandardInput = true;
  41.                                 myp.StartInfo.RedirectStandardOutput = true;
  42.                                 myp.Start();
  43.  
  44.                                 MySWriter = myp.StandardInput;
  45.                                 MySReader = myp.StandardOutput;
  46.                                 MySWriter.WriteLine("mysqldump --no-defaults -u " + user + " -p" + pass + " " + database + " >" + filename + "");
  47.                                 MySWriter.Close();
  48.                                 myp.WaitForExit();
  49.                                 myp.Close();
  50.                                 Console.WriteLine("database backedup at " + DateTime.Now.Date);
  51.                             }
  52.                         }
  53.                         catch (Exception ef)
  54.                         {
  55.                             Console.WriteLine(ef);
  56.                         }
  57.                         break;
  58.                     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement