package atest;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import web.db.DBConnector;
/**
* @author 朱言信
* @desc 备份oracle
*/
public class DadaBackup4Oracle {
public void doWork(){
//执行该数据备份线程
innerBackupClass ibc = new innerBackupClass("这里输入oracle的用户名", "密码", "192.168.0.66:1521/orcl", "输出的地址", "输出的文件名", "要备份的表名");
Thread td = new Thread(ibc);
td.start();
}
class innerBackupClass implements Runnable {
private String user; //用户名
private String password; //密码
private String url; //链接地址
private String outFilePath; //输出的文件路径
// private String outZipFilePath; //输出的zip文件路径
private String filename; //文件名
private String tableNames; //表名
// Sys_databackup databackup = null;
/**
* 构造方法
*/
public innerBackupClass(String user, String password, String url, String outFilePath,
// String outZipFilePath,
String filename,
String tableNames
// Sys_databackup databackup
) {
this.user = user;
this.password = password;
this.tableNames = tableNames;
this.url = url;
this.outFilePath = outFilePath;
// this.outZipFilePath = outZipFilePath;
this.filename = filename;
// this.databackup = databackup;
}
/**
* 线程执行入口
*/
public void run() {
Connection con = DBConnector.getconecttion(); // 取得一个数据库连接
Runtime rt = Runtime.getRuntime();
Process processexp = null;
checkCreatDir(outFilePath);
//这里拼装的是exp导出 当然还可以使用其它的 你懂得
String exp = "exp " + user + "/" + password + "@" + url + " file="
+ outFilePath + "/" + filename + ".dmp";
if(!"".equals(tableNames)){
exp += " tables=(" + tableNames + ")";
}
try {
processexp = rt.exec(exp);
new Thread(new StreamDrainer(processexp.getInputStream())).start();
new Thread(new StreamDrainer(processexp.getErrorStream())).start();
processexp.getOutputStream().close();
int exitValue = processexp.waitFor();
// databackup.setBackupstate("1"); //1为成功 0为失败
if(exitValue != 0){
// databackup.setBackupstate("0");
}
//将备份DMP文件压缩为zip
//删除dmp文件及所在的文件夹
//将备份的结果持久化
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
DBConnector.freecon(con); // 释放数据库连接
}
}
public void checkCreatDir(String dirPath) { // 目录是否存在
File file = new File(dirPath);
if (!file.exists()) {
file.mkdirs();
}
}
}
/**
*输出控制台信息
*/
class StreamDrainer implements Runnable {
private InputStream ins;
public StreamDrainer(InputStream ins) {
this.ins = ins;
}
public void run() {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(ins));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
最近下载更多
阿斯顿自行车在 LV1
2022年11月17日
503382513 LV12
2022年1月10日
lwp011 LV27
2020年7月6日
liuhuan8911 LV4
2019年11月20日
jaonsang LV25
2019年2月3日
weixh7 LV25
2018年11月6日
AAAAAABBBB LV1
2018年10月23日
masterY LV11
2018年9月8日
hellozui LV11
2018年7月18日
故事_sun LV26
2018年5月28日
最近浏览更多
lironggang LV38
2023年3月28日
uni-code_0123 LV1
2022年12月5日
阿斯顿自行车在 LV1
2022年11月17日
Dominick LV14
2022年11月17日
1358849392 LV21
2022年11月11日
liuziqi0529 LV4
2022年3月5日
503382513 LV12
2022年1月10日
xb1406112453 LV5
2021年2月28日
yuzhiyuan1977 LV2
2021年1月5日
dongzhan LV12
2020年12月9日

