ITPub博客

首页 > 数据库 > Oracle > expdp / impdp

expdp / impdp

原创 Oracle 作者:diashad 时间:2014-09-25 07:56:27 0 删除 编辑
同样的有交互模式/命令行模式/参数文件模式。

	1.导出表
		Expdp scott/tiger DIRECTORY=dump_dir DUMPFILE=tab.dmp TABLES=dept,emp
	2.导出方案(默认模式)
		Expdp scott/tiger DIRECTORY=dump_dir DUMPFILE=schema.dmp
		SCHEMAS=system,scott
	3.导出表空间 
		Expdp system/manager DIRECTORY=dump_dir DUMPFILE=tablespace.dmp
		TABLESPACES=user01,user02
	4. 传输表空间
		# 需指定TRANSPORT_TABLESPACES 参数,表空间内的object必须是独立的
		# Unlike tablespace mode, transportable tablespace mode requires that the specified tables be completely self-contained. That is, the partitions of all tables in the set must also be in the set.
		# You cannot export transportable tablespaces and then import them into a database at a lower release level. The target database must be at the same or higher release level as the source database.	
		
	5. 导出数据库
		Expdp system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=Y
		需EXP_FULL_DATABASE role

使用数据泵的一些限制条件:
	1.oracle 10g 才能使用
	2.expdp / impdp 两个工具只在server端提供!

	SELECT * FROM ALL_DIRECTORIES;
	create directory MY_DIR as '/home/oracle';
		# 若不创建,第一次运行expdb会创建 DATA_PUMP_DIR /u01/app/oracle/product/10g/rdbms/log/
	grant read,write on DIRECTORY MY_DIR to scott;
	select PRIVILEGE,TABLE_NAME from dba_tab_privs where GRANTEE='SCOTT';

只导出对象定义(METADATA_ONLY)
	expdp parfile=/home/oracle/expdp.txt
	----------------------------
	USERID=scott/tiger
	DIRECTORY=MY_DIR
	job_name=pump_tab_e
	CONTENT=METADATA_ONLY
	DUMPFILE=e.dmp
	TABLES=emp

只导出对象数据(DATA_ONLY)
	expdp parfile=/home/oracle/expdp.txt
	----------------------------
	USERID=scott/tiger
	DIRECTORY=MY_DIR
	job_name=pump_tab_e
	CONTENT=DATA_ONLY
	DUMPFILE=e2.dmp
	TABLES=emp

	impdp parfile=/home/oracle/impdp.txt
	----------------------------
	userid=scott/tiger 
	DIRECTORY=MY_DIR 
	DUMPFILE=e2.dmp
	TABLES=emp

导出对象定义和数据(all)
	EXPDP parfile=/home/oracle/expdp.txt
	----------------------------
	USERID=scott/tiger
	DIRECTORY=MY_DIR
	job_name=pump_tab_e
	CONTENT=all
	DUMPFILE=e.dmp
	TABLES=e,d

	impdp parfile=/home/oracle/impdp.txt
	----------------------------
	userid=scott/tiger 
	DIRECTORY=MY_DIR 
	DUMPFILE=E.DMP

导出用户所有数据(连接的用户)
	expdp parfile=/home/oracle/expdp.txt
	----------------------------
	USERID=scott/tiger
	DIRECTORY=MY_DIR
	job_name=pump_tab_e
	CONTENT=all
	DUMPFILE=scott.dmp

导出用户所有数据(指定用户,并行模式)
	expdp parfile=/home/oracle/expdp.txt
	----------------------------
	USERID=system/oracle
	DIRECTORY=MY_DIR
	PARALLEL=2
	job_name=pump_tab_e
	CONTENT=all
	DUMPFILE=scott.dmp
	schemas=scott

	-----------------------------------------------------
	include/exclude 例子:
	include=table:"in('DB','TS')"
	或者include=table:"like '%E%'"
	或者include=function,package,procedure,table:"='EMP'"
	或者exclude=SEQUENCE,TABLE:"IN ('EMP','DEPT')"

	expdp parfile=/home/oracle/expdp.txt
	-----------------------------------------------------
	USERID=scott/tiger
	DIRECTORY=MY_DIR
	job_name=pump_tab_e
	CONTENT=all
	DUMPFILE=e.dmp
	include=table:"like 'E%'"
	------------------------------------------------------

将scott的数据复制到u1用户
	grant connect,resource to u1 identified by u1;

	create public database link link_local_system connect to system
	identified by oracle using 'orcl';

	impdp system/oracle network_link=link_local_system schemas=scott remap_schema=scott:u1
	-----------------------------------------------------
	在18节点使用数据泵导出248节点数据:
	conn / as sysdba

	create public database link link248 connect to scott
	identified by scott using '248';

	expdp scott/tiger schemas=scott directory=my_dir network_link=link248 dumpfile=exp_scott.dmp logfile=exp_scott.log

	impdp userid=scott/tiger directory=my_dir dumpfile=exp_scott.dmp

##################################################
expdp/impdp job
[oracle@10g admin]$ expdp scott/tiger schemas=scott dumpfile=a.dmp directory=tmp job_name=abc
[oracle@10g admin]$ expdp attach=abc

Export: Release 10.2.0.1.0 - 64bit Production on Friday, 23 March, 2012 16:20:01

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

Username: scott
Password: 

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

Job: ABC
  Owner: SCOTT                          
  Operation: EXPORT                         
  Creator Privs: FALSE                          
  GUID: BBE5ACE1914E586BE040A8C0541E6060
  Start Time: Friday, 23 March, 2012 16:18:54
  Mode: SCHEMA                         
  Instance: orcl
  Max Parallelism: 1
  EXPORT Job Parameters:
  Parameter Name      Parameter Value:
     CLIENT_COMMAND        scott/******** schemas=scott dumpfile=a.dmp directory=tmp job_name=abc 
  State: EXECUTING                      
  Bytes Processed: 0
  Current Parallelism: 1
  Job Error Count: 0
  Dump File: /home/oracle/backup/a.dmp
    bytes written: 4,096
  
Worker 1 Status:
  State: EXECUTING                      
  Object Schema: SCOTT
  Object Name: DEPT
  Object Type: SCHEMA_EXPORT/TABLE/TABLE
  Completed Objects: 1
  Worker Parallelism: 1

Export> kill_job
Are you sure you wish to stop this job ([yes]/no): yes

stoped impdp/expdp job会在dba_datapump_jobs中留下一条记录,显示为not running.
清除stopped job分两种情况:
1) job能够attach
如果job能够attach, 则可以attach后再kill job.
如:expdp system/**** attach=SYS_EXPORT_TABLE_01
        kill_job

2) job无法attach
如果job无法attach, 则需要删除连接DataPump的用户下的master table.
如:conn system/*****
        drop table SYS_EXPORT_TABLE_01 (master table名称一般与job name相同)

以上的用户名和job name都可以从dba_datapump_jobs中得到。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/203348/viewspace-1280104/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: exp / imp
请登录后发表评论 登录
全部评论

注册时间:2011-08-08

  • 博文量
    86
  • 访问量
    472944