热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

Oracle10g的EXPDP与IMPDP的导出与导入测试

通过DB_LINK的复制功能,利用expdp,impdp进行数据的远程备份及恢复。进行测试前,将服务器B上scott用户的dept,emp进行删除,本测

通过DB_LINK的复制功能,利用expdp,impdp进行数据的远程备份及恢复。进行测试前,将服务器B上scott用户的dept,emp进行删除,本测

实验环境:

服务器A:172.21.1.30

服务器B:172.21.1.40

两台服务器上分别运行两套Oracle数据库,本实验以scott用户为例进行测试。

实验目的:

通过DB_LINK的复制功能,利用expdp,impdp进行数据的远程备份及恢复。进行测试前,将服务器B上scott用户的dept,emp进行删除,本测试只是使用impdp将服务器A数据库下scott用户的dept,emp表导入到服务器B数据库scott用户下。

操作步骤:

1.在服务器A,B上分别以sys身份登录数据库,并创建directory,db_link,命令如下:

session A: > create directory dp01 as '/bk/dp01';

Directory created.

session A: >create public database link ln_db40 connect to scott identified by tiger using 'ip40';

Database link created.

session A: >grant connect,resource,exp_full_database,imp_full_database to scott identified by tiger;

Grant succeeded.

session B: > create directory dp02 as '/bk/dp02';

Directory created.

session B: >create public database link ln_db30 connect to scott identified by tiger using 'ip30';

Database link created.

session B: >grant connect,resource,exp_full_database,imp_full_database to scott identified by tiger;

Grant succeeded.

2.在确认以上步骤中的db_link没问题后,做以下操作:

a. 服务器A:(将本地数据库中scott用户下的dept,emp两张表导出备份文件为exp01.dmp)

[oracle@session A: dp01]$ expdp scott/tiger directory=dp01 dumpfile=exp01.dmp network_link=ln_db30 tables=emp,dept

Export: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:39:05

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@ip30 directory=dp01 dumpfile=exp01.dmp network_link=ln_db30 tables=emp,dept
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 320 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."SYS_EXPORT_SCHEMA_01" 172.8 KB 1073 rows
. . exported "SCOTT"."DEPT" 5.656 KB 4 rows
. . exported "SCOTT"."EMP" 7.820 KB 14 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/bk/dp01/exp01.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:39:37

[oracle@session A: dp01]$ ls

exp01.dmp export.log import.log

b. 将备份文件exp01.dmp从服务器A拷贝到服务器B:

[oracle@session A: dp01]$ scp –r exp01.dmp 172.21.1.40:/bk/dp02/

c.在服务器A上,执行以下命令,将dept,emp表导入到服务器B的scott用户下:


[oracle@session A: dp01]$ impdp scott/tiger@ip40 directory=dp02 dumpfile=exp01.dmp tables=emp,dept

Import: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:34:57

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/********@ip40 directory=dp02 dumpfile=exp01.dmp tables=emp,dept
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."DEPT" 5.656 KB 4 rows
. . imported "SCOTT"."EMP" 7.820 KB 14 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 14:34:55

3.使用sys用户登录服务器A的数据库,进行测试,查看B的scott用户下的dept,emp表是否存在:

$ sqlplus / as sysdba

session A: > conn scott/tiger

Connected.

session A: > select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE

session A: > select * from tab@ln_db40;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE

由以上实验不难看出,表dept,emp已成功导入B的scott用户。

EXPDP 可以导出所有数据库的数据,只要它能连接到这个数据库,或者它登录的数据库
上能读取到被导出的库的数据,因为此时可以通过数据库链来读取被导出的库的数据。

如下测试:

可以分为三个服务器:A,B,,C,以下命令在A在执行:

[oracle@session A: dp01]$ expdp scott/tiger@ip40 directory=dp02 dumpfile=exp01.dmp network_link=ln_db50 tables=emp,dept

Export: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:39:05

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@ip40 directory=dp02 dumpfile=exp01.dmp network_link=ln_db50 tables=emp,dept
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 320 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."SYS_EXPORT_SCHEMA_01" 172.8 KB 1073 rows
. . exported "SCOTT"."DEPT" 5.656 KB 4 rows
. . exported "SCOTT"."EMP" 7.820 KB 14 rows
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/bk/dp01/exp01.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:39:37

说明:

expdp 在服务器A上;

scott/tiger@ip40 连接到服务器B的数据库;

network_link=ln_db30 是服务器B的数据库中scott用户的数据库链,其指向服务器C的用户scott,
SCOTT10用户中只有两个表dept,emp.

从上面的操作可以看出:expdp 可以是客户端的程序,但它导出的数据(DMP)必须存放在它登录

的数据库的目录下(本例中,存放在机器B的数据库directory=dp02下),而被导出的数据是通过

数据库链(network_link)到机器C的数据库里读取的。

另外注意:在这过程中,A数据库用户scott和C数据库用户scott(或者数据库链中的用户)都必须被

授予EXP_FULL_DATABASE 权限。

nelwork_link意思是从本地数据库导入datafile直接到remote database,中间省略了exp的操作,

nelwork_link=source_database_link,确认nelwork_link参数是一个存在的目标数据库名称,同时

存在database link.

补充一下两个限制条件:

nelwork_link parameter Restrictions


Network imports do not support the use of evolved types.

a: When the NETWORK_LINK parameter is used in conjunction with the TABLES parameter,

only whole tables can be imported (not partitions of tables).

所以,当使用impdp导入时多张表时,如果添加network_link参数,就会报错如下:

UDI-00011: parameter dumpfile is incompatible with parameter network_link


b: If the USERID that is executing the import job has the IMP_FULL_DATABASE role on the

target database, then that user must also have the EXP_FULL_DATABASE role on the source

database.The only types of database links supported by Data Pump Import are: public,

fixed-user, and connected-user. Current-user database links are not supported.

推荐阅读
  • 本文详细介绍了IBM DB2数据库在大型应用系统中的应用,强调其卓越的可扩展性和多环境支持能力。文章深入分析了DB2在数据利用性、完整性、安全性和恢复性方面的优势,并提供了优化建议以提升其在不同规模应用程序中的表现。 ... [详细]
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • PHP 编程疑难解析与知识点汇总
    本文详细解答了 PHP 编程中的常见问题,并提供了丰富的代码示例和解决方案,帮助开发者更好地理解和应用 PHP 知识。 ... [详细]
  • 优化联通光猫DNS服务器设置
    本文详细介绍了如何为联通光猫配置DNS服务器地址,以提高网络解析效率和访问体验。通过智能线路解析功能,域名解析可以根据访问者的IP来源和类型进行差异化处理,从而实现更优的网络性能。 ... [详细]
  • 本文详细介绍了如何使用libpq库与PostgreSQL后端建立连接。通过探讨PQconnectdb()函数的工作原理及其在实际应用中的使用方法,帮助读者理解并掌握建立高效、稳定的数据库连接的关键步骤。 ... [详细]
  • SQL中UPDATE SET FROM语句的使用方法及应用场景
    本文详细介绍了SQL中UPDATE SET FROM语句的使用方法,通过具体示例展示了如何利用该语句高效地更新多表关联数据。适合数据库管理员和开发人员参考。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 构建基于BERT的中文NL2SQL模型:一个简明的基准
    本文探讨了将自然语言转换为SQL语句(NL2SQL)的任务,这是人工智能领域中一项非常实用的研究方向。文章介绍了笔者在公司举办的首届中文NL2SQL挑战赛中的实践,该比赛提供了金融和通用领域的表格数据,并标注了对应的自然语言与SQL语句对,旨在训练准确的NL2SQL模型。 ... [详细]
  • 本文详细介绍了HTML中标签的使用方法和作用。通过具体示例,解释了如何利用标签为网页中的缩写和简称提供完整解释,并探讨了其在提高可读性和搜索引擎优化方面的优势。 ... [详细]
  • 数据库内核开发入门 | 搭建研发环境的初步指南
    本课程将带你从零开始,逐步掌握数据库内核开发的基础知识和实践技能,重点介绍如何搭建OceanBase的开发环境。 ... [详细]
  • 本文深入探讨 MyBatis 中动态 SQL 的使用方法,包括 if/where、trim 自定义字符串截取规则、choose 分支选择、封装查询和修改条件的 where/set 标签、批量处理的 foreach 标签以及内置参数和 bind 的用法。 ... [详细]
  • 使用C#开发SQL Server存储过程的指南
    本文介绍如何利用C#在SQL Server中创建存储过程,涵盖背景、步骤和应用场景,旨在帮助开发者更好地理解和应用这一技术。 ... [详细]
author-avatar
灵绾绾
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有