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;
}
}
