exp是oracle提供的一个对数据库进行逻辑备份的客户端工具。利用这个工具可以将数据库按表空间、用户或某些表保存到操作系统下的一个二进制格式的文件里。这个二进制文件是平台无关的,也就是说可以将windows下的exp文件imp到linux/unix系统中,利用这个特性可以完成某些数据迁移工作。10g之前的版本没有data pump,数据导入导出的时候必须要exp/imp。
1 EXP的参数说明
在命令行中输入exp help=y或者exp -help即可显示exp命令的参数。
[oracle@book ~]$ exp -help
Export: Release 10.2.0.4.0 - Production on Sat Feb 9 19:39:58 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.
You can let Export prompt you for parameters by entering the EXP
command followed by your username/password:
Example: EXP SCOTT/TIGER
Or, you can control how Export runs by entering the EXP command followed
by various arguments. To specify parameters, you use keywords:
Format: EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
USERID must be the first parameter on the command line.
Keyword Description (Default) Keyword Description (Default)
--------------------------------------------------------------------------
USERID username/password FULL export entire file (N)
BUFFER size of data buffer OWNER list of owner usernames
FILE output files (EXPDAT.DMP) TABLES list of table names
COMPRESS import into one extent (Y) RECORDLENGTH length of IO record
GRANTS export grants (Y) INCTYPE incremental export type
INDEXES export indexes (Y) RECORD track incr. export (Y)
DIRECT direct path (N) TRIGGERS export triggers (Y)
LOG log file of screen output STATISTICS analyze objects (ESTIMATE)
ROWS export data rows (Y) PARFILE parameter filename
CONSISTENT cross-table consistency(N) CONSTRAINTS export constraints (Y)
OBJECT_CONSISTENT transaction set to read only during object export (N)
FEEDBACK display progress every x rows (0)
FILESIZE maximum size of each dump file
FLASHBACK_SCN SCN used to set session snapshot back to
FLASHBACK_TIME time used to get the SCN closest to the specified time
QUERY select clause used to export a subset of a table
RESUMABLE suspend when a space related error is encountered(N)
RESUMABLE_NAME text string used to identify resumable statement
RESUMABLE_TIMEOUT wait time for RESUMABLE
TTS_FULL_CHECK perform full or partial dependency check for TTS
VOLSIZE number of bytes to write to each tape volume
TABLESPACES list of tablespaces to export
TRANSPORT_TABLESPACE export transportable tablespace metadata (N)
TEMPLATE template name which invokes iAS mode export
Export terminated successfully without warnings.
在这里我们可以看到参数的说明和默认值。
有几个参数比较重要
USERID 必须要有这个参数,但是可以不用输入USERID。 exp userid=test/test ... 或者 exp test/oracle... 都可以
File 指定了导出文件的存储位置和存储文件名
Rows 指定导出时,是否包括表中的数据行,如果设置成N,则只导出表结构。
Compress
Compress参数不是设置对导出的内容进行压缩,而是指示exp如何控制create table中的storage语句。当compress设置为Y时,storage语句将包含一个和当前对象所占extent总和相当的一个初始extent(这个初始extent可能很大),这样在导入时所有数据将都在初始extent中。建议设置成N。
Filesize
在某些平台下文件的大小是有限制的,当导出的对象较大时就需要使用这个参数来指定文件的最大值。它必须配合FILE参数进行使用,file参数指定多个文件,当文件的值达到filesize时,exp自动转到下一个文件继续写。如
exp userid=test/test file=f1,f2,f3,f4,f5,。。。 filesize=2G
这样将创建f1.dmp, f2.dmp等一系列文件,每个大小都为2G,如果导出的总量小于10G,EXP不必创建f5.bmp。
Query
Exp通过该参数提供导出表中一部分数据的功能。利用query可以进行一些特殊操作,例如当我们需要导出一个非分区的大表时,可以使用query=where_clause 人为的将表分成几个不重叠部分进行并行导出,这样可以加快导出速度,再结合file,filesize还可以边exp边imp。
exp userid=jiang/oracle file=aa.dmp tables=aa QUERY=\"where rownum\<10\"