Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region backupdatabase
- if (Now.Hour == 00 && Now.Minute == 00 && Now.Second == 00)
- {
- string a = @"C:\AppServ";
- string user = "root";
- string pass = "12345678";
- string database = "hard";
- string filename = "databackup.sql";
- try
- {
- if (File.Exists(@"C:\AppServ\databackup.sql"))
- {
- Console.WriteLine("Deleting old file");
- File.Delete(@"C:\AppServ\databackup.sql");
- StreamWriter MySWriter;
- StreamReader MySReader;
- Process myp = new Process();
- myp.StartInfo.FileName = "cmd.exe";
- myp.StartInfo.UseShellExecute = false;
- myp.StartInfo.WorkingDirectory = a;
- myp.StartInfo.RedirectStandardInput = true;
- myp.StartInfo.RedirectStandardOutput = true;
- myp.Start();
- MySWriter = myp.StandardInput;
- MySReader = myp.StandardOutput;
- MySWriter.WriteLine("mysqldump --no-defaults -u " + user + " -p" + pass + " " + database + " >" + filename + "");
- MySWriter.Close();
- myp.WaitForExit();
- myp.Close();
- Console.WriteLine("database backedup at " + DateTime.Now.Date);
- }
- else
- {
- StreamWriter MySWriter;
- StreamReader MySReader;
- Process myp = new Process();
- myp.StartInfo.FileName = "cmd.exe";
- myp.StartInfo.UseShellExecute = false;
- myp.StartInfo.WorkingDirectory = a;
- myp.StartInfo.RedirectStandardInput = true;
- myp.StartInfo.RedirectStandardOutput = true;
- myp.Start();
- MySWriter = myp.StandardInput;
- MySReader = myp.StandardOutput;
- MySWriter.WriteLine("mysqldump --no-defaults -u " + user + " -p" + pass + " " + database + " >" + filename + "");
- MySWriter.Close();
- myp.WaitForExit();
- myp.Close();
- Console.WriteLine("database backedup at " + DateTime.Now.Date);
- }
- }
- catch (Exception ef)
- {
- Console.WriteLine(ef);
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement