电脑技术学习

oracle逻辑备份恢复 exp/imp篇

dn001

  1.数据导出工具EXP

  EXP是客户端工具,该工具不仅可以在oracle客户端使用,还可以在oracle服务器端使用。当在oracle客户端使用EXP工具时,必须带有连接字符串;当在oracle服务器端使用EXP工具时,可以不带字符串。导出包括导出表、导出方案、导出数据库三种模式。

  (1)导出表

  导出表是指使用EXP工具将一个或多个表的结构和数据存储到OS文件中,导出表是使用TABLES选项来完成的。

  普通用户可以导出其自身方案的所有表,但如果要导出其他方案的表,则要求该用户必须具有EXP_FULL_DATABASE角色或DBA角色。另外当导出表时,默认情况下会导出相应表上的所有索引、触发器、约束。下面以SYSTEM用户导出SCOTT.DEPT表为例,示例如下:

  exp system/oracle@charge TABLE=scott.dept,scott.emp FILE=tab1.dmp

  (2)导出方案

  导出方案是指使用EXP工具将一个或多个方案中的所有对象记数据存储到OS文件中,导出表是使用OWNER选项来完成的。

  普通用户可以导出其自身方案,但如果要导出其他方案,则要求该用户必须具有DBA角色或EXP_FULL_DATABASE角色。当用户要导出其自身方案的所有对象时,可以不指定OWNER选项,下面以SYSTEM用户导出SCOTT方案的所有对象为例,示例如下:

  exp system/oracle@charge OWNER=scott FILE=schemal.dmp

  以上为命令行方式进行数据的导出,EXP工具还可以以交互的方式进行数据导出。

  (1)导出表(交互方式)

  [oracle@ora-asm3 dbs]$ exp

  Export: Release 10.2.0.1.0 - Production on 星期一 6月 16 16:24:26 2008

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

  Username: charge输入用户名

  Password:;;;;输入密码

  Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

  With the Partitioning, OLAP and Data Mining options

  Enter array fetch buffer size: 4096 >;;;;输入缓冲区大小,可以默认也可以自定义,如果数据文件较大,建议设置的大一些。

  Export file: expdat.dmp > charge01.dmp输入导出的文件名,必须以.dmp文件做为扩展名。

  (2)U(sers), or (3)T(ables): (2)U > t输入导出类型,默认为用户(也就是方案),在此输入t,为导出表

  Export table data (yes/no): yes >;;是否导出表中的数据,如果选NO,则导出表结构。

  Compress extents (yes/no): yes >;是否对数据压缩

  Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

  About to export specified tables via Conventional Path ...

  Table(T) or Partition(T:P) to be exported: (RETURN to quit) > clients输入表名

  开始导出clients表数据

  . . exporting table;;;;;CLIENTS 10 rows exported

  Table(T) or Partition(T:P) to be exported: (RETURN to quit) >如果没有要导出的数据时,按回车退出。

  Export terminated successfully without warnings.

  提示导出成功,没有任何告警。
  (2)导出方案(交互方式)

  [oracle@ora-asm3 dbs]$ exp

  Export: Release 10.2.0.1.0 - Production on 星期一 6月 16 16:23:47 2008

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

  Username: charge;;;;输入用户名

  Password:;;;;;输入密码

  Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

  With the Partitioning, OLAP and Data Mining options

  Enter array fetch buffer size: 4096 >;;;输入缓冲区大小,可以默认也可以自定义,如果数据文件较大,建议设置的大一些。

  Export file: expdat.dmp > charge.dmp;;输入导出的文件名,必须以.dmp做为扩展名。

  (2)U(sers), or (3)T(ables): (2)U > u 输入导出类型,默认为用户(方案),可以直接回车,也可以输入u。

  Export grants (yes/no): yes >导入权限

  Export table data (yes/no): yes >;是否导出表中的数据,如果选NO,则导出表结构。

  Compress extents (yes/no): yes > 是否对数据压缩

  Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

  . exporting pre-schema procedural objects and actions

  . exporting foreign function library names for user CHARGE

  . exporting PUBLIC type synonyms

  . exporting private type synonyms

  . exporting object type definitions for user CHARGE

  About to export CHARGE's objects ...

  . exporting database links

  . exporting sequence numbers

  . exporting cluster definitions

  . about to export CHARGE's tables via Conventional Path ...

  . . exporting table;BALANCE; 0 rows exported

  . . exporting table;BALANCEFINISHED; 0 rows exported

  ………………

  . exporting synonyms

  . exporting views

  . exporting stored procedures

  . exporting operators

  . exporting referential integrity constraints

  . exporting triggers

  . exporting indextypes

  . exporting bitmap, functional and extensible indexes

  . exporting posttables actions

  . exporting materialized views

  . exporting snapshot logs

  . exporting job queues

  . exporting refresh groups and children

  . exporting dimensions

  . exporting post-schema procedural objects and actions

  . exporting statistics

  Export terminated successfully without warnings.

  提示导出成功,没有任何告警。

  2.数据导入工具IMP

  (1)导入表

  导入表是指使用工具IMP将EXP文件中的表结构及其数据转载到数据库中,导入表是使用TABLES选项来完成的。

  普通用户可以直接导入其拥有的表,但如果要将表导入到其他用户中,则要求该用户必须具有IMP_FULL_DATABASE角色或DBA角色。注意,如果要将表导入到其他用户中,则需要指定FROMUSER和TOUSER选项,示例如下:

  imp scott/oracle@charge FILE=tab2.dmp TABLES=dept.emp

  imp system/oracle@charge FILE=tab2.dmp TABLES=dept.emp; FROMUSER=scott TOUSER=system

  如上所示,第一示例表示将文件tab2.dmp中DEPT和EMP表的结构和数据导入到SCOTT用户中;第二个示例表示文件tab2.dmp中SCOTT用户的DEPT和EMP表导入SYSTEM用户中。

  (2)导入方案

  导入方案是指使用工具IMP将EXP文件中的特定方案的所有对象及数据转载到数据库中。

  普通用户可以直接导入其自身方案,并且在导入时需要提供USERID和FILE选项即可。但如果要将一个方案的所有对象导入到其他方案中,则要求该用户必须具有IMP_FULL_DATABASE角色,并且必须提供FROMUSER和TOUSER选项。示例如下:

  imp scott/oracle@charge FILE=schema2.dmp

  imp system/oracle@charge FILE=schema2.dmp FROMUSER=scott; TOUSER=system

  如上所示,第一示例表示将文件schema 2.dmp中SCOTT用户的所有对象及数据导入到SCOTT用户中;第二个示例表示文件schema 2.dmp中SCOTT用户的所有对象及数据导入SYSTEM用户中。
  以上为命令行方式进行数据的导出,EXP工具还可以以交互的方式进行数据导出。

  (1)导入表(交互方式)

  [oracle@ora-asm3 ~]$ imp

  Import: Release 10.2.0.1.0 - Production on 星期一 6月 16 16:40:10 2008

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

  Username: charge;;;输入用户名

  Password: 输入密码

  Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

  With the Partitioning, OLAP and Data Mining options

  Import file: expdat.dmp > charge.dmp;输入要导入的数据文件

  Enter insert buffer size (minimum is 8192) 30720>;;输入缓冲区大小,可以默认也可以自定义,如果数据文件较大,建议设置的大一些。

  Export file created by EXPORT:V10.02.01 via conventional path

  import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

  List contents of import file only (yes/no): no >;只列出导入文件的内容

  Ignore create error due to object existence (yes/no): no >由于对象已存在, 忽略创建错误

  Import grants (yes/no): yes >导入权限

  Import table data (yes/no): yes >;;导入表数据,如果选NO,则导入表结构

  Import entire export file (yes/no): no >;;导入整个导出文件

  Username: charge;;;;;要导入方案的名称

  Enter table(T) or partition(T:P) names. Null list means all tables for user

  Enter table(T) or partition(T:P) name or . if done: clients输入要导入的表名

  Enter table(T) or partition(T:P) name or . if done:; 如果没有要导入的表时,直接回车,进行导入

  . importing CHARGE's objects into CHARGE

  . importing CHARGE's objects into CHARGE

  . . importing table;;"CLIENTS" 10 rows imported

  Import terminated successfully without warnings.

  导入成功,没有告警。

  (2)导入方案(交互方式)

  [oracle@ora-asm3 ~]$ imp

  Import: Release 10.2.0.1.0 - Production on 星期一 6月 16 17:17:54 2008

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

  Username: charge; 输入用户名称

  Password:;;;;输入密码

  Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

  With the Partitioning, OLAP and Data Mining options

  Import file: expdat.dmp > charge.dmp;输入要导入的数据文件

  Enter insert buffer size (minimum is 8192) 30720>输入缓冲区大小,可以默认也可以自定义,如果数据文件较大,建议设置的大一些。

  Export file created by EXPORT:V10.02.01 via conventional path

  import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

  List contents of import file only (yes/no): no >;;;;只列出导入文件的内容

  Ignore create error due to object existence (yes/no): no >由于对象已存在, 忽略创建错误

  Import grants (yes/no): yes >导入权限

  Import table data (yes/no): yes >;;导入表数据,如果选NO,则导入表结构

  Import entire export file (yes/no): no >;;导入整个导出文件

  Username: charge;输入要导入方案的名称

  Enter table(T) or partition(T:P) names. Null list means all tables for user

  Enter table(T) or partition(T:P) name or . if done:;;;回车,进行导入数据

  . importing CHARGE's objects into CHARGE

  . . importing table"BALANCE"0 rows imported

  . . importing table"BALANCEFINISHED"0 rows imported

  About to enable constraints...

  Import terminated successfully without warnings.

  导入成功,没有任何告警。

标签: