ORACLE 备份恢复命令imp/exp

来源:互联网 发布:部落冲突骷髅法术 数据 编辑:程序博客网 时间:2024/06/06 12:54

几天闲来无事,就整理了下imp/exp 

imp/exp是Oracle导入导出命令,可以用作数据的迁移,expdp/imdp也是Oracle数据导入导出的命令,效率比imp/exp效率要高,这个后面再讨论


一  EXP

exp 是数据的导出命令,可以用于表,用户,整个数据库,
exp -help


Export: Release 11.2.0.1.0 - Production on Mon Dec 8 19:01:16 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  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


上面是exp -help的相关参数

1,表模式:

    备份某个用户模式下指定的对象(表)。业务数据库通常采用这种备份方式。若备份到本地文件,使用如下命令:
exp username/password rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=exp.dmp log=exp.log tables=tab1,tab2,tab3


若直接备份到磁带设备,使用如下命令:
注:在磁盘空间允许的情况下,应先备份到本地服务器,然后再拷贝到磁带。出于速度方面的考虑,尽量不要直接备份到磁带设备。
    exp scott/tiger owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log


eg:

[oracle@DRAGON chenlong]$ exp scott/tiger  rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/home/oracle/chenlong/exp.dmp log=/home/oracle/chenlong/exp.log tables=emp,dept


Export: Release 11.2.0.1.0 - Production on Mon Dec 8 19:05:32 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.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: indexes on tables will not be exported


About to export specified tables via Conventional Path ...
. . exporting table                            EMP
                                                           14 rows exported
EXP-00091: Exporting questionable statistics.
. . exporting table                           DEPT
                                                            4 rows exported
Export terminated successfully with warnings.




 

2,用户模式:

    备份某个用户模式下的所有对象。业务数据库通常采用这种备份方式。 若备份到本地文件,使用如下命令:
    exp scott/tiger owner=scott rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp.dmp log=exp.log
 
若直接备份到磁带设备,使用如下命令:
    exp scott/tiger owner=scott rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=/dev/rmt0 log=exp.log
 
    注:如果磁盘有空间,建议备份到磁盘,然后再拷贝到磁带。如果数据库数据量较小,可采用这种办法备份。

3,完全模式:

    备份完整的数据库。业务数据库不采用这种备份方式。备份命令为:
    exp usernumber/password rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y  file=exp_.dmp log=exp.log


二:IMP

       import 要与export 对应。 就是采用什么方式export,就需要采用什么方式import。

因此import 也有三种模式:表恢复、用户恢复、完全恢复。




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)
DATA_ONLY              import only data (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


1. 表模式

此方式将根据按照表模式备份的数据进行恢复。  
 
1.1 恢复备份数据的全部内容
    imp scott/tiger fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log
 
若从磁带设备恢复,使用如下命令:
imp scott/tiger fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 log=imp.log
 
1.2 恢复备份数据中的指定表:
若从本地文件恢复,使用如下命令:
imp scott/tiger fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n file=exp.dmp log=imp.log tables=t1,t2,t3
 
若从磁带设备恢复,使用如下命令:
imp scott/icd fromuser=scott touser=scott rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0  
log=imp.tiger 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.1. ignore参数

    Oracle在恢复数据的过程中,当恢复某个表时,该表已经存在,就要根据ignore参数的设置来决定如何操作。
    若ignore=y,Oracle不执行CREATE TABLE语句,直接将数据插入到表中,如果插入的记录违背了约束条件,比如主键约束,则出错的记录不会插入,但合法的记录会添加到表中。
    若ignore=n,Oracle不执行CREATE TABLE语句,同时也不会将数据插入到表中,而是忽略该表的错误,继续恢复下一个表。 ­
 

3.2. indexes参数

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

3.3 字符集转换

    对于单字节字符集(例如US7ASCII),恢复时,数据库自动转换为该会话的字符集(NLS_LANG参数);
    对于多字节字符集(例如ZHS16CGB231280),恢复时,应尽量使字符集相同(避免转换),如果要转换,目标数据库的字符集应是输出数据库字符集的超集。

3.4 grants

    导入权限

3.5 commit

    该参数为Y时,导入的过程会提交数据行,若buffer设置得太小,则会过去频繁的提交数据,对性能有一定的影响.

 
四   常见问题及解决方法

4.1 数据库对象已经存在

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

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

    不符合主外键约束时, 数据会导入失败,
    解决办法:
    先导入主表, 再导入依存表
    disable目标导入对象的主外键约束, 导入数据后, 再enable它们
 

4.3  权限不够

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

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

    默认的EXP时, compress = Y, 也就是把所有的数据压缩在一个数据块上.
    导入时, 如果不存在连续一个大数据块, 则会导入失败. 导出80M以上的大表时, 记得compress= N, 则不会引起这种错误.
 

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

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

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

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



注意:

1,导入时要注意字符集的,字符集不能由高到底(超集到子集)

2,导入时要注意版本问题。


后面再讨论expdp/impdp

参考于:http://blog.csdn.net/tianlesoftware/article/details/4718366
 

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 3个月宝宝感冒鼻塞怎么办 2个月宝宝感冒鼻塞怎么办 5个月宝宝鼻塞怎么办 6个月宝宝鼻塞怎么办 3个月婴儿感冒咳嗽怎么办 感冒打喷嚏打不出来怎么办 4岁宝宝体温37.5怎么办 8个月的宝宝鼻塞怎么办 4个月婴儿鼻塞怎么办 我一躺下就鼻塞怎么办 感冒了鼻子堵了怎么办 感冒鼻涕流的多怎么办 小孩感冒鼻塞怎么办最简单方法 鼻子痒老打喷嚏流鼻涕怎么办 眼睛红痒鼻子流鼻涕怎么办 19个月宝宝流鼻血怎么办 9个月宝宝流鼻血怎么办 8个月宝宝流鼻血怎么办 4个月宝宝流鼻血怎么办 20个月宝宝发烧流鼻血怎么办 60天宝宝老鼻塞怎么办 10个月宝宝头被撞到流鼻血怎么办 狗狗受凉吐了怎么办 狗狗咳嗽流鼻涕一直不好怎么办 宝宝感冒咳嗽流鼻涕发烧怎么办 狗狗感冒咳嗽流鼻涕怎么办 9岁儿童咳嗽鼻塞怎么办 三个月大的狗狗流鼻涕怎么办 3个月小狗干呕流鼻涕怎么办 狗狗流鼻涕怎么办有浓 小狗狗感冒了怎么办呢 狗狗一直擤鼻涕怎么办 小狗感冒流黄鼻涕怎么办 六个月宝宝鼻塞流鼻涕怎么办 小狗吃太多吐了怎么办 狗狗晕车一直吐怎么办 狗狗已经晕车了怎么办 狗狗得犬瘟怎么办 泰迪坐车吐了怎么办 小孩感冒流鼻涕带血怎么办 孩子鼻子流鼻涕有血丝怎么办