ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【EXPDP】使用EXPDP工具的 EXCLUDE选项过滤掉不关心的数据库对象

【EXPDP】使用EXPDP工具的 EXCLUDE选项过滤掉不关心的数据库对象

Linux操作系统 作者:season0891 时间:2016-03-02 22:08:11 0 删除 编辑
使用EXPDP逻辑备份工具的EXCLUDE选项可以指定那类数据库对象不被导出,EXPDP工具的前身EXP如果想要完成同样的任务非常的困难。我们以排除部分表为例看一下这个选项带给我们的便利。
如果在命令行中完成备份,特殊字符的转义需要特别注意(我这里使用的是Linux操作系统)。

1.EXPDP帮助中的描述信息
ora10g@secDB /expdp$ expdp -help
……
EXCLUDE   Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
……

2.创建directory数据库对象,并将读写权限授予sec用户
sys@ora10g> create or replace directory dump_dir as '/expdp';

Directory created.

sys@ora10g> grant read,write on directory dump_dir to sec;

Grant succeeded.

3.确认操作系统信息
ora10g@secDB /expdp$ uname -a
Linux secDB 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

4.在sec用户下创建几张表用于后续的测试
创建三张表T1、T2和T3,每张表中初始化一条数据
sec@ora10g> create table t1 (x int);
sec@ora10g> insert into t1 values (1);
sec@ora10g> create table t2 (x int);
sec@ora10g> insert into t2 values (2);
sec@ora10g> create table t3 (x int);
sec@ora10g> insert into t3 values (3);
sec@ora10g> commit;

5.为了与后面的比较,先全用户导出
ora10g@secDB /expdp$ rm -f sec.dmp sec.log
ora10g@secDB /expdp$ expdp sec/sec directory=dump_dir dumpfile=sec.dmp logfile=sec.log

Export: Release 10.2.0.3.0 - 64bit Production on Monday, 08 March, 2010 9:59:25

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=dump_dir dumpfile=sec.dmp logfile=sec.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 192 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
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
. . exported "SEC"."T1"                                  4.914 KB       1 rows
. . exported "SEC"."T2"                                  4.914 KB       1 rows
. . exported "SEC"."T3"                                  4.914 KB       1 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 09:59:32


6.排除T1表进行备份
ora10g@secDB /expdp$ rm -f sec.dmp sec.log
ora10g@secDB /expdp$ expdp sec/sec directory=dump_dir dumpfile=sec.dmp logfile=sec.log EXCLUDE=TABLE:\"IN\(\'T1\'\)\"

Export: Release 10.2.0.3.0 - 64bit Production on Monday, 08 March, 2010 10:02:03

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=dump_dir dumpfile=sec.dmp logfile=sec.log EXCLUDE=TABLE:"IN('T1')"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
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
. . exported "SEC"."T2"                                  4.914 KB       1 rows
. . exported "SEC"."T3"                                  4.914 KB       1 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:02:10

排除表T1后T2和T3表被成功导出。


7.排除多张表进行备份
以排除表T1和T2两张表为例进行演示
ora10g@secDB /expdp$ rm -f sec.dmp sec.log
ora10g@secDB /expdp$ expdp sec/sec directory=dump_dir dumpfile=sec.dmp logfile=sec.log EXCLUDE=TABLE:\"IN\(\'T1\',\'T2\'\)\"

Export: Release 10.2.0.3.0 - 64bit Production on Monday, 08 March, 2010 10:03:17

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=dump_dir dumpfile=sec.dmp logfile=sec.log EXCLUDE=TABLE:"IN('T1','T2')"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
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
. . exported "SEC"."T3"                                  4.914 KB       1 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:03:24


排除表T1和T2后T3表被成功导出。
注意在Linux的bash下特殊字符的转义处理

8.
使用PARFILE参数规避不同操作系统中特殊字符的转义
为了规避不同操作系统上特殊字符转义带来的麻烦,我们可以使用PARFILE参数规避一下这个难题
ora10g@secDB /expdp$ vi sec.par
userid=sec/sec
directory=dump_dir
dumpfile=sec.dmp
logfile=sec.log
EXCLUDE=TABLE:"IN('T1','T2')"
~
~

ora10g@secDB /expdp$ rm -f sec.dmp sec.log
ora10g@secDB /expdp$ expdp parfile=sec.par

Export: Release 10.2.0.3.0 - 64bit Production on Monday, 08 March, 2010 10:10:28

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  parfile=sec.par
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
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
. . exported "SEC"."T3"                                  4.914 KB       1 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:10:35


在完成特殊条件导出时,推荐将需要的所有参数统一写到参数文件中。

9.小结
EXPDP工具与EXP相比不仅仅是效率上的提升,更重要的是功能上的增强。
本文中以EXPDP的EXCLUDE选项为例展示了此工具的便捷之处,善用之。

Good luck.

secooler
10.03.08

-- The End --

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/90618/viewspace-2025775/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-06-10

  • 博文量
    791
  • 访问量
    1930523