这是有声音的视频, 请检查播放器,耳机或者音箱 声音输出设备
教程使用 Oracle 11g Release 2 版本
数据存储中, 有时会遇到数据丢失的情况,我们就需要定期做一个数据备份的工作。
在oracle中,使用EXP程序导出数据到文件进行备份, 而使用IMP就可以进行恢复。
EXP可以导出一个数据库, 也可以指定导出数据库的某个对象相关信息,
例如:数据表,表的某一列,或者表的相关信息。
===========================================
CREATE TABLE xue_sheng( id integer, xing_ming varchar(25));
INSERT INTO xue_sheng VALUES(1,'ZhanSan');
INSERT INTO xue_sheng VALUES(2,'LiSi');
COMMIT;
----------------------------------------------
下面开始进行备份: (备份学生表里的全部数据)
[oracle@localhost ~]$ exp scott/tiger <- 这里输入账号
Export: Release 11.2.0.1.0 - Production on Thu Jul 15 05:30:10 2010
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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Enter array fetch buffer size: 4096 > 4096 <-这里是缓冲区大小, 默认4096
Export file: expdat.dmp > mydata.dmp <-输入备份文件名字,默认名字expdat.dmp
(2)U(sers), or (3)T(ables): (2)U > T <- 因为我要备份表,所以选择T
Export table data (yes/no): yes > yes <- 是否导出表中的数据
Compress extents (yes/no): yes > yes <- 是否对数据进行压缩
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > xue_sheng <-输入备份的表名字
. . exporting table XUE_SHENG 2 rows exported <-导出提示信息
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > <- 退出就直接回车
Export terminated successfully without warnings.
[oracle@localhost ~]$
如果刚才没有指定备份文件的具体路径,备份文件mydata.dmp就会在当前目录下
[oracle@localhost ~]$ ls my*
mydata.dmp
=======================================
先把xue_sheng 表的数据全部删除
[oracle@localhost ~]$ sqlplus scott/tiger
SQL> select * from xue_sheng;
SQL> delete from xue_sheng;
SQL> commit;
SQL> select * from xue_sheng;
SQL> exit;
下面使用 IMP 进行数据恢复
[oracle@localhost ~]$ imp scott/tiger
Import: Release 11.2.0.1.0 - Production on Thu Jul 15 05:54:32 2010
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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Import data only (yes/no): no > yes
Import file: expdat.dmp > mydata.dmp
Enter insert buffer size (minimum is 8192) 30720>
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no >
Ignore create error due to object existence (yes/no): no >
Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no > yes
. importing SCOTT's objects into SCOTT
. . importing table "XUE_SHENG" 2 rows imported
Import terminated successfully with warnings.
[oracle@localhost ~]$
---------------------------------
验证一下数据是否被恢复
[oracle@localhost ~]$ sqlplus scott/tiger
SQL> select * from xue_sheng;
============================================
还有拷贝文件的备份方式
例如将 /u01/oradata/wilson 目录下的所有文件拷贝到其他地方
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
=================
总结一下: 主要是讲解 EXP 和 IMP 这2个的用法, 视频就到这里结束了, 谢谢观看。88
12月 8th, 2011 at 14:35:54 #匿名
这些教程对我们这些初学者真的真的非常有用啊,谢谢站主~~~
[回复]