java调用shell脚本执行impdp命令

博客介绍了数据库导出和导入的脚本内容。导出包括库模式、用户模式、表模式,还提及无tns文件方式及限制数据行的导出。导入需登录linux,进入指定目录执行导入命令,同时给出了一段Java代码片段用于远程shell操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

脚本内容:

一、导出

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

}
“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值