Oracle-32-数据泵

数据泵是在数据库中以段为单位移动数据的一种手段,是一种数据迁移的工具。它是以备PLSQL的形式,查询出备份结果后进行备份的,因此无法使用归档日志对备份的数据进行前滚操作的。

首先我们先创建备份时存放临时数据的目录

SYS@ orcl>!mkdir /home/oracle/bak

创建逻辑目录(物理目录的别名)

SYS@ orcl>create or replace directory expbak as '/home/oracle/bak';

Directory created.

Elapsed: 00:00:00.03

查看逻辑目录

SYS@ orcl>select * from dba_directories;

OWNER    DIRECTORY_NAME         DIRECTORY_PATH
-------- ---------------------- ----------------------------------------------------------------------
SYS      ORACLE_OCM_CONFIG_DIR  /u01/app/oracle/product/11.2.0/db_1/ccr/state
SYS      DATA_PUMP_DIR          /u01/app/oracle/admin/orcl/dpdump/
SYS      MEDIA_DIR              /u01/app/oracle/product/11.2.0/db_1/demo/schema/product_media/
SYS      XMLDIR                 /ade/b/2125410156/oracle/rdbms/xml
SYS      DATA_FILE_DIR          /u01/app/oracle/product/11.2.0/db_1/demo/schema/sales_history/
SYS      LOG_FILE_DIR           /u01/app/oracle/product/11.2.0/db_1/demo/schema/log/
SYS      SS_OE_XMLDIR           /u01/app/oracle/product/11.2.0/db_1/demo/schema/order_entry/
SYS      SUBDIR                 /u01/app/oracle/product/11.2.0/db_1/demo/schema/order_entry//2002/Sep
SYS      EXPBAK                 /home/oracle/bak

9 rows selected.

Elapsed: 00:00:00.01

授予SCOTT用户读写逻辑目录的权限

SYS@ orcl>grant read,write on directory expbak to scott;

Grant succeeded.

Elapsed: 00:00:00.02

数据泵导出

创建测试表

SCOTT@ orcl>create table test as select * from all_objects;

Table created.

Elapsed: 00:00:02.07

为了方便备份,在物理路径下创建数据泵文件,这里我们只导出对象定义(表结构)

[oracle@RHEL6 bak]$ vi expbak.txt

userid=scott/scott
directory=expbak
dumpfile=exp_test.dmp
logfile=exp_test.log
job_name=exp_test
tables=test
content=metadata_only

执行脚本

sqlplus / as sysdba
SYS@ orcl>execute sys.dbms_metadata_util.load_stylesheets;

PL/SQL procedure successfully completed.

Elapsed: 00:00:02.42

执行数据泵

[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 13:54:27 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."EXP_TEST":  scott/******** parfile=/home/oracle/bak/expbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE
Master table "SCOTT"."EXP_TEST" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_TEST is:
  /home/oracle/bak/exp_test.dmp
Job "SCOTT"."EXP_TEST" successfully completed at 13:54:33

修改参数文件,导出数据

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=scott/scott
directory=expbak
dumpfile=exp_test_data.dmp
logfile=exp_test_data.log
job_name=exp_test
tables=test
content=data_only
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"expbak.txt" 7L, 137C written  
[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 14:02:58 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."EXP_TEST":  scott/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 7 MB
. . exported "SCOTT"."TEST"                              5.451 MB   55639 rows
Master table "SCOTT"."EXP_TEST" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_TEST is:
  /home/oracle/bak/exp_test_data.dmp
Job "SCOTT"."EXP_TEST" successfully completed at 14:03:01

修改配置文件,导出所有数据

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=scott/scott
directory=expbak
dumpfile=exp_test_all.dmp
logfile=exp_test_all.log
job_name=exp_test
tables=test
content=all
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"expbak.txt" 7L, 129C written 
[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 14:04:54 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."EXP_TEST":  scott/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 7 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."TEST"                              5.451 MB   55639 rows
Master table "SCOTT"."EXP_TEST" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_TEST is:
  /home/oracle/bak/exp_test_all.dmp
Job "SCOTT"."EXP_TEST" successfully completed at 14:05:00
[oracle@RHEL6 bak]$ ll -tr
total 11440
-rw-r-----. 1 oracle asmadmin   94208 Jul 24 13:54 exp_test.dmp
-rw-r--r--. 1 oracle asmadmin     753 Jul 24 13:54 exp_test.log
-rw-r-----. 1 oracle asmadmin 5791744 Jul 24 14:03 exp_test_data.dmp
-rw-r--r--. 1 oracle asmadmin     929 Jul 24 14:03 exp_test_data.log
-rw-r--r--. 1 oracle oinstall     129 Jul 24 14:04 expbak.txt
-rw-r-----. 1 oracle asmadmin 5812224 Jul 24 14:05 exp_test_all.dmp
-rw-r--r--. 1 oracle asmadmin     976 Jul 24 14:05 exp_test_all.log

我们也可以一次备份多张表

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=scott/scott
directory=expbak
dumpfile=exp_test_1.dmp
logfile=exp_test_1.log
job_name=exp_1
tables=emp,dept
query=dept:"where deptno<>40",emp:"where deptno=30"
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"expbak.txt" 7L, 126C written  

由于默认情况下,备份全量数据,因此我们取消content=all参数

[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 15:53:15 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."EXP_1":  scott/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."DEPT"                              5.914 KB       3 rows
. . exported "SCOTT"."EMP"                               8.257 KB       6 rows
Master table "SCOTT"."EXP_1" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_1 is:
  /home/oracle/bak/exp_test_1.dmp
Job "SCOTT"."EXP_1" successfully completed at 15:53:24

也可以备份用户模式

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=scott/scott
directory=expbak
dumpfile=exp_scott.dmp
logfile=exp_scott.log
job_name=exp_scott
schemas=scott
parallel=8
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"expbak.txt" 6L, 114C written 

 其中parallel=8启用并行模式,可以增加导出的速度

[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 15:58:07 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."EXP_SCOTT":  scott/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 7.187 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."TEST"                              5.451 MB   55639 rows
. . exported "SCOTT"."DEPT"                              5.937 KB       4 rows
. . exported "SCOTT"."EMP"                               8.570 KB      14 rows
. . exported "SCOTT"."SALGRADE"                          5.867 KB       5 rows
. . exported "SCOTT"."BONUS"                                 0 KB       0 rows
Master table "SCOTT"."EXP_SCOTT" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_SCOTT is:
  /home/oracle/bak/exp_scott.dmp
Job "SCOTT"."EXP_SCOTT" successfully completed at 15:58:37

也可以导出整个表空间

[oracle@RHEL6 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jul 24 16:09:04 2018

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SYS@ orcl>

查看数据库表空间情况、

SYS@ orcl>select name from v$tablespace;

NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
EXAMPLE

6 rows selected.

Elapsed: 00:00:00.02
SYS@ orcl>select owner,table_name from dba_tables where tablespace_name='USERS';

OWNER                          TABLE_NAME
------------------------------ ------------------------------
SCOTT                          DEPT
SCOTT                          EMP
SCOTT                          BONUS
SCOTT                          SALGRADE
SCOTT                          TEST
OE                             PRODUCT_REF_LIST_NESTEDTAB
OE                             SUBCATEGORY_REF_LIST_NESTEDTAB
SH                             DIMENSION_EXCEPTIONS
ORACLE                         EMP
ORACLE                         BONUS
ORACLE                         DEPT
ORACLE                         SALGRADE
ORACLE                         A_YD_TEMP
ORACLE                         A_LT_TEMP
ORACLE                         A_DX_TEMP

15 rows selected.

Elapsed: 00:00:00.05

修改配置文件

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=system/sys
directory=expbak
dumpfile=exp_users.dmp
logfile=exp_users.log
job_name=exp_users
tablespaces=users
parallel=8
~
"expbak.txt" 7L, 128C written    
[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 16:18:48 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SYSTEM"."EXP_USERS":  system/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 8.125 MB
. . exported "SCOTT"."TEST"                              5.451 MB   55639 rows
. . exported "OE"."CATEGORIES_TAB"                       14.15 KB      22 rows
. . exported "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB"       6.585 KB      21 rows
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "OE"."PRODUCT_REF_LIST_NESTEDTAB"           12.50 KB     288 rows
. . exported "ORACLE"."DEPT"                             5.937 KB       4 rows
. . exported "ORACLE"."EMP"                              8.578 KB      15 rows
. . exported "ORACLE"."SALGRADE"                         5.867 KB       5 rows
. . exported "SCOTT"."DEPT"                              5.937 KB       4 rows
. . exported "SCOTT"."EMP"                               8.570 KB      14 rows
. . exported "SCOTT"."SALGRADE"                          5.867 KB       5 rows
. . exported "ORACLE"."A_DX_TEMP"                            0 KB       0 rows
. . exported "ORACLE"."A_LT_TEMP"                            0 KB       0 rows
. . exported "ORACLE"."A_YD_TEMP"                            0 KB       0 rows
. . exported "ORACLE"."BONUS"                                0 KB       0 rows
. . exported "SCOTT"."BONUS"                                 0 KB       0 rows
. . exported "SH"."DIMENSION_EXCEPTIONS"                     0 KB       0 rows
. . exported "OE"."PURCHASEORDER"                        243.9 KB     132 rows
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Master table "SYSTEM"."EXP_USERS" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.EXP_USERS is:
  /home/oracle/bak/exp_users.dmp
Job "SYSTEM"."EXP_USERS" successfully completed at 16:19:14

我们对全库进行备份

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=system/sys
directory=expbak
dumpfile=exp_full.dmp
logfile=exp_full.log
job_name=exp_full
full=y
parallel=8
~
~
~

这里由于日志过长就不放上来了

下面我们看一下数据泵特有的功能:模糊匹配表名

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=scott/scott
directory=expbak
dumpfile=exp_table.dmp
logfile=exp_table.log
job_name=exp_table
include=table:"like 'E%'"
parallel=8
~
~
~
[oracle@RHEL6 bak]$ expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 16:32:25 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."EXP_TABLE":  scott/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
. . exported "SCOTT"."EMP"                               8.570 KB      14 rows
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Master table "SCOTT"."EXP_TABLE" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.EXP_TABLE is:
  /home/oracle/bak/exp_table.dmp
Job "SCOTT"."EXP_TABLE" successfully completed at 16:32:37

数据泵导入

编写参数文件

[oracle@RHEL6 bak]$ vi impbak.txt

userid=scott/scott
directory=expbak
dumpfile=exp_test.dmp
logfile=imp_test.dmp

删除原先SCOTT用户下的表

[oracle@RHEL6 ~]$ sqlplus scott/scott

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jul 24 16:42:08 2018

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SCOTT@ orcl>drop table test purge;

Table dropped.

Elapsed: 00:00:00.06

进行数据导入

[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 16:44:09 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_FULL_01":  scott/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE
Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at 16:44:12

查询表是否导入成功

SCOTT@ orcl>select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BONUS                          TABLE
DEPT                           TABLE
EMP                            TABLE
SALGRADE                       TABLE
TEST                           TABLE

Elapsed: 00:00:00.02
SCOTT@ orcl>select * from test;

no rows selected

Elapsed: 00:00:00.00

由于之前备份的是元数据(表结构),因此表里面的内容是空的

我们导入数据

[oracle@RHEL6 bak]$ vi impbak.txt

userid=scott/scott
directory=expbak
dumpfile=exp_test_data.dmp
logfile=imp_test_data.dmp

~
~
~
[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 17:00:41 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_FULL_01":  scott/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST"                              5.451 MB   55639 rows
Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at 17:00:45

查看数据是否已经导入

SCOTT@ orcl>select count(1) from test;

  COUNT(1)
----------
     55639

Elapsed: 00:00:00.20

修改参数文件,让导入可以追加数据

[oracle@RHEL6 bak]$ vi impbak.txt

userid=scott/scott
directory=expbak
dumpfile=exp_test_data.dmp
logfile=imp_test_data.dmp
table_exists_action=append
~
~

再次导入,看看是否成功

[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 17:05:41 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_FULL_01":  scott/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST"                              5.451 MB   55639 rows
Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at 17:05:45
SCOTT@ orcl>select count(1) from test;

  COUNT(1)
----------
    111278

Elapsed: 00:00:00.17

也可以将表导入后重新命名

[oracle@RHEL6 bak]$ vi impbak.txt

userid=scott/scott
directory=expbak
dumpfile=exp_test_all.dmp
logfile=imp_test_all.dmp
remap_table=test:test1
~
~
[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 17:12:18 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_FULL_02" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_FULL_02":  scott/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST1"                             5.451 MB   55639 rows
Job "SCOTT"."SYS_IMPORT_FULL_02" successfully completed at 17:12:22
SCOTT@ orcl>select count(1) from test1;

  COUNT(1)
----------
     55639

Elapsed: 00:00:00.19

在导入时也可以更改表空间信息

查看表及所在表空间信息

SCOTT@ orcl>select table_name,tablespace_name from tabs;

TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
TEST1                          USERS
SYS_IMPORT_FULL_01             USERS
TEST                           USERS
SALGRADE                       USERS
BONUS                          USERS
EMP                            USERS
DEPT                           USERS

7 rows selected.

Elapsed: 00:00:00.09
oracle@RHEL6 bak]$ vi impbak.txt 

userid=scott/scott
directory=expbak
dumpfile=exp_test_all.dmp
logfile=imp_test_all.log
remap_tablespace=users:test
remap_table=test:test1

查看表空间信息

SYS@ orcl>select name from v$tablespace;

NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
EXAMPLE

6 rows selected.

Elapsed: 00:00:00.02

创建新的表空间

SYS@ orcl>create tablespace test datafile '/home/oracle/test.dbf' size 10M;

Tablespace created.

Elapsed: 00:00:00.33
SYS@ orcl>select name from v$tablespace;

NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
EXAMPLE
TEST

7 rows selected.

Elapsed: 00:00:00.01

导入数据

[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 18:19:12 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_FULL_01":  scott/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST1"                             5.451 MB   55639 rows
Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at 18:19:16

下面我们跨用户导入(需要使用管理员账号)

[oracle@RHEL6 bak]$ vi impbak.txt 

userid=system/sys
directory=expbak
dumpfile=exp_test_all.dmp
logfile=imp_test_all.log
remap_table=test:test1
remap_schema=scott:oracle
~
[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 18:25:46 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "ORACLE"."TEST1"                            5.451 MB   55639 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 18:25:49
ORACLE@ orcl>select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
A_DX_TEMP                      TABLE
A_LT_TEMP                      TABLE
A_YD_TEMP                      TABLE
BONUS                          TABLE
DEPT                           TABLE
EMP                            TABLE
SALGRADE                       TABLE
TEST                           TABLE
TEST1                          TABLE

9 rows selected.

Elapsed: 00:00:00.01

我们将用户导入数据库

ORACLE@ orcl>conn scott/scott
Connected.
SCOTT@ orcl>select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BIN$cbzuDG70J+rgUAB/AQAUug==$0 TABLE
BONUS                          TABLE
CLASSES                        TABLE
DEPT                           TABLE
EMP                            TABLE
SALGRADE                       TABLE
TEST                           TABLE
TEST1                          TABLE

8 rows selected.

Elapsed: 00:00:00.01
SCOTT@ orcl> conn / as sysdba
Connected.
SYS@ orcl>drop user scott cascade;

User dropped.

Elapsed: 00:00:02.01
SYS@ orcl>grant connect,resource to scott identified by tiger;

Grant succeeded.

Elapsed: 00:00:00.03
SYS@ orcl>conn scott/tiger
Connected.
SCOTT@ orcl>select * from tab;

no rows selected

Elapsed: 00:00:00.02
oracle@RHEL6 bak]$ vi impbak.txt 

userid=system/sys
directory=expbak
dumpfile=exp_scott.dmp
logfile=imp_scott.log
[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 18:33:36 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST"                              5.451 MB   55639 rows
. . imported "SCOTT"."DEPT"                              5.937 KB       4 rows
. . imported "SCOTT"."EMP"                               8.570 KB      14 rows
. . imported "SCOTT"."SALGRADE"                          5.867 KB       5 rows
. . imported "SCOTT"."BONUS"                                 0 KB       0 rows
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 18:33:41
SCOTT@ orcl>select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BONUS                          TABLE
DEPT                           TABLE
EMP                            TABLE
SALGRADE                       TABLE
TEST                           TABLE

Elapsed: 00:00:00.01

表空间还原

我们先备份TEST表空间

[oracle@RHEL6 bak]$ vi expbak.txt 

userid=scott/tiger
directory=expbak
dumpfile=exp_test.dmp
logfile=exp_test.log
job_name=exp_table
tablespaces=test
parallel=8
SYS@ orcl>create table scott.e1 tablespace test as select * from scott.emp;

Table created.

Elapsed: 00:00:00.08
SYS@ orcl>select owner,table_name from dba_tables where tablespace_name='TEST';

OWNER                          TABLE_NAME
------------------------------ ------------------------------
SCOTT                          E1

Elapsed: 00:00:00.06
[oracle@RHEL6 bak]$expdp parfile=/home/oracle/bak/expbak.txt

Export: Release 11.2.0.1.0 - Production on Tue Jul 24 18:45:38 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SYSTEM"."EXP_TABLE":  system/******** parfile=/home/oracle/bak/expbak.txt 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
. . exported "SCOTT"."E1"                                8.562 KB      14 rows
Processing object type TABLE_EXPORT/TABLE/TABLE
Master table "SYSTEM"."EXP_TABLE" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.EXP_TABLE is:
  /home/oracle/bak/exp_test_tablespace.dmp
Job "SYSTEM"."EXP_TABLE" successfully completed at 18:45:45

[oracle@RHEL6 bak]$ 
SYS@ orcl>drop tablespace test including contents;

Tablespace dropped.

Elapsed: 00:00:00.42
SYS@ orcl>create tablespace test datafile size 10M;

Tablespace created.

Elapsed: 00:00:00.47
SYS@ orcl>select owner,table_name from dba_tables where tablespace_name='TEST';

no rows selected

Elapsed: 00:00:00.04
[oracle@RHEL6 bak]$ vi impbak.txt 

userid=system/sys
directory=expbak
dumpfile=exp_test_tablespace.dmp
logfile=imp_scott.log
~
[oracle@RHEL6 bak]$ impdp parfile=/home/oracle/bak/impbak.txt

Import: Release 11.2.0.1.0 - Production on Tue Jul 24 18:49:32 2018

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** parfile=/home/oracle/bak/impbak.txt 
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."E1"                                8.562 KB      14 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 18:49:36
SYS@ orcl>select owner,table_name from dba_tables where tablespace_name='TEST';

OWNER                          TABLE_NAME
------------------------------ ------------------------------
SCOTT                          E1

Elapsed: 00:00:00.04

猜你喜欢

转载自blog.csdn.net/Paul_George/article/details/81183091