java调用系统命令之oracle数据库备份

 
package com.test; 
  

import java.io.BufferedInputStream; 
import java.io.BufferedReader; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.util.Date; 
  

/** 
  * java 程序 导入导出数据库 做到程序定时 ( 结合 quartz,log) 自动备份,防止数据丢失 
  * 
  * @author leiwei 2011 - 12 - 1 
  * 
  */ 
public class BackupDB { 
   
   Runtime runtime = Runtime.getRuntime(); 
Process process = null ; 
   boolean isSuccess = false ; 
   
   /** 
     * 备份、还原 oracle 数据库的方法 
     * 
     * @param cmdStr 备份命令 ( 即导出 ) 
     */ 
   public boolean backupORreductionOracleDB(String cmdStr) { 
      try { 
         process = runtime .exec(cmdStr); 
         isSuccess = true ; 
      } catch (IOException e) { 
         e.printStackTrace(); 
      } 
      return isSuccess ; 
   } 
  

   /** 
     * 
     * 测试 
     */ 
   public static void main(String[] args) { 
      //oracle 备份、还原命令 
      String backupCmd = "exp scott/[email protected]/lworcl file=d:/javaDB.dmp full=y" ; 
//    String reductionCmd = "imp scott/[email protected]/lworcl file=d:/javaDB.dmp full=y"; 
      boolean reSuccess = new BackupDB().backupORreductionOracleDB(backupCmd); 
      System. out .println(reSuccess); 
   } 
}

你可能感兴趣的:(技术成就快乐,Utils)