拓扑园

  • Oracle性能优化
  • Oracle项目案例
    • Oracle近期项目案例(目录)
    • Oracle实战问题解析(目录)
    • Oracle数据库名变更流程(2种方式)
    • Oracle数据库目录更换流程(使用Oracle的clone工具)
    • Oracle数据库迁移方案(目录)
  • 技术研究-密保
    • FG-MySQL
    • FG-Docker/K8S
    • FG-PostgreSQL
    • FG-ORACLE_BBED
    • FG-ORACLE
    • FG-Elasticsearch(ES)+ELK
    • Oracle-19C-OCP
    • WERN_ORACLE培训
    • redis数据库
    • Nginx培训学习系列
  • 图灵小队
    • MySQL8.0/Oracle/Memcached/Redis等安装配置于RHEL/OL6/7/8.X系列-运行环境最优配置
    • PG安装配置于RHEL/9X系列-运行环境最优配置
    • 自动维护任务详解-开启、关闭信息统计收集(统计信息)
    • 图灵小队-Oracle存储过程导出表的明细_UTL_FILE(文章)
    • 图灵小队-Oracle数据库删除/卸载操作指南(文章)
    • 图灵小队-Oracle常用性能查询SQL语句(文章)
    • 图灵小队-Oracle数据库上线前检查(文章)
    • 图灵小队-Oracle常用SQL语句(文章)
    • 图灵小队-Oracle脚本合集(文章)
    • 图灵小队-Oracle技巧记录(文章)
    • LLL的Oracle培训(目录)
    • LLL的docker培训(目录)
    • 标准化文档系列(目录)
    • Oracle/MySQl等面试题
  • Oracle
    • Oracle
    • ADG
    • RAC
    • ASM
    • EXPDP/IMPDP
    • 工厂数据导入导出系列
    • OGG
    • RMAN
  • 云计算
    • 云计算
    • docker
    • kubernetes
  • Linux
    • Linux
    • PHP
    • Nginx
    • haproxy
    • mail
    • 网站
    • 域名
    • 网址收藏
  • 数据中心
    • 数据中心
    • EBS数据文件库容
    • VMware虚拟化
    • mysql
    • EBS系列
    • 大数据
    • SVN
    • zabbix
    • SAP
    • 备份相关
    • FC交换机
    • SVN
  • 其他
    • 外研英语4年级下册-听力
    • 影视系列
    • 如何使用iTunes软件通过抓包下载旧版本的ios的app
Oracle数据库恢复专家团队:TEL:18562510581(微信同号);QQ:284833194;QQ群:496333360
天高任鸟飞
  1. 首页
  2. 技术学习系列
  3. WERN_ORACLE培训
  4. 正文

第27部分 oracle11g的逻辑备份恢复2-expdp,impdp

2020年4月22日 463点热度 1人点赞 0条评论

目录

  • 一、为什么使用数据泵?与exp/imp区别
  • 三、expdp四种模式:表、用户、可传输表空间、全库。
  • 四、expdp的重要参数
  • 五、导出举例
    • 1、建立转储(存放)目录
    • 2、目录对象[system权限]:
    • 3、导出scott的student,address表
    • 4、导出scott用户student、address的表结构,不导出数据
    • 5、导出scott用户【用system导出普通用户】
    • 6、只导出scott用户student、address的表数据,不导出结构
    • 7、导出student表、和表上面的主约束、索引
    • 8、【exclude】导出student表、约束,但不导出索引
    • 9、【exclude】导出student表,不导出约束、不导出索引
    • 10、【exclude】导出scott对象的表,但不导出student,BONUS表
    • 11、【exclude】导出student表和约束、索引,导出addres表的结构和数据,但不导出address表的约束和索引
    • 12、【include】导出student表和约束、索引,导出addres表的结构和数据,但不导出address表的约束和索引
    • 13、【include】导出student表的sno>1的记录,和address的sno=2的记录
  • 五、impdp的重要参数
  • 六、impdp的举例
    • 1、remap_schames的使用
    • 2、remap_tablespaces的使用

一、为什么使用数据泵?与exp/imp区别

exp/imp的缺点是速度太慢,在大型生产库中尤其明显。从10g开始,oracle设计了数据泵,这是一个服务器端的工具,它为Oracle数据提供高速并行及大数据的迁移。

exp/imp可以在客户端调用,但是expdp/impdp只能在服务端,因为在使用expdp/impdp以前需要在数据库中创建一个 Directory 。

二、EXPDP导出流程

在expdp进行导出时:

1、先创建了MT表,并把对象的信息插入到MT表,之后进行导出动作;

2、导出完成后,MT表也导出到转储文件中;

3、导出任务完成后、或者删除了导出任务后,MT表自动删除;

4、如果导出任务异常终止,MT表仍然保留。

三、expdp四种模式:表、用户、可传输表空间、全库。

四、expdp的重要参数

1、部分的exp中的参数仍然可用,有的不能使用,如index。

2、directory:供转储文件和日志文件使用的目录对象。

3、job_name:指定的任务的名称。

4、content:指定要导出的数据, 其中有效关键字值为: (ALL), DATA_ONLY 和 METADATA_ONLY,当设置content为ALL 时,将导出对象定义及其所有数据;

DATA_ONLY时,只导出对象数据;为METADATA_ONLY时,只导出对象定义 。

5、reuse_dumpfiles:如果导出文件已经存在,是否覆盖。

6、compression:压缩导出文件。

7、estimate:指定估算被导出表所占用磁盘空间分方法.默认值是BLOCKS

8、 estimate_only:是否只估算导出占用的磁盘空间,而不进行真正的导出,默认是N。

9、exclude:用于指定执行操作时要排除对象类型或相关对象,用法:EXCLUDE=object_type[:name_clause] [,….]

10、include:用于指定执行操作时要包含的对象类型或相关对象,用法:INCLUDE=object_type[:name_clause] [,….]

11、query:导出符合条件的行。

12、attch:连接到现有的作业,可以用在中断导出任务后重新启动导出任务。

五、导出举例

1、建立转储(存放)目录

[oracle@localhost ~]$ mkdir /data/expdpbackup/

2、目录对象[system权限]:

SQL>create directory mes_backup as '/data/expdpbackup';
SQL>grant read,write on directory  mes_backup to scott;

3、导出scott的student,address表

expdp scott/scott directory=mes_backup dumpfile=expdp_scott1.dmp tables=student,address

导出过程,会出现sys_export_table_01表,通过select * from tab可以查到,即前面说的MT表

1587562974421485.png

4、导出scott用户student、address的表结构,不导出数据

reuse_dumpfiles=y 覆盖已存在的dmp文件,默认为n,不覆盖

expdp scott/scott directory=mes_backup dumpfile=expdp_scott2.dmp tables=student,address content=metadata_only reuse_dumpfiles=y

导入 expdp_scott2.dmp,查看是否只有结构而没有数据。

impdp scott/scott directory=mes_backup dumpfile=expdp_scott2.dmp

image.png

image.png

5、导出scott用户【用system导出普通用户】

expdp syetem/oracle directory=mes_backup dumpfile=expdp_scott11.dmp s=scott job_name=expdpjob

其中,job_name就是我们指定的MT表的名字

image.png

image.png

6、只导出scott用户student、address的表数据,不导出结构

expdp scott/scott directory=mes_backup dumpfile=expdp_scott2.dmp tables=student,address content=data_only reuse_dumpfiles=y

如果不导出结构,把scott的student和address表删了,再导入的时候,会报错,如下:

impdp scott/scott directory=mes_backup dumpfile=expdp_scott_data-nomata.dmp

image.png

但是如果是空的表,是可以导入的

创建空表,再导入:

create table student(sno int,sname varchar2(10),sage int,constraint pk_sno primary key(sno));
create table address(sno int,zz varchar2(10));

image.png

7、导出student表、和表上面的主约束、索引

exp和expdp都可以实现

exp scott/scott file=/data/exp1.dmp tables=student
expdp scott/scott directory=mes_backup dupfile=expdp_scott3.dmp tables=student

8、【exclude】导出student表、约束,但不导出索引

exp scott/scott file=/data/exp1.dmp tables=student indexes=n
expdp scott/scott directory=mes_backup dupfile=expdp_scott14.dmp tables=student exclude=index

image.png

9、【exclude】导出student表,不导出约束、不导出索引

exp scott/scott file=/data/exp1.dmp tables=student indexes=n constraints=n

expdp scott/scott directory=mes_backup dumpfile=expdp_scott15.dmp tables=student exclude=index,constraint

10、【exclude】导出scott对象的表,但不导出student,BONUS表

expdp scott/scott directory=mes_backup dumpfile=expdp_scot17.dmp exclude=table:"in('BONUS')" exclude=table:"in('STUDENT')" 

expdp scott/scott directory=mes_backup dumpfile=expdp_scot17.dmp exclude=table:"in('BONUS','STUDENT')" #这种在参数文件中可以实现,直接运行是不可以的,需要用上述语句

11、【exclude】导出student表和约束、索引,导出addres表的结构和数据,但不导出address表的约束和索引

expdp scott/scott directory=mes_backup dumpfile=expdp_scot18.dmp tables=student,address exclude=constraint:"in('CON_ZZ')" exclude=index:"in('IND_ADD_SNO')"

12、【include】导出student表和约束、索引,导出addres表的结构和数据,但不导出address表的约束和索引

使用参数的方式,expdp1.txt

directory=mes_backup dumpfile=epdp7.dmp include=table:"in('STUDENT','ADDRESS')"  include=index:"in('PK_SNO','IND_STU_SNAME')"  include=constraint:"in('PK_SNO','CON_SAGE')"

执行参数

[oracle@localhost data]$ expdp scott/scott parfile=/data/expdp1.txt 

image.png

13、【include】导出student表的sno>1的记录,和address的sno=2的记录

使用参数的方式,expdp2.txt

directory=mes_backup dumpfile=epdp7.dmp reuse_dumpfiles=y tables=student,address query=student:"where sno >1",address:"where sno=2"

执行参数文件

[oracle@localhost data]$ expdp scott/scott parfile=/data/expdp2.txt 

image.png

14、估算导出占用的磁盘空间

expdp MESSHYCBZ/Mes1qaz#EDC DIRECTORY=backup_mes estimate_only=y

五、impdp的重要参数

1、content:

指定要加载的数据, 其中有效关键字值为: (ALL), DATA_ONLY 和 METADATA_ONLY,

当设置content为ALL 时,将加载对象定义及其所有数据;

DATA_ONLY时,只加载对象数据;为METADATA_ONLY时,只加载对象定义 。

2、estimate:估算所占用磁盘空间分方法.默认值是BLOCKS

3、remap_schema:用于将对象从一个用户下导入到另一个用户下。

4、remap_tablespace:用于将对象从一个表空间下导入到另一个表空间下。

5、remap_datafile:用于在不同文件系统的平台间,切换数据文件路径。

六、impdp的举例

1、remap_schames的使用

expdp scott/scott directory=mes_backup dumpfile=expdp1.dmp schemas=scott;

hr进行导入:

impdp test/test directory=mes_backup dumpfile=expdp1.dmp remap_schame=scott:test

2、remap_tablespaces的使用

expdp scott/scott directory=mes_backup dumpfile=expdp1.dmp schemas=scott;

hr进行导入:

impdp test/test directory=mes_backup dumpfile=expdp1.dmp remap_tablespace=users:example
标签: 暂无
最后更新:2020年4月25日

admin

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论

COPYRIGHT © 2022 拓扑园. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

鲁ICP备2021020523号

鲁ICP备2021020523号