码迷,mamicode.com
首页 > 数据库 > 详细

Oracle_逻辑备份--笔记

时间:2015-01-16 20:49:34      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:

 Oracle逻辑备份的概念:
 
逻辑备份就是创建数据库对象的逻辑拷贝并存入一个二进制转储文件:.dmp文件
这些记录的导出与其物理位置无关 
导入的实质就是读取被导出的二进制转储文件并将其恢复到数据库
这里讲expdp/impdp导入导出,也将实例Data pump(即expdp/impdp的使用方法)。
 
 
使用数据泵导出时,如果不是直接导出到远程数据库中,而是首先创建目录对象
目录对象是数据库服务器上的命名目录位置。
 
1.创建对象目录:
  1.1window下:
SQL>create directory pbdir as ‘f:\datadump‘;
  1.2linux下:
SQL>create directory pbdir as ‘/oracle/datapump/dumps‘;
 
2.为目录对象授权。 
SQL>grant read,write on directory pbdir to pd;
--对具体的用户授权。
SQL>grant read,write on directory pbdir to public;
--将目录对象设置为公共读写。
 
3.选择导出的方式、
导出的方式有四种:
1、数据库方式:整个数据库导出到dump文件中。
2.用户方式:导出一个或多个用户下的所有数据。
3、表方式:导出表数据。
4、表空间方式:导出表空间数据以及与其相关的对象。
 
 
3.1数据库导出方式:--需要exp_full_database权限。
  3.1.1window下:
c:> expdp system/passwd directory=pbdir dumpfile=alldb.dmp full=y
 
  3.1.2linux下:
$ expdp system/passwd directory=pbdir dumpfile=alldb.dmp full=y
 
 
参数的解释:
system/passwd    ---用户与密码。
directory        ---导出数据的目录。
dumpfile         ---转储文件的名称。
full=y           ---表示是完全数据库备份。
 
 
3.2用户导出方式:
 3.2.1 window
c:> expdp system/passwd directory=pbdir dumpfile=pd.dmp schemas=pd
 
 3.2.2 linux
$ expdp system/passwd directory=pbdir dumpfile=pd.dmp schemas=pd
 
 说明:用户方式,用schemas代替full,如果要多个用户备份,则用逗号隔开。
 
 
3.3表的导出方式:
 3.3.1 window
c:> expdp system/passwd directory=pbdir dumpfile=pd_table.dmp tables=person,student
   nolofile=y content=data_only
 
 3.3.2 linux
$ expdp system/passwd directory=pbdir dumpfile=pd_table.dmp tables=person,student
   nolofile=y content=data_only
 
参数说明:
 nologfile=y   --不会吧操作日志写入磁盘。
 content=data_only     --只导出表中数据,不会导出元数据(?)
 content=metadata_only  ---只导出元数据,不导出数据。
 如果不写此参数,两者兼得。
 
 
 
 
3.4表空间方式
 3.4.1 window
c:> expdp system/passwd directory=pbdir dumpfile=person_ts.dmp tablespace=tablespace_list
  
 
 3.4.2 linux
$ expdp system/passwd directory=pbdir dumpfile=person_ts.dmp tablespace=tablespace_list
 
参数说明:
tablespace=tablespace_list 指定要导出的表空间。
 
 
 
 
3.5.1 实验--以备份表为例。
 
 
手动在在F盘建立目录oracledump;
 
--这段代码只是在Oracle申明备份路径,操作系统中还未真正建立此目录,需要手动建立目录。
SQL> create directory dpdir as ‘F:\oracledump‘;
目录已创建。
 
--把备份目录授权给scott.接下来便是备份Scott用户的表。
SQL> grant read,write on directory dpdir to scott;
授权成功。
 
SQL> exit
 
---导出的代码。(scott/tiger 用户与密码,directory 导出数据的目录,dumpfile 导出文件的名称,tables 导出表的名称)
 
C:\>expdp scott/tiger directory=dpdir dumpfile=tab.dmp tables=dept,emp
 
Export: Release 12.1.0.1.0 - Production on 星期三 12月 3 11:46:02 2014
 
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
 
连接到: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=dpdir dumpfile=tab.dmp tables=dept,emp
正在使用 BLOCKS 方法进行估计...
......
 
----删掉emp,dept表,为实验需要。
SQL> drop table scott.emp;
 
表已删除。
 
SQL> drop table scott.dept;
 
表已删除。
 
 
---导入备份数据。参数意义与导出一样。
C:\>impdp scott/tiger directory=dpdir dumpfile=tab.dmp tables=dept,emp
 
Import: Release 12.1.0.1.0 - Production on 星期三 12月 3 11:48:22 2014
 
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
 
连接到: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
已成功加载/卸载了主表 "SCOTT"."SYS_IMPORT_TABLE_01"
 
 
 
另--重定义对象目录语句如下:
SQL>create or replace directory dumpdir as ‘E:\oracledump‘;
 
 
 
 
 
 
 
 
 
 4、逻辑备份之EXPDP/IMPDP
使用数据泵(Data Dump)导出/导入包括4种方式:导出表、导出方案、导出表空间、导出数据库。
 
 
(1)导出表
在E盘建立目录oracledump;
SQL> CREATE DIRECTORY dump_dir AS ‘E:\oracledump‘;
SQL> GRANT READ,WRITE ON DIRECTORY dump_dir TO scott;
E:\>expdp scott/tiger DIRECTORY=dump_dir DUMPFILE=tab.dmp TABLES=dept,emp
导入表:
SQL> drop table scott.emp;
SQL> drop table scott.dept;
E:\>impdp scott/tiger directory=dump_dir dumpfile=tab.dmp tables=dept,emp
 
 
(2)导出方案:
E:\>expdp scott/tiger DIRECTORY=dump_dir DUMPFILE=schemaScott.dmp SCHEMAS=‘SCOTT‘;
导入方案:
SQL> drop user scott cascade;
SQL> create user scott identified by tiger;
SQL> grant dba to scott;
E:\>impdp system/oracle directory=dump_dir dumpfile=schemaScott.dmp schemas=scott
 
 
 
(3)导出表空间:
E:\>expdp system/oracle directory=dump_dir dumpfile=tablespaceUsers.dmp ESTIMATE_ONLY
导入表空间:
impdp system/oracle directory=dump_dir dumpfile=tablespaceUsers.dmp tablespaces=users
 
 
 
(4)导出数据库:
E:\>expdp system/oracle directory=dump_dir dumpfile=database.dmp FULL=Y
导入数据库:
impdp system/oracle directory=dump_dir dumpfile=database.dmp FULL=Y 
 
 
SQL>create or replace directory dumpdir as ‘/gxuorcl/dumpfiles‘;
 
 

Oracle_逻辑备份--笔记

标签:

原文地址:http://www.cnblogs.com/yzhl/p/4226876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!