66.3. expdp/impdp

简介:

创建 dump 目录与用户

create directory mydump as '/u01/oracle';
		
grant read, write on directory mydump to dumpuser
grant read,write on directory backup to finance;		
		

66.3.1. expdp

导出用户的数据

expdp dumpuser/password directory=mydump dumpfile=user.dmp
			

导出指定表数据

expdp dumpuser/password directory=mydump dumpfile=table.dmp tables=test1,test2
			

按用户导

expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=backup;			
			

并行进程进程数

expdp scott/tiger@orcl directory=backup dumpfile=scott3.dmp parallel=40 job_name=scott3			
			

指定查询条件

expdp scott/tiger@orcl directory=backup dumpfile=expdp.dmp Tables=emp query='WHERE age=20';			
			

按表空间导

expdp system/manager DIRECTORY=backup DUMPFILE=tablespace.dmp TABLESPACES=temp,example;			
			

导整个数据库

expdp system/manager DIRECTORY=backup DUMPFILE=full.dmp FULL=y;			
			

			

			
			

66.3.2. impdp

导入该用户数据

impdp dumpuser/password directory=mydump dumpfile=user.dmp
			

导出表数据

impdp dumpuser/password directory=mydump dumpfile=table.dmp
			
$ impdp  \'/ as sysdba\' directory=backup dumpfile=user.dmp logfile=user.log tablespaces=dave,bl table_exists_action=replace;			
			

导到指定Schemas下

impdp scott/tiger DIRECTORY=backup DUMPFILE=expdp.dmp SCHEMAS=scott;
			

改变表的所有者

impdp system/manager DIRECTORY=backup DUMPFILE=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;
			

导入表空间

impdp system/manager DIRECTORY=backup DUMPFILE=tablespace.dmp TABLESPACES=example;
			

导入数据库

impdb system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;			
			

追加数据

impdp system/manager DIRECTORY=backup DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION			
			

66.3.3. 数据泵演示

创建目录

mkdir  /opt/oracle/backup			
			

创建用户

create user backup identified by passw0rd;
GRANT resource,connect,CREATE SESSION,CREATE TABLE,SELECT ANY TABLE,UPDATE ANY TABLE,DELETE ANY TABLE,INSERT ANY TABLE,ALTER ANY TABLE,DROP ANY TABLE TO backup;


create directory backup as '/opt/oracle/backup';
grant read,write on directory backup to backup;		
			

例 66.1. expdp

				
$ expdp backup/passw0rd dumpfile=backup.dmp directory=backup

Export: Release 11.2.0.1.0 - Production on Tue Dec 1 16:19:56 2015

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
Starting "BACKUP"."SYS_EXPORT_SCHEMA_01":  backup/******** dumpfile=backup.dmp directory=backup 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
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
Master table "BACKUP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for BACKUP.SYS_EXPORT_SCHEMA_01 is:
  /opt/oracle/backup/backup.dmp
Job "BACKUP"."SYS_EXPORT_SCHEMA_01" successfully completed at 16:20:28
				
				

运行完成后会在/opt/oracle/backup/目录生成backup.dmp文件


例 66.2. impdp

首先将dmp文件复制到恢复目录中,确认oracle用户有权限访问该文件。

mv backup.dmp /opt/oracle/backup/
chown oracle:oinstall /opt/oracle/backup/backup.dmp
				

如果不知道目录可以使用下面语句查看

				
SQL> SELECT directory_name, directory_path FROM dba_directories WHERE directory_name='BACKUP';

DIRECTORY_NAME
------------------------------
DIRECTORY_PATH
------------------------------
BACKUP
/opt/oracle/backup
				
				
				
$ impdp backup/passw0rd directory=backup dumpfile=backup.dmp

Import: Release 11.2.0.1.0 - Production on Tue Dec 1 16:32:34 2015

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
ORA-31655: no data or metadata objects selected for job
ORA-39154: Objects from foreign schemas have been removed from import
Master table "BACKUP"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "BACKUP"."SYS_IMPORT_FULL_01":  backup/******** directory=backup dumpfile=backup.dmp 
Job "BACKUP"."SYS_IMPORT_FULL_01" successfully completed at 16:32:36
				
				

66.3.4. 查看dmp文件的表空间

impdp \'/ as sysdba\' dumpfile=backup:expdp.dmp sqlfile=backup:expdp.sql

grep 'TABLESPACE' /opt/oracle/backup/expdp.sql | awk '{print $2}' | sort -u
TABLESPACE
"TS_DATA_DEF"
"TS_DATA_IDX"
UNLIMITED
			





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
SQL Oracle 关系型数据库
Oracle-数据泵expdp/impdp实操
Oracle-数据泵expdp/impdp实操
348 0
|
搜索推荐
|
Oracle 关系型数据库 数据库
IMPDP
在10g之前,传统的导出和导入分别使用EXP工具和IMP工具,从10g开始,不仅保留了原有的EXP和IMP工具,还提供了数据泵导出导入工具EXPDP和IMPDP.使用EXPDP和IMPDP时应该注意的事项: 1、EXP和IMP是客户端工具程序,它们既可以在可以客户端使用,也可以在服务端使用。
1749 0
|
关系型数据库 数据库 数据安全/隐私保护
EXPDP
OracleDatabase 10g引入了最新的数据泵(DataDump)技术,数据泵导出导入(EXPDP和IMPDP)的作用 1、实现逻辑备份和逻辑恢复. 2、在数据库用户之间移动对象. 3、在数据库之间移动对象 4、实现表空间搬移.
1407 0
|
数据库 关系型数据库 Oracle
|
存储 SQL 数据库
|
数据安全/隐私保护
|
SQL Oracle 关系型数据库