oracle expdp impdp 自动创建directory的一键导入导出批处理脚本

导入脚本

@echo off
pushd %~dp0
if exist tempdir rd tempdir
if exist start.sql del start.sql
if exist drop.sql del drop.sql
md tempdir
set td=%cd%\tempdir
set tn=tempdir%random%
echo create directory %tn% as '%td%' >> start.sql;
echo grant read,write on directory %tn% to public>> start.sql;
echo drop directory %tn% > drop.sql
if exist dmpenv.bat call dmpenv.bat
sqlplus / as sysdba < start.sql
impdp oa1/oa1@orcl  directory=%tn% remap_schema="oa1:oa2" table_exists_action=replace dumpfile=import.dmp full=y
sqlplus / as sysdba < drop.sql
del start.sql
del drop.sql
rem del dmpenv.bat
cmd

上述导入脚本在实际应用的时候 不需要再去创建对应的数据库的Directory,只需要修改上面 impdp部分的命令 并且将需要导入的dmp文件重命名为import.dmp并且在上述脚本的同目录下新建tempdir目录并将import.dmp放在tempdir目录之下即可。

导出脚本

@echo off
pushd %~dp0
if exist tempdir rd tempdir
if exist start.sql del start.sql
if exist drop.sql del drop.sql
md tempdir
set td=%cd%\tempdir
set tn=tempdir%random%
echo create directory %tn% as '%td%' >> start.sql;
echo grant read,write on directory %tn% to public>> start.sql;
echo drop directory %tn% > drop.sql
sqlplus / as sysdba < start.sql
expdp oa1/oa1@orcl schemas=oa1 directory=%tn% dumpfile=export.dmp
sqlplus / as sysdba < drop.sql
del start.sql
del drop.sql
cmd

上述导出脚本只需要修改expdp部分的命令并另存为bat或者cmd后缀的脚本运行即可 不需要再去创建对应的数据库的Directory,脚本运行完成之后 导出的export.dmp文件位于脚本文件同目录下的tempdir目录下面

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天水麒麟姜伯约

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值