应用程序中oracle数据库备份和恢复

昨天花了一个多小时写的一个小东西,可能以前有很多人写过了,不过还是放上来看看

备份,可以实现在应用程序文件夹内生成一个DataBaseBak文件夹,并把dmp文件按照时间来保存在这个文件夹内,我设的精度是分钟,可以自行更改,异常写入系统日志:

   string startpath = Application.StartupPath;
   DirectoryInfo di = new DirectoryInfo(startpath+"\\DataBaseBak");
   di.Create();
   string oraPath = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Oracle").GetValue("ORACLE_HOME").ToString();
   System.Diagnostics.Process proc = new System.Diagnostics.Process();
   proc.EnableRaisingEvents = false;
   proc.StartInfo.FileName = oraPath +"\\bin\\EXP.exe";
   proc.StartInfo.Arguments = " username/password@servicename file="+di.FullName+"\\filename"+DateTime.Now.ToString("yyyy-MM-dd-HH-mm")+".dmp owner=username";
   proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
   this.Cursor = Cursors.WaitCursor;
   try
   {
    proc.Start();
    MessageBox.Show("数据库备份成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
   }
   catch(Exception ee)
   {
    MessageBox.Show("数据库备份失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    EventLog newLog=new EventLog();
    newLog.Source = "OracleErr";
    newLog.WriteEntry(ee.Message,System.Diagnostics.EventLogEntryType.Error);
   }
   finally
   {
    proc.Dispose();
   }

   this.Cursor = Cursors.Arrow;

恢复,可以自动定位到DataBaseBak文件夹,然后自行选择需要的dmp文件,进行恢复,并将异常写入系统日志:

OpenFileDialog selectDMPDialog = new OpenFileDialog();
   selectDMPDialog.InitialDirectory = Application.StartupPath + "\\DataBaseBak";
   selectDMPDialog.Filter = "备份文件(*.dmp)|*.dmp";
   if(selectDMPDialog.ShowDialog() == DialogResult.OK)
   {
    string oraPath = Registry.LocalMachine.OpenSubKey("software").OpenSubKey("Oracle").GetValue("ORACLE_HOME").ToString();
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents = false;
    proc.StartInfo.FileName = oraPath+"\\bin\\IMP.exe";
    proc.StartInfo.Arguments = " username/password@servicename file="+selectDMPDialog.InitialDirectory+"\\"+selectDMPDialog.FileName+" fromuser=username";
    proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    this.Cursor = Cursors.WaitCursor;
    try
    {
     proc.Start();
     MessageBox.Show("数据库导入成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    catch(Exception ee)
    {
     MessageBox.Show("数据库备份失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
     EventLog newLog=new EventLog();
     newLog.Source = "OracleErr";
     newLog.WriteEntry(ee.Message,System.Diagnostics.EventLogEntryType.Error);
    }
    finally
    {
     proc.Dispose();
    }
    this.Cursor = Cursors.Arrow;

转载于:https://www.cnblogs.com/ggyyppmm/archive/2004/09/02/38848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值