exp,imp

来源:互联网 发布:js获取当前登录用户名 编辑:程序博客网 时间:2024/06/05 11:52

导出(export)是用exp将数据库部分或全部对象的结构和数据导出。
导入(import)使用imp将os中的对象结构和数据装载到数据库中的过程。

exp和imp用于实现逻辑备份和逻辑恢复,导入导出的作用如下:
a.重新组织表
b.在数据库用户之间移动对象
c.在数据库之间移动对象
d.升级数据库到其他平台
e.升级数据库到更高版本

一.基本命令

(一).获取帮助

exp help=y/imp help =y

(二).三种工作方式

1.交互式
exp/imp --按提示输入所需要的参数
2.命令行
[oracle@redhat5 dmp]$ exp scott/oracle file=/home/oracle/dmp/scott.dmp log=/home/oracle/dmp/scott.log owner=scott;
注意:需要建用户scott
[oracle@redhat5 dmp]$ imp scott/oracle file=/home/oracle/dmp/scott.dmp log=/home/oracle/dmp/scott2.log fromuser=scott touser=scott
不建用户的导入方法:
[oracle@redhat5 dmp]$ imp system/oracle file=/home/oracle/dmp/scott.dmp full=y ignore=y;

3.参数文件
[oracle@redhat5 dmp]$ exp parfile=username.par
[oracle@redhat5 dmp]$ cat username.par
userid=scott/oracle
file=/home/oracle/dmp/scott1.dmp
log=/home/oracle/dmp/scott4.log
owner=scott

(三).三种模式

1.表方式

[oracle@redhat5 dmp]$ exp scott/oracle file=/home/oracle/dmp/emp.dmp log=/home/oracle/dmp/emp.log tables=scott.emp;
[oracle@redhat5 dmp]$ imp scott/oracle file=/home/oracle/dmp/emp.dmp tables=emp fromuser=scott touser=scott;

2.用户方式

参考上

3.全库方式

[oracle@redhat5 dmp]$ exp system/oracle file=/home/oracle/dmp/full.dmp log=/home/oracle/dmp/full.log full=y;
[oracle@redhat5 dmp]$ imp system/oracle file=/home/oracle/dmp/full.dmp full=y;

(四).高级选项

1.分割成多个文件
[oracle@redhat5 dmp]$ exp system/oracle file=/home/oracle/dmp/1.dmp,/home/oracle/dmp/2.dmp filesize=50m full=y
2.增量导出/导入
a.完全增量导出 --备份整个数据库
[oracle@redhat5 dmp]$ exp system/oracle file=/home/oracle/dmp/full.dmp inctype=complete;
b.增量型 增量导出:导出上一次备份后改变的数据
[oracle@redhat5 dmp]$ exp system/oracle file=/home/oracle/dmp/2.dmp inctype=incremental;
c.累积性 增量导出:只导出自上次完全(complete)导出后数据库中变化了的信息
[oracle@redhat5 dmp]$ exp system/oracle file=/home/oracle/dmp/3.dmp inctype=cumulative;

3.表空间传输
案例:
在orcl库进行
SQL> create tablespace wl datafile '/oracle/app/oracle/oradata/orcl/wl01.dbf' size 100m extent management local;
SQL> create user u1 identified by oracle default tablespace wl;
User created.
SQL> grant connect,resource to u1;
Grant succeeded.
SQL> create table u1.tab1 tablespace wl as select * from sys.dba_objects;
分别在orcl和prod库进行
SQL> SELECT des.PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp,V$DATABSE des WHERE tp.PLATFORM_NAME=des.PLATFORM_NAME;
在orcl库进行
SQL> execute dbms_tts.transport_set_check('wl',true);
SQL> select * from transport_set_violations;
SQL> alter tablespace wl read only;
[oracle@redhat5 dmp]$ exp userid=\'/ as sysdba\' tablespaces=wl file=/home/oracle/dmp/wl.dmp transport_tablespace=y;
将orcl库的wl表空间的数据文件和导出的dmp,传送到目标平台prod
注意:拷贝导出的DMP文件到目标平台:拷贝表空间的数据文件到目标平台
[oracle@redhat5 prod]$ cp ../orcl/wl01.dbf wl01.dbf
在prod操作
SQL> create user u1 identified by oracle;
SQL> grant connect,resource to u1;
[oracle@redhat5 prod]$ imp userid=\'/ as sysdba\' tablespaces=wl file=/home/oracle/dmp/wl.dmp 
transport_tablespace=y datafiles=/oracle/app/oracle/oradata/prod/wl01.dbf fromuser=u1 touser=u1
在orcl库操作
将被导入的表空间设置为可读可写
SQL> alter tablespace wl read write;
在prod库即可查看wl表空间的相关信息

(五).优化

1.加快exp速度

a.加大large_pool_size,可以提高exp的速度
b.采用直接路径的方式(direct=y),数据不需要经过内存进行整合
c.设置较大的buffer,如果导出大对象,小buffer会失败
d.导出(export)文件到不在oracle使用的驱动器上
e.不要export到nfs文件系统
f.Unix环境:用管道模式直接导入导出提高exp/imp性能

2.加快imp速度

a.建立一个indexfile,在数据import完成后再建立索引
b.将import文件放在不同的驱动器上
c.增加DB_BLOCK_BUFFERS
d.增加log_buffer
e.以非归档方式运行oracle(noachivelog)
f.建立打的表空间和回滚段,offline其他回滚段,会镦锻的大小为最大表的2分之1
g.使用commit=n,analyze=n
h.单用户模式导入
i.Unix:使用管道模式
0 0
原创粉丝点击