oracle 数据库备份还原 EXPDP IMPDP

一、expdp/impdp和exp/imp的区别
1、exp和imp是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用。
2、expdp和impdp是服务端的工具程序,他们只能在oracle服务端使用,不能在客户端使用。
3、imp只适用于exp导出的文件,不适用于expdp导出文件;impdp只适用于expdp导出的文件,而不适用于exp导出文件。
4、对于10g以上的服务器,使用exp通常不能导出0行数据的空表,而此时必须使用expdp导出。

二、expdp导出步骤
(1)创建逻辑目录:
   第一步:在服务器上创建真实的目录;(注意:第三步创建逻辑目录的命令不会在OS上创建真正的目录,所以要先在服务器上创建真实的目录。如下图:)
oracle 数据库备份还原 EXPDP IMPDP
  第二步:用sys管理员登录sqlplus;
oracle 数据库备份还原 EXPDP IMPDP
  第三步:创建逻辑目录;
SQL> create directory data_dir as '/home/oracle/dmp/user';
Directory created.
  第四步:查看管理员目录,检查是否存在;
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME


DIRECTORY_PATH


SYS DATA_DIR
/home/oracle/dmp/user
  第五步:用sys管理员给你的指定用户赋予在该目录的操作权限。
SQL> grant read,write on directory data_dir to user;
Grant succeeded.
(2)用expdp导出dmp,有五种导出方式:
第一种:“full=y”,全量导出数据库;
expdp user/passwd@orcl dumpfile=expdp.dmp directory=data_dir full=y logfile=expdp.log;
第二种:schemas按用户导出;
expdp user/passwd@orcl schemas=user dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
第三种:按表空间导出;
expdp sys/passwd@orcl tablespace=tbs1,tbs2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
第四种:导出表;
expdp user/passwd@orcl tables=table1,table2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
第五种:按查询条件导;
expdp user/passwd@orcl tables=table1='where number=1234' dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;

三、impdp导入步骤
(1)如果不是同一台服务器,需要先将上面的dmp文件下载到目标服务器上,具体命令参照:http://www.cnblogs.com/promise-x/p/7452972.html
(2)参照“expdp导出步骤”里的前三步,建立逻辑目录;
(3)用impdp命令导入,对应五种方式:
第一种:“full=y”,全量导入数据库;
impdp user/passwd directory=data_dir dumpfile=expdp.dmp full=y;
第二种:同名用户导入,从用户A导入到用户A;
impdp A/passwd schemas=A directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;
第三种:①从A用户中把表table1和table2导入到B用户中;
impdp B/passwdtables=A.table1,A.table2 remap_schema=A:B directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;
    ②将表空间TBS01、TBS02、TBS03导入到表空间A_TBS,将用户B的数据导入到A,并生成新的oid防止冲突;

impdp A/passwd remap_tablespace=TBS01:A_TBS,TBS02:A_TBS,TBS03:A_TBS remap_schema=B:A FULL=Y transform=oid:n
directory=data_dir dumpfile=expdp.dmp logfile=impdp.log
第四种:导入表空间;
impdp sys/passwd tablespaces=tbs1 directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;
第五种:追加数据;
impdp sys/passwd directory=data_dir dumpfile=expdp.dmp schemas=system table_exists_action=replace logfile=impdp.log;
--table_exists_action:导入对象已存在时执行的操作。有效关键字:SKIP,APPEND,REPLACE和TRUNCATE

原文:https://www.cnblogs.com/promise-x/p/7477360.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章