关于impdp:将oracle RDS表数据下载到本地数据库

Downloading oracle RDS table data to a local database

我有一个Amazon Oracle RDS数据库。我想导出RDS表并将其导入我的本地数据库。更重要的是它包括一个NCLOB列。本地系统是运行Cygwin的Win10。

我运行expdp来捕获数据:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ expdp xlat@int_rds/*****tables=TEXT_POOL_XLAT file=int_TEXT_POOL_XLAT.expdp

Export: Release 11.2.0.1.0 - Production on Mon Feb 18 11:37:30 2019

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Legacy Mode Active due to the following parameters:
Legacy Mode Parameter:"file=int_TEXT_POOL_XLAT.expdp" Location: Command Line, Replaced with:"dumpfile=int_TEXT_POOL_XLAT.expdp"
Legacy Mode has set reuse_dumpfiles=true parameter.
Legacy Mode has set nologfile=true parameter.
Starting"XLAT"."SYS_EXPORT_TABLE_01":  xlat/********@int_rds tables=TEXT_POOL_XLAT dumpfile=int_TEXT_POOL_XLAT.expdp reuse_dumpfiles=true nologfile=true
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 51.68 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported"XLAT"."TEXT_POOL_XLAT"                     32.50 MB  137850 rows
Master table"XLAT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for XLAT.SYS_EXPORT_TABLE_01 is:
  /rdsdbdata/datapump/int_TEXT_POOL_XLAT.expdp
Job"XLAT"."SYS_EXPORT_TABLE_01" successfully completed at Mon Feb 18 17:37:29 2019 elapsed 0 00:00:04

到目前为止一切顺利。 expdp将文件转储到Or??acle DATA_PUMP_DIR中,我使用脚本通过sqlplus命令下载数据:

1
2
3
4
5
6
7
8
9
10
11
12
sqlplus -s $DBusername/$DBpassword@$database >/dev/null <<EOF
set colsep ,
set pagesize 0
set trimspool on
set headsep off
set linesize 8000
set termout off
SET FEEDBACK OFF
spool $filename $append
select * from table (rdsadmin.rds_file_util.read_text_file(p_directory => 'DATA_PUMP_DIR', p_filename  => '$DPfilename'));
quit
EOF

数据已下载。但是当我运行impdp时,我得到:

1
2
3
4
5
6
7
8
9
10
11
$ impdp xlat/f0nature1931@local tables=TEXT_POOL_XLAT dumpfile=int_TEXT_POOL_XLAT.expdp directory='DATA_PUMP_DIR'

Import: Release 11.2.0.1.0 - Production on Mon Feb 18 11:58:32 2019

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31619: invalid dump file"C:\\app\\waynej/admin/orcl/dpdump/int_TEXT_POOL_XLAT.expdp"

我错过了什么吗?我认为这不是CR / LF问题,因为脚本下载时没有任何翻译。

预先感谢。


RDS过程rdsadmin.rds_file_util.read_text_file仅读取文本文件。
EXPDP DUMP文件不是文本文件,而是二进制文件。

禁止RDS实例的文件访问。仅通过db_link访问DATA_PUMP_DIR目录,并使用DBMS_FILE_TRANSFER包。

  • 在RDS数据库和您的本地计算机之间的RDS实例上创建数据库链接
    甲骨文。
  • 将转储文件从RDS实例复制到本地Oracle DB使用
    通过数据库链接的DBMS_FILE_TRANSFER.PUT_FILE
  • 将转储文件导入本地数据库
    impdp xlat/f0nature1931@local tables=TEXT_POOL_XLAT dumpfile=int_TEXT_POOL_XLAT.expdp directory='DATA_PUMP_DIR'
  • 如果您没有机会在本地数据库和RDS Oracle之间建立链接,则可以通过两种其他方式导出数据。

    1
    您可以使用本地PC上的旧exp实用程序导出数据,该实用程序还会创建导出文件.dmp,但格式不同。该格式与impdp expdp不兼容。 exp imp实用程序可以通过SQL * NET网络作为客户端服务器连接到目标数据库。该实用程序已过时,性能较低。像在运行实用程序expdp时一样,不会在服务器上创建dmp文件。 dmp文件写在运行实用程序exp的一侧(服务器或客户端)

    1
    $ORACLE_HOME/bin/exp parfile=parfile_exp_full FILE=export.dmp LOG=export.log

    然后使用imp将数据导入本地Oracle实例。

    1
    $ORACLE_HOME/bin/imp parfile=parfile_imp_full FILE=export.dmp LOG=import.log

    2

    您可以使用sqlplus

    将数据导出到CSV文件。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    $ORACLE_HOME/bin/sqlplus -s user/pass@rds_amazon  @csv2.sql.

    more csv2.sql

    set heading off
    set termout OFF
    SET FEEDBACK OFF
    SET TAB OFF
    set pause off
    set verify off
    SET UNDERLINE OFF
    set trimspool on
    set echo off
    set linesize 1000
    set pagesize 0
    set wrap off
    spool test2.csv
    select code||','||name||','||code_rail from alexs.all_station;
    spool off
    exit;

    然后使用实用程序sqlldr或SQL Developer将数据导入到本地Oracle实例。

    用于从Excel导入的SQL Developer