Would you like to react to this message? Create an account in a few clicks or log in to continue.

    My Backup - Command line

    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    My Backup - Command line Empty My Backup - Command line

    Post  Admin Thu Nov 26, 2009 9:07 am

    try
    {
    DateTime backupTime = DateTime.Now;
    int year = backupTime.Year;
    int month = backupTime.Month;
    int day = backupTime.Day;
    int hour = backupTime.Hour;
    int minute = backupTime.Minute;
    int second = backupTime.Second;
    int ms = backupTime.Millisecond;

    String tmestr = backupTime.ToString();
    tmestr = "C:\\"+year+"-"+month+"-"+day+"-"+hour+"-"+minute+".sql";
    StreamWriter file = new StreamWriter(tmestr);
    ProcessStartInfo proc = new ProcessStartInfo();
    string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} > {4};", "root", "password", "localhost", "dbfile", "backup.sql");
    proc.FileName = "mysqldump";
    proc.RedirectStandardInput = false;
    proc.RedirectStandardOutput = true;
    proc.Arguments = cmd;//"-u root -p smartdb > testdb.sql";
    proc.UseShellExecute = false;
    Process p = Process.Start(proc);
    string res;
    res = p.StandardOutput.ReadToEnd();
    file.WriteLine(res);
    p.WaitForExit();
    file.Close();

    }

    catch (IOException ex)
    {
    MessageBox.Show("Disk full or other IO error , unable to backup!");
    }

      Current date/time is Mon May 20, 2024 8:56 am