Friday 10 June 2011

Oracle backup and Restore code in c#.net

For Backup:

protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime Time = DateTime.Now;
        int year = Time.Year;
        int month = Time.Month;
        int day = Time.Day;
        int hour = Time.Hour;
        int min = Time.Minute;
        int second = Time.Second;
        int millisecond = Time.Millisecond;

        string path = "C:/oracle/product/10.2.0/backup/";
        path = path + day + "-" + month + "-" + year + "-" + hour + "-" + min + "-" + second + "-" + millisecond;
              
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = "C:/oracle/product/10.2.0/db_1/BIN/exp.exe";
        psi.RedirectStandardInput = false;
        psi.RedirectStandardOutput = true;
        //psi.Arguments = string.Format("USERID=test/test  FULL=y FILE=" + path + ".dmp CONSISTENT=y GRANTS=y BUFFER=100000 rows = Yes");
        psi.Arguments = string.Format("USERID=test/test  FILE=" + path + ".dmp TABLES=(t)");
        psi.UseShellExecute = false;
       
        Process process = Process.Start(psi);
        process.WaitForExit();
        process.Close();
        Response.Write("<script>alert('Database Backup Completed Successfully')</script>");
      
    }
For Restore:

 protected void Button2_Click(object sender, EventArgs e)
    {
       // 2011-4-5-16-5-49-156.dmp
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = "C:/oracle/product/10.2.0/db_1/BIN/imp.exe";
        psi.RedirectStandardInput = false;
        psi.RedirectStandardOutput = true;
        psi.Arguments = string.Format("USERID=test/test  FILE=C:/oracle/product/10.2.0/backup/111.dmp FROMUSER=test TABLES=(t) IGNORE=y");
        //imp SYSTEM/password FULL=y FIlE=dba.dmp
        psi.UseShellExecute = false;


        Process process = Process .Start(psi);
        process.WaitForExit();
        process.Close();
        Response.Write("<script>alert('Database Restore Completed Successfully')</script>");

    }


3 comments:

  1. pls send me this app dr.gn8n@gmail.com

    ReplyDelete
  2. It is working on test perfectly but unable to operate in production pc.

    ReplyDelete