脚本内容:
一、导出
1、库模式:整个数据库:
2、用户模式:
EXP CFG/CFG@ZQCREDIT BUFFER=64000 FILE=C:\CFG.DMP OWNER=CFG
3、表模式:
exp bsd/bsd@JSCREDIT_142 file=D:\数据文件备份\JSCREDIT_BSD_20151231_2.dmp log=D:\数据文件备份\JSCREDIT_BSD_20151231_2.log TABLES=(CORP_ATTEND_DETAIL,CORP_PRESON_FINGERIMG)
没有配置tns文件的方式:
exp bsd/bsd@IP/DBNAME file=D:\数据文件备份\JSCREDIT_BSD_20151231_2.dmp log=D:\数据文件备份\JSCREDIT_BSD_20151231_2.log TABLES=(CORP_ATTEND_DETAIL,CORP_PRESON_FINGERIMG)
限制数据行:
EXP name/pwd@MYDB FILE=D:\XXX.DMP LOG=D:\XXX.LOG TABLES=(DW_MDY_QYSPECIALCHECKINFO, DW_MDY_QYBADCREDITINFO) query=“‘where rownum<=100’”
二、导入
1.登录 linux
oracle su - oracle -c
2. 进入目录 /home/app/oracle/product/11.2.0/db_1/bin/ bin路径 执行
su -oracle -c "/home/app/oracle/product/11.2.0/db_1/bin/impdp 用户名/密码 director=DUMP1 dumpfile='文件路径' remap_schema=SBOD_WBEP:DATA_IMPORT remap_tablespace=SBOD_WBEP:DATA_IMPORT logfile='存储日志文件路径'"
imp导入模式 IMP NAME/PASWD@DBSHILIE FILE=D:path\DW.DMP BUFFER=64000 TABLES=(table1,table2)
码片段:
package com.tydic.cia.fileimport;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
public class RemoteShellTool {
private Connection conn;
private String ipAddr;
private String charset = “uft-8”;
private String userName;
private String password;
public RemoteShellTool(String ipAddr, String userName, String password, String charset) {
super();
this.ipAddr = ipAddr;
this.userName = userName;
this.password = password;
this.charset = charset;
}
public boolean login() throws IOException {
conn = new Connection(ipAddr);
conn.connect();
return conn.authenticateWithPassword(userName, password);
}
public String exec(String cmd) {
InputStream in = null;
String result = "";
try {
if (this.login()) {
Session sessoin = conn.openSession();
sessoin.execCommand(cmd);
in = sessoin.getStdout();
result = this.processStdout(in, this.charset);
if (result == null || "".equals(result.trim())) {
in = sessoin.getStderr();
result = this.processStdout(in, this.charset);
}
sessoin.close();
conn.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public String processStdout(InputStream in, String charset) {
byte[] buf = new byte[1024];
StringBuffer sb = new StringBuffer();
try {
while (in.read(buf) != -1) {
sb.append(new String(buf, charset));
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
/**
* @param args
*/
public static void main(String[] args) {
// RemoteShellTool tool = new RemoteShellTool("ip", "oracle", "oracle@clean", "utf-8");
RemoteShellTool tool = new RemoteShellTool("ip", "root", "@admin", "utf-8");
String cmd = "./myshell.sh";
cmd = "/home/oracle/myshell.sh";
long start = System.currentTimeMillis();
System.out.println(new Date());
String result = tool.exec(cmd);
System.out.println("tes....." + System.currentTimeMillis());
long end = System.currentTimeMillis();
System.out.println((end - start) + "ms");
System.out.println(result);
}
}
“`