zoukankan      html  css  js  c++  java
  • 备份与还原ORACLE数据库(通过CMD命令执行)

    image

    31.1:(若用程序调用cmd,则在备份和还原 末尾语句加上 2>&1 ,直接运行则不需要加)

          --备份:
         1) exp SA/"""abc@1234"""@192.168.31.1:1521/DB1 buffer=10240000 file=C:akdata_back.dmp log=C:akdata_bak_explog.txt owner=(sa,user1) 2>&1
          --还原:还原前先执行删除,后执行还原
        1)  sqlplus sa/"""abc@1234"""@192.168.31.1:1521/DB1 @C:akdeleteDBObjects.txt
        2)  imp SA/"""abc@1234"""@192.168.31.1:1521/DB1 file=C:akdata_back.dmp full=y ignore=y 2>&1

    deleteDBObjects.txt内容:
                          declare vsql varchar2(2000);
                          begin
                                --删除表
                                BEGIN
                                  for i in (select 'drop table '||owner||'.'||table_name||' cascade constraints' v_name
                                              from dba_tables where owner='SA' or owner='user1')
                              loop
                                  vsql:=i.v_name;
                                 --dbms_output.put_line(vsql);
                                   execute immediate vsql;
                                end loop;
                                end;

                                --删除过程和函数
                                BEGIN
                                  for i in (select 'drop '|| object_type||' '||owner||'.' || object_name||'' v_name
                                            from dba_objects where (object_type='PROCEDURE' or object_type='FUNCTION' or object_type='PACKAGE') and (owner='SA' or owner='user1')
                                            )
                                  loop
                                  vsql:=i.v_name;
                                 --dbms_output.put_line(vsql);
                                   execute immediate vsql;
                                  end loop;
                                end;
                          end;
                          /
                          exit;

    相关代码如下:

    public async void ExecuteCmd()
          {
              try
              {
                  Process[] MyProcess = Process.GetProcessesByName("exp");//获取已经存在的exp.exe和imp.exe进程
                  MyProcess.ToList().AddRange(Process.GetProcessesByName("imp"));
                  if (MyProcess.Length != 0)
                  {
                      for (int i = 0; i < MyProcess.Length; i++)
                      {
                          MyProcess[i].Kill();//关闭已存在的进程
                          MyProcess[i].Dispose();
                      }
                  }

                  string cmd = txtInput.Text;// strInput;
                  System.Diagnostics.Process p = new System.Diagnostics.Process();
                  p.StartInfo.FileName = "cmd.exe";// @"D:MyOracleOracle11gproduct11.2.0dbhome_1BINexp.exe";
                                                   //启用操作系统外壳程序执行
                  p.StartInfo.UseShellExecute = false;
                  p.StartInfo.RedirectStandardInput = true;
                  p.StartInfo.RedirectStandardOutput = true;
                  p.StartInfo.RedirectStandardError = true;
                  p.StartInfo.CreateNoWindow = true;

                  p.OutputDataReceived += new DataReceivedEventHandler(P_OutputDataReceived);
                  p.ErrorDataReceived += new DataReceivedEventHandler(P_OutputDataReceived);

                  p.Start();                                  //设置自动刷新缓冲并更新   
                                                              //p.StandardInput.AutoFlush = true;           //写入命令     
                  p.StandardInput.AutoFlush = true;           //写入命令
                  p.StandardInput.WriteLine(cmd);                             //p.StandardInput.WriteLine(strInput);
                  p.StandardInput.WriteLine("exit");          //等待结束  

                  p.BeginOutputReadLine();
                  p.WaitForExit();

              }
              catch (Exception ex)
              {
              }
          }

          delegate void AsynUpdateUI(string msg);
          private void UpdataUIStatus(string msg)
          {
              if (InvokeRequired)
              {
                  this.Invoke(new AsynUpdateUI(delegate (string argMsg)
                  {

                      txtShow.AppendText(argMsg + Environment.NewLine);

                  }), msg);
              }
              else
              {
                  txtShow.AppendText(msg + Environment.NewLine);
              }
          }
          private void P_OutputDataReceived(object sender, DataReceivedEventArgs e)
          {
              if (e.Data != null)
              {
                  string x = e.Data.ToString();
                  UpdataUIStatus(x);
              }
          }
          private void btnBAKUP_Click(object sender, EventArgs e)
          {
              Thread t = new Thread(new ThreadStart(this.ExecuteCmd));
              t.Start();
          }

    点击下载源码

  • 相关阅读:
    Linux Ubuntu系统的安装||grub启动字符界面
    linux 第一个qt程序 以及 linux qt cannotfind lgL的解决
    linux ftp 文件传输的搭建 以qt上传为例
    linux gcc 安装和第一个hello world脚本
    python bug debug
    python 元组的概念以及 math 模块
    移动端调试
    移动终端学习2:触屏原生js事件及重力感应
    input file 类型为excel表格
    gulp构建工具的安装
  • 原文地址:https://www.cnblogs.com/jx270/p/8143153.html
Copyright © 2011-2022 走看看