通过shell解析dump生成parfile(r2笔记76天)

时间:2022-05-04
本文章向大家介绍通过shell解析dump生成parfile(r2笔记76天),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

当我们得到一个dump文件的时候,总是有些不太确定dump文件中是否含有一些我们原本不希望出现的表,如果在未知的情况下对dump文件进行操作时很危险的,比如我们想要得到的是表结构的信息。如果不指定需要的表,会把当前schema下所有的Object对象的信息都导出。一般的操作中,建议还是使用parfile。

[ora11g@rac1 dbm_lite]$ exp n1/n1 file=n1_ddl.dmp rows=n statistics=none Export: Release 11.2.0.3.0 - Production on Tue Aug 26 07:21:57 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in US7ASCII character set and AL16UTF16 NCHAR character set server uses AL32UTF8 character set (possible charset conversion) Note: table data (rows) will not be exported

About to export specified users ... . exporting pre-schema procedural objects and actions . exporting foreign function library names for user N1 . exporting PUBLIC type synonyms . exporting private type synonyms . exporting object type definitions for user N1 About to export N1's objects ... . exporting database links . exporting sequence numbers . exporting cluster definitions . about to export N1's tables via Conventional Path ... . . exporting table BIG_INSERT . . exporting table BIG_INSERT_EXT2 . . exporting table CLOB_TEST . . exporting table CLOB_TEST_EXT2 . . exporting table DATA . . exporting table NEW_DATA . . exporting table OLD_DATA . . exporting table PAR_DATA . . exporting table RATED_EVENT . . exporting table SMALL_INSERT . . exporting table SMALL_INSERT_EXT2 . . exporting table T . . exporting table T1 . . exporting table T2 . . exporting table TEMP_TEST . . exporting table TEMP_TEST_EXT2 . . exporting table TEST . . exporting table TEST_DATA . . exporting table TEST_DATA_EXT2 . . exporting table TEST_EXT2 . . exporting table TT . . exporting table TTT . . exporting table TT_EXT2 . . exporting table T_EXT2 . . exporting table T_TEMP . . exporting table T_TEMP_EXT2 . . exporting table WIN_LIST . exporting synonyms . exporting views . exporting stored procedures . exporting operators . exporting referential integrity constraints . exporting triggers . exporting indextypes . exporting bitmap, functional and extensible indexes . exporting posttables actions . exporting materialized views . exporting snapshot logs . exporting job queues . exporting refresh groups and children . exporting dimensions . exporting post-schema procedural objects and actions . exporting statistics Export terminated successfully without warnings. 但是很多时候我们都因为是dump文件,感觉一下子没有了方向。无从查起。 如果我们能够得到dump文件中的table列表,那就太好了,我们可以很安全的进行数据的操作。不会稀里糊涂的把一些“未知”操作避免。 如果要解析dump文件,之前分享过一篇日志,通过awk来解析dump文件,得到对应的sql语句,现在来通过一些简单的命令解析dump文件。 我简单测试过百兆,数十G的dump文件,这个命令的速度都还可以, 首先,我们得到一个比较粗略的table list [ora11g@rac1 dbm_lite]$ strings n1_ddl.dmp|grep "CREATE TABLE"|awk '{print $3}' "BIG_INSERT" "CLOB_TEST" "DATA" "NEW_DATA" "OLD_DATA" "PAR_DATA" "RATED_EVENT" "SMALL_INSERT" "T" "T1" "T2" "TEMP_TEST" "TEST" "TEST_DATA" "TT" "TTT" "T_TEMP" "WIN_LIST" 得到的内容如上所示,我们需要去除双引号,然后加入tables=,每行末尾加入一个逗号。 先去掉双引号 [ora11g@rac1 dbm_lite]$ strings n1_ddl.dmp|grep "CREATE TABLE"|awk '{print $3}'|sed 's/"//g' BIG_INSERT CLOB_TEST DATA NEW_DATA OLD_DATA PAR_DATA RATED_EVENT SMALL_INSERT T T1 T2 TEMP_TEST TEST TEST_DATA TT TTT T_TEMP WIN_LIST 然后再次判断,如果是第一行就加入前缀tables=,否则加入前缀一个逗号,这样就不用麻烦的判断最后一行的逗号是不是要加了。 [ora11g@rac1 dbm_lite]$ strings n1_ddl.dmp|grep "CREATE TABLE"|awk '{print $3}'|sed 's/"//g'|awk '{ if(FNR==1) print "tables="$1 ; else print ","$1}' tables=BIG_INSERT ,CLOB_TEST ,DATA ,NEW_DATA ,OLD_DATA ,PAR_DATA ,RATED_EVENT ,SMALL_INSERT ,T ,T1 ,T2 ,TEMP_TEST ,TEST ,TEST_DATA ,TT ,TTT ,T_TEMP ,WIN_LIST 简单验证一下,可以看到导出的信息很“干净”,我们在数据导入的时候也可以做类似的操作。 [ora11g@rac1 dbm_lite]$ exp n1/n1 file=a.dmp parfile=a.par rows=n statistics=none Export: Release 11.2.0.3.0 - Production on Tue Aug 26 07:34:19 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in US7ASCII character set and AL16UTF16 NCHAR character set server uses AL32UTF8 character set (possible charset conversion) Note: table data (rows) will not be exported About to export specified tables via Conventional Path ... . . exporting table BIG_INSERT . . exporting table CLOB_TEST . . exporting table DATA . . exporting table NEW_DATA . . exporting table OLD_DATA . . exporting table PAR_DATA . . exporting table RATED_EVENT . . exporting table SMALL_INSERT . . exporting table T . . exporting table T1 . . exporting table T2 . . exporting table TEMP_TEST . . exporting table TEST . . exporting table TEST_DATA . . exporting table TT . . exporting table TTT . . exporting table T_TEMP . . exporting table WIN_LIST Export terminated successfully without warnings.