Java備份還原Oracle資料庫

來源:互聯網
上載者:User

Java備份還原Oracle資料庫,不知道還有沒好點的方法 希望有的也能提供下方法或者代碼。

package com.servlet.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Database Backup還原
 * @author RootSuper
 * @version 2012-11-12
 */
@SuppressWarnings("unused")
public class BackupOracleDatabase {

 /** 使用者名稱 */
 private String userName;
 /** 密碼 */
 private String userPass;
 /** 服務地址 */
 private String serverAddr;
 /** 備份檔案路徑 */
 private String backupFilePath;
 /** 備份日誌路徑*/
 private String logPath;

 /**
  * constructor
  * @param userName 資料庫使用者名稱
  * @param userPass 資料庫使用者密碼
  * @param serverAddr  服務地址:連接埠/資料庫名稱
  * @param backupFilePath 備份檔案路徑
  */
 public BackupOracleDatabase(String Name, String Pass,
   String Addr, String FilePath,String log) {
  this.userName = Name;
  this.userPass = Pass;
  this.serverAddr = Addr;
  this.backupFilePath = FilePath;
  this.logPath = log;
 }

 
 /**
  * 擷取命令串
  * @param bool 是否為還原資料庫的命令串 預設為擷取備份命令
  * @return commStr 命令串
  */
 private String GetCommand(boolean bool){
  String commStr = "EXP @USER@/@PASSWORD@@@SERVER@ FILE=@FILEPATH@ LOG=@LOGPATH@ FULL=Y";
  if(bool){
   commStr = "IMP @USER@/@PASSWORD@@@SERVER@ FILE=@FILEPATH@ LOG=@LOGPATH@ FULL=Y";
  }
  String temp = commStr.replaceAll("@USER@", this.userName).replaceAll("@PASSWORD@", this.userPass).replaceAll("@SERVER@", this.serverAddr).replaceAll("@FILEPATH@",this.backupFilePath).replaceAll("@LOGPATH@", this.logPath);
  System.out.println(temp);
    return temp;
 }
 

 /**
  * 備份或者還原資料庫
  * @param bool 真:還原資料庫  假:備份資料庫
  * @return boolean
  */
 public boolean expBackup(boolean bool) {
  Runtime rt = Runtime.getRuntime();
  Process processexp = null; 
  try {
   processexp = rt.exec(GetCommand(bool));
   return true;
  } catch (IOException e) {
   e.printStackTrace();
  }
  return false;
 }
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.