290112011 发表于 2018-9-23 11:14:18

【Oracle expdp 排除表参数】

  【Oracle expdp 排除表参数】
  使用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:>  Copyright (c) 2003, 2005, Oracle.All rights reserved.

  Connected to: Oracle Database 10g Enterprise Edition>  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:>  Copyright (c) 2003, 2005, Oracle.All rights reserved.

  Connected to: Oracle Database 10g Enterprise Edition>  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:>  Copyright (c) 2003, 2005, Oracle.All rights reserved.

  Connected to: Oracle Database 10g Enterprise Edition>  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:>  Copyright (c) 2003, 2005, Oracle.All rights reserved.

  Connected to: Oracle Database 10g Enterprise Edition>  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 --

页: [1]
查看完整版本: 【Oracle expdp 排除表参数】