最近讨论恢复的贴子好多,所以我也拿个出来讨论讨论,恢复的场景是:误操作删除表,并且控制文件也被损坏了,讨论只是为了彻底搞懂内部原量,避免下次犯同样的错误!
下面是我详细的实验步骤:
第一步:恢复过程通过观察用户gyj下的T1表,有一行数据。
idle> conn gyj/gyj Connected.
gyj@OCM> select * from t1;
ID NAME
---------- ----------------------------------------------------------------------------------------------------
1 BBBBBBBB
第二步:正常关闭数据库,做全库的冷备
gyj@OCM> conn / as sysdba
Connected.
sys@OCM> select * from v$dbfile;
FILE# NAME
---------- -------------------------------
6 /u01/app/oracle/oradata/ocm/undotbs01.dbf
5 /u01/app/oracle/oradata/ocm/example01.dbf
3 /u01/app/oracle/oradata/ocm/tp1.dbf
2 /u01/app/oracle/oradata/ocm/sysaux01.dbf
1 /u01/app/oracle/oradata/ocm/system01.dbf
4 /u01/app/oracle/oradata/ocm/tp2.dbf
6 rows selected.
sys@OCM> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@ocm ~]$ cp -rf /u01/app/oracle/oradata/ocm/* /backup/cold/
第三步:启动库,登录用户gyj,向T1表中插入一条数据
sys@OCM> startup
ORACLE instance started.
Total System Global Area 581750784 bytes
Fixed Size 1337860 bytes
Variable Size 243271164 bytes
Database Buffers 314572800 bytes
Redo Buffers 22568960 bytes
Database mounted.
Database opened.
sys@OCM> conn gyj/gyj
Connected.
gyj@OCM> insert into t1 values(2,'AAAAAAA');
1 row created.
gyj@OCM> commit;
Commit complete.
第四步:查当前数据库系统时间
gyj@OCM> select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2013-05-01:20:11:39
第五步:再查一条数据到T1表
gyj@OCM> insert into t1 values(3,'CCCCCCCCC');
1 row created.
gyj@OCM> commit;
Commit complete.
第六步:模拟用户误操作,做了drop,把不该drop的T1表给干掉了!!!!
gyj@OCM> drop table t1;
Table dropped.
第七步:假设我的控制文件这时也损坏了
[oracle@ocm ocm]$ rm -rf control0*
第八步:数据库过会马上就宕机
sys@OCM> shutdown abort;
ORACLE instance shut down.
第九步:假设我现在要做不完全恢复,而且我做基于时间的不完全恢复,恢复到2013-05-01:20:11:39
预期的结果,不完全恢复后表里面应该是两条记录:
gyj@OCM> select * from t1;
ID NAME
---------- ----------------------------------------------------------------------------------------------------
1 BBBBBBBB
2 AAAAAAA
第十步:开始恢复
(1)还原控制文件
[oracle@ocm ~]$ cp /backup/cold/*.ctl /u01/app/oracle/oradata/ocm/
(2)还原数据文件
[oracle@ocm ~]$ cp /backup/cold/*.dbf /u01/app/oracle/oradata/ocm/
(3)启动数据库到mount
sys@OCM> startup mount;
ORACLE instance started.
Total System Global Area 581750784 bytes
Fixed Size 1337860 bytes
Variable Size 243271164 bytes
Database Buffers 314572800 bytes
Redo Buffers 22568960 bytes
Database mounted.
(4)不完全恢复
sys@OCM> recover database until time '2013-05-01:20:11:39';
Media recovery complete.
(5)用resetlogs打开数据库
sys@OCM> alter database open resetlogs;
Database altered.
第十一步:验证T1表的结果是不是两条记录
sys@OCM> conn gyj/gyj
Connected.
gyj@OCM> select * from t1;
ID NAME
---------- ----------------------------------------------------------------------------------------------------
1 BBBBBBBB
只有一条记录,这是什么情况呢???????????
问题应该出在第十步:开始恢复的(4)不完全恢复这一步,如果在这步的恢复命令改为:
recover database until time '2013-05-01:20:11:39' using backup controlfile;
就可以了,但为啥Oracle这里不提示错误呢,在用户管理下对备份的控制文件做恢复应该必须加using backup controlfile.
但我这里没加using backup controlfile为啥没提示你加呢,恢复照样成功,但结果不是你想要的!!!