Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182528
  • 博文数量: 21
  • 博客积分: 436
  • 博客等级: 下士
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-29 10:02
文章分类

全部博文(21)

文章存档

2017年(1)

2016年(1)

2014年(2)

2012年(9)

2011年(7)

2010年(1)

分类:

2012-01-18 11:47:08

原文地址:ORACLE EXP/IMP 说明 作者:zzjlzx

ORACLE EXP/IMP 说明
分类: Oracle 基础知识 Oracle 备份与恢复 4082人阅读 评论(6) 举报

 

 

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

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

 

Export

 

 

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

 

参考:

       Linux 前台 后台进程 说明

       http://blog.csdn.net/tianlesoftware/archive/2011/01/27/6165753.aspx

 

. 命令帮助如下:

 

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.

 

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.

 

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.

 

Keyword  Description (Default)       Keyword      Description (Default)

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

USERID   username/password           FULL         import entire file (N)

BUFFER   size of data buffer         FROMUSER     list of owner usernames

FILE     input files (EXPDAT.DMP)    TOUSER       list of usernames

SHOW     just list file contents (N) TABLES       list of table names

IGNORE   ignore create errors (N)    RECORDLENGTH length of IO record

GRANTS   import grants (Y)           INCTYPE      incremental import type

INDEXES  import indexes (Y)          COMMIT       commit array insert (N)

ROWS     import data rows (Y)        PARFILE      parameter filename

LOG      log file of screen output   CONSTRAINTS  import constraints (Y)

DESTROY                overwrite tablespace data file (N)

INDEXFILE              write table/index info to specified file

SKIP_UNUSABLE_INDEXES  skip maintenance of unusable indexes (N)

FEEDBACK               display progress every x rows(0)

TOID_NOVALIDATE        skip validation of specified type ids

FILESIZE               maximum size of each dump file

STATISTICS             import precomputed statistics (always)

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

COMPILE                compile procedures, packages, and functions (Y)

STREAMS_CONFIGURATION  import streams general metadata (Y)

STREAMS_INSTANTIATION  import streams instantiation metadata (N)

VOLSIZE                number 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=y  file=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=yOracle不执行CREATE TABLE语句,直接将数据插入到表中,如果插入的记录违背了约束条件,比如主键约束,则出错的记录不会插入,但合法的记录会添加到表中。

      ignore=nOracle不执行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.5  impexp使用的字符集不同

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

 

5.6  impexp版本不能往上兼容

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

       如果遇到迁移因版本不同的问题,可以用低版本的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

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

  4  size 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=y   buffer=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=y  full=y ignore=y buffer=65536 file=/tmp/exp_fulldatabase_090101.dmp log=/tmp/imp.log;

 

 

 

 

阅读(1727) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~