`
tianshibaijia
  • 浏览: 1128064 次
文章分类
社区版块
存档分类
最新评论

ORACLE EXP/IMP 说明

 
阅读更多

Oracle的导出导入是一个很常用的迁移工具。在Oracle 10g中,Oracle推出了数据泵(expdp/impdp).它可以通过使用并行,从而在效率上要比exp/imp要高。

在Oracle 10g和11g的官方文档里没有搜到有关exp/imp的说明,在9i里找到了相关的使用说明。连接如下:

Export

http://download.oracle.com/docs/cd/B10501_01/server.920/a96652/ch01.htm

Import

http://download.oracle.com/docs/cd/B10501_01/server.920/a96652/ch02.htm#SUTIL002

执行备份和恢复的时候,不要在客户端的shell窗口执行,要将备份的的进程添加到服务器的后台执行。

参考:

Linux前台和后台进程说明

http://blog.csdn.net/xujinyang/article/details/6962621

一.命令帮助如下:

1.1 export

[oracle@rac1 ~]$exp help=y

Export: Release 10.2.0.1.0 - Production on Tue May 10 10:35:26 2011

Copyright (c) 1982, 2005, 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.

KeywordDescription (Default)KeywordDescription (Default)

--------------------------------------------------------------------------

USERIDusername/passwordFULLexport entire file (N)

BUFFERsize of data bufferOWNERlist of owner usernames

FILEoutput files (EXPDAT.DMP)TABLESlist of table names

COMPRESSimport into one extent (Y) RECORDLENGTH length of IO record

GRANTSexport grants (Y)INCTYPEincremental export type

INDEXESexport indexes (Y)RECORDtrack incr. export (Y)

DIRECTdirect path (N)TRIGGERSexport triggers (Y)

LOGlog file of screen outputSTATISTICSanalyze objects (ESTIMATE)

ROWSexport data rows (Y)PARFILEparameter filename

CONSISTENT cross-table consistency(N) CONSTRAINTSexport constraints (Y)

OBJECT_CONSISTENTtransaction set to read only during object export (N)

FEEDBACKdisplay progress every x rows (0)

FILESIZEmaximum size of each dump file

FLASHBACK_SCNSCN used to set session snapshot back to

FLASHBACK_TIMEtime used to get the SCN closest to the specified time

QUERYselect clause used to export a subset of a table

RESUMABLEsuspend when a space related error is encountered(N)

RESUMABLE_NAMEtext string used to identify resumable statement

RESUMABLE_TIMEOUTwait time for RESUMABLE

TTS_FULL_CHECKperform full or partial dependency check for TTS

VOLSIZEnumber of bytes to write to each tape volume

TABLESPACESlist of tablespaces to export

TRANSPORT_TABLESPACE export transportable tablespace metadata (N)

TEMPLATEtemplate name which invokes iAS mode export

Export terminated successfully without warnings.

1.2 import

[oracle@rac1 ~]$ imp help=y

Import: Release 10.2.0.1.0 - Production on Tue May 10 10:35:49 2011

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

You can let Import prompt you for parameters by entering the IMP

command followed by your username/password:

Example: IMP SCOTT/TIGER

Or, you can control how Import runs by entering the IMP command followed

by various arguments. To specify parameters, you use keywords:

Format:IMP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)

Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N

or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

KeywordDescription (Default)KeywordDescription (Default)

--------------------------------------------------------------------------

USERIDusername/passwordFULLimport entire file (N)

BUFFERsize of data bufferFROMUSERlist of owner usernames

FILEinput files (EXPDAT.DMP)TOUSERlist of usernames

SHOWjust list file contents (N) TABLESlist of table names

IGNOREignore create errors (N)RECORDLENGTH length of IO record

GRANTSimport grants (Y)INCTYPEincremental import type

INDEXESimport indexes (Y)COMMITcommit array insert (N)

ROWSimport data rows (Y)PARFILEparameter filename

LOGlog file of screen outputCONSTRAINTSimport constraints (Y)

DESTROYoverwrite tablespace data file (N)

INDEXFILEwrite table/index info to specified file

SKIP_UNUSABLE_INDEXESskip maintenance of unusable indexes (N)

FEEDBACKdisplay progress every x rows(0)

TOID_NOVALIDATEskip validation of specified type ids

FILESIZEmaximum size of each dump file

STATISTICSimport precomputed statistics (always)

RESUMABLEsuspend when a space related error is encountered(N)

RESUMABLE_NAMEtext string used to identify resumable statement

RESUMABLE_TIMEOUTwait time for RESUMABLE

COMPILEcompile procedures, packages, and functions (Y)

STREAMS_CONFIGURATIONimport streams general metadata (Y)

STREAMS_INSTANTIATIONimport streams instantiation metadata (N)

VOLSIZEnumber of bytes in file on each volume of a file on tape

The following keywords only apply to transportable tablespaces

TRANSPORT_TABLESPACE import transportable tablespace metadata (N)

TABLESPACES tablespaces to be transported into database

DATAFILES datafiles to be transported into database

TTS_OWNERS users that own data in the transportable tablespace set

Import terminated successfully without warnings.

[oracle@rac1 ~]$

二.Export

1.表模式

备份某个用户模式下指定的对象(表)。业务数据库通常采用这种备份方式。若备份到本地文件,使用如下命令:

exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=exp.dmp log=exp.log tables=tab1,tab2,tab3

若直接备份到磁带设备,使用如下命令:

exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log tables=tab1,tab2,tab3

注:在磁盘空间允许的情况下,应先备份到本地服务器,然后再拷贝到磁带。出于速度方面的考虑,尽量不要直接备份到磁带设备。

2.用户模式

备份某个用户模式下的所有对象。业务数据库通常采用这种备份方式。若备份到本地文件,使用如下命令:

exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp.dmp log=exp.log

若直接备份到磁带设备,使用如下命令:

exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log

注:如果磁盘有空间,建议备份到磁盘,然后再拷贝到磁带。如果数据库数据量较小,可采用这种办法备份。

3.完全模式

备份完整的数据库。业务数据库不采用这种备份方式。备份命令为:

exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 full=yfile=exp_.dmp log=exp.log

三.IMPORT

import要与export对应。就是采用什么方式export,就需要采用什么方式import,因此import也有三种模式:表恢复、用户恢复、完全恢复。

1.表模式

此方式将根据按照表模式备份的数据进行恢复。

1.1恢复备份数据的全部内容

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log

若从磁带设备恢复,使用如下命令:

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 log=imp.log

1.2恢复备份数据中的指定表:

若从本地文件恢复,使用如下命令:

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log tables=t1,t2,t3

若从磁带设备恢复,使用如下命令:

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0

log=imp.log tables=t1,t2,t3

2.用户模式

此方式将根据按照用户模式备份的数据进行恢复。

2.1.恢复备份数据的全部内容

若从本地文件恢复,使用如下命令:

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log

若从磁带设备恢复,使用如下命令:

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 log=imp.log

2.2.恢复备份数据中的指定表

若从本地文件恢复,使用如下命令:

imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=exp.dmp log=imp.log tables=t1,t2,t3;

3.完全模式

如果备份方式为完全模式,采用下列恢复方法:

imp system/manager rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y volsize=0 full=y file=exp.dmp log=imp.log

4.参数说明

4.1. ignore参数

Oracle在恢复数据的过程中,当恢复某个表时,该表已经存在,就要根据ignore参数的设置来决定如何操作。

若ignore=y,Oracle不执行CREATE TABLE语句,直接将数据插入到表中,如果插入的记录违背了约束条件,比如主键约束,则出错的记录不会插入,但合法的记录会添加到表中。

若ignore=n,Oracle不执行CREATE TABLE语句,同时也不会将数据插入到表中,而是忽略该表的错误,继续恢复下一个表。­

4.2. indexes参数

在恢复数据的过程中,若indexes=n,则表上的索引不会被恢复,但是主键对应的唯一索引将无条件恢复,这是为了保证数据的完整性。

4.3字符集转换

对于单字节字符集(例如US7ASCII),恢复时,数据库自动转换为该会话的字符集(NLS_LANG参数);

对于多字节字符集(例如ZHS16CGB231280),恢复时,应尽量使字符集相同(避免转换),如果要转换,目标数据库的字符集应是输出数据库字符集的超集。

5.IMP常见问题及解决方法

5.1数据库对象已经存在

一般情况,导入数据前应该彻底删除目标数据下的表,序列,函数/过程,触发器等;数据库对象已经存在,按缺省的imp参数,则会导入失败如果用了参数ignore=y,会把exp文件内的数据内容导入如果表有唯一关键字的约束条件,不合条件将不被导入如果表没有唯一关键字的约束条件,将引起记录重复

5.2数据库对象有主外键约束

不符合主外键约束时,数据会导入失败,

解决办法:

先导入主表,再导入依存表

disable目标导入对象的主外键约束,导入数据后,再enable它们

5.3权限不够

如果要把A用户的数据导入B用户下, A用户需要有imp_full_database权限

5.4导入大表(大于80M )时,存储分配失败

默认的EXP时, compress = Y,也就是把所有的数据压缩在一个数据块上.

导入时,如果不存在连续一个大数据块,则会导入失败.导出80M以上的大表时,记得compress= N,则不会引起这种错误.

5.5imp和exp使用的字符集不同

如果字符集不同,导入会失败,可以改变unix环境变量或者NT注册表里NLS_LANG相关信息.导入完成后再改回来.

5.6imp和exp版本不能往上兼容

可以从低版本导入高版本,但不能从高版本导入到低版本。

如果遇到迁移因版本不同的问题,可以用低版本的export导出,到导入到低版本。

四.示例

4.1 oracle创建表空间,创建用户

//创建临时表空间

create temporary tablespace test_temp

tempfile ‘/u01/app/oracle/oradata/orcl/test_temp01.Dbf'

size 32m autoextend on next 32m maxsize 2048m

extent management local;

//创建数据表空间

create tablespace test_data logging

datafile '/u01/app/oracle/oradata/orcl/test_data01.dbf' ­

size 32m autoextend on

next 32m maxsize 2048m

extent management local;

//创建用户并指定表空间

create user username identified by password

default tablespace test_data

temporary tablespace test_temp;

//给用户授予权限­

grant connect,resource to username;

先创建一个用户和表空间,用户名david,密码david.在这个表空间下创建一个表:tianle。随便插入些数据。代码如下:

SQL> create tablespace test_data

3datafile '/u01/app/oracle/oradata/orcl/test_data01.dbf'

4size 5m;

Tablespace created.

SQL> create user david identified by david default tablespace test_data;

SQL> grant connect,resource to david;

SQL> conn david/david

SQL> create table tianle(id number, content varchar2(100));

SQL> set wrap off

SQL> column id format a20;

SQL> column content format a50;

4.2表模式备份与恢复

备份:

[oracle@roy orcl]$ exp david/david rows=y indexes=n compress=n buffer=65536 file=exp_tianle_090101.dmp log=exp_tianle_090101.log tables=(tianle);

恢复:

[oracle@roy orcl]$ imp david/david fromuser=david touser=david rows=y indexes=n commit=ybuffer=65536 file=exp_tianle_090101.dmp log=imp_tianle_090101.log tables=(tianle); ­

4.3用户模式备份与恢复

备份:

[oracle@roy orcl]$ exp david/david owner=david rows=y indexes=n compress=n buffer=65536 file=exp_david__090101.dmp log=exp_david_090101.log; ­

恢复:

[oracle@roy orcl]$ imp david/david fromuser=david touser=david rows=y indexes=n commit=y buffer=65536 file=exp_tianle_090101.dmp log=exp_tianle_090101.log; ­

4.4完全模式备份与恢复

备份:

[oracle@roy orcl]$ exp david/david rows=y indexes=n compress=n buffer=65536 full=y file=exp_fulldatabase_090101.dmp log=exp_fulldatabase_090101.log; ­

恢复

[oracle@roy orcl]$ imp david/david rows=y indexes=n commit=yfull=y ignore=y buffer=65536 file=/tmp/exp_fulldatabase_090101.dmp log=/tmp/imp.log;


-------------------------------------------------------------------------------------------------------

分享到:
评论

相关推荐

    Oracle中利用EXP/IMP工具实现数据迁移

    通过EXP/IMP可以实现产品系统的跨平台的迁移,需要迁移的数据库已经部署了高级复制环境,打算进行一系列的测试,测试包含高级复制环境数据库在通过 EXP/IMP工具迁移到新的环境中,复制环境是否生效。文中通过实例...

    Oracle数据库逻辑增量备份之exp/imp

    Oracle数据库逻辑增量备份之exp/imp 1 一、实现需求 1 二、逻辑备份恢复工具exp/imp 2 1、逻辑备份原理 2 2、exp语法和参数 2 3、imp语法和参数 3 三、exp逻辑备份 4 1、exp表模式备份 4 2、exp用户模式备份 5 3、...

    Oracle expimp,备份或导入时注意的事项

    Oracle exp/imp,备份或导入时注意的事项: 本篇主要讲述的是Oracle exp/imp备份导入的实际操作中需要注意的事项的介绍,凡事都不是完美的。不论哪种计算机语言,不论它的实际操作技巧是如何灵活,都是避免不掉它的...

    oracle exp imp详解

    导入/导出是ORACLE幸存的最古老的两个命令行工具,其实我从来不认为Exp/Imp是一种好的备份方式,正确的说法是Exp/Imp只能是一个好的转储工具,特别是在小型数据库的转储,表空间的迁移,表的抽取,检测逻辑和物理...

    oracle数据库exp_imp命令详解[参考].pdf

    oracle数据库exp_imp命令详解[参考].pdf

    exp/imp命令详解(实例)

    oracle数据库备份exp/imp命令详解(实例)

    exp/imp1oracle导入导出

    ............................

    EXP IMP详解

    导入/导出是ORACLE幸存的最古老的两个命令行工具,其实我从来不认为Exp/Imp是一种好的备份方式,正确的说法是Exp/Imp只能是一个好的转储工具,特别是在小型数据库的转储,表空间的迁移,表的抽取,检测逻辑和物理...

    oracleClient安装包exp和imp文件.zip

    Oracle客户端11.2.0.4.0的安装包,及其中exp和imp文件

    oracle命令 exp&imp命令详解

    oracle命令 导入和导出命令详解 exp和imp命令详解

    Oracle 管道 解决Exp/Imp大量数据处理问题

    Oracle的exp/imp是许多用户经常使用的两个工具. 它们常被用来做数据库的逻辑备份,数据库重组和数据转移等工作.

    Oracle中用exp_imp命令参数详解

    Oracle中用exp/imp命令参数详解 用 exp 数 据 导 出、用 imp 数 据 导 入

    oracle的expimp使用方法学习

    xp/imp两个命令可以说是oracle中最常用的命令了. ORACLE数据库有两类备份方法。第一类为物理备份,该方法实现数据库的完整恢复,但 数据库必须运行在归挡模式下(业务数据库在非归挡模式下运行),且需要极大的外部 ...

    ORACLE12c客户端含sqlplus、exp、imp等工具

    oracle版本绿色客户端(只收集了32位的,可在32、64下运行),并提供了相应的启动脚本,不需要任何配置,可随时随地拷贝使用。...本包提供windows下的32位绿色免安装、简易oracle客户端,含sqlplus、exp、imp等工具

    oracle exp-imp命令详解.doc

    oracle exp命令、imp命令,数据库应用导入,导出

    ORACLE的EXP和IMP

    oracle,exp,imp,备份

    oracle11G_64位的imp.exe及exp.exe BIN包

    oracle11g的bin包括imp.exe、exp.exe 64位亲测可用 oracle11g的bin包括imp.exe、exp.exe 64

    oracle imp/exp命令和举例

    oracle imp/exp命令,具体讲解了整库备份和还原,某几个表的备份和还原,有语法结构,有对应的实例。

    oracle9i的EXP和IMP

    oracle9i的EXP和IMP。方便只下载客户端精简版,但是又有导入导出需求的朋友。

    oracle_exp_imp详解

    导入/导出是ORACLE幸存的最古老的两个命令行工具,其实我从来不认为Exp/Imp是一种好的备份方式,正确的说法是Exp/Imp只能是一个好的转储工具,特别是在小型数据库的转储,表空间的迁移,表的抽取,检测逻辑和物理...

Global site tag (gtag.js) - Google Analytics