Home > Database > Mysql Tutorial > Java备份还原Oracle数据库

Java备份还原Oracle数据库

WBOY
Release: 2016-06-07 17:25:34
Original
991 people have browsed it

Java备份还原Oracle数据库,不知道还有没好点的方法 希望有的也能提供下方法或者代码。

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;

/**
 * 数据库备份还原
 * @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;
 }
}

 

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template