测试环境:
sys@OCM> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
下面是我详细的实验步骤:
第一步:恢复过程通过观察用户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为啥没提示你加呢,恢复照样成功,但结果不是你想要的!!!
同样的实验,我再重复做一遍,可以直接搞定!!!!
区别就在:
第十步:开始恢复
4)不完全恢复 sys@OCM> recover database until time '2013-05-01:20:11:39' using backup controlfile;
多加了using backup controlfile,恢复出来的结果就是我想要的了。
开始实验:
第一步:恢复过程通过观察用户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:43:41
第五步:再查一条数据到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 ~]$ cd /u01/app/oracle/oradata/ocm/
[oracle@ocm ocm]$ rm -rf control0*
第八步:数据库过会马上就宕机
sys@OCM> shutdown abort;
ORACLE instance shut down.
第九步:假设我现在要做不完全恢复,而且我做基于时间的不完全恢复,恢复到2013-05-01:20:43:41
预期的结果,不完全恢复后表里面应该是两条记录:
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:43:41' using backup controlfile;
ORA-00279: change 27740297 generated at 05/01/2013 20:38:21 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_1_814307175.dbf
ORA-00280: change 27740297 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log '/u01/app/oracle/arch/1_1_814307175.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
sys@OCM> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
1 1 1 52428800 512 1 NO CURRENT 27739253 2013-05-01 20:26:15 2.8147E+14
3 1 0 52428800 512 1 YES UNUSED 0 0
2 1 0 52428800 512 1 YES UNUSED 0 0
sys@OCM> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
3 ONLINE /u01/app/oracle/oradata/ocm/redo03.log NO
2 ONLINE /u01/app/oracle/oradata/ocm/redo02.log NO
1 ONLINE /u01/app/oracle/oradata/ocm/redo01.log NO
sys@OCM> recover database until time '2013-05-01:20:43:41' using backup controlfile;
ORA-00279: change 27740297 generated at 05/01/2013 20:38:21 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/arch/1_1_814307175.dbf
ORA-00280: change 27740297 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/ocm/redo01.log
Log applied.
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
2 AAAAAAA
结果是我所预期的,正是两条记录。。。。。
虽然我知道是这么做是没错的!!!!!!!!但我把这个实验拿出来的目的是想和大家一起讨论一下!
SQL>recover database using backup controlfile;
该命令用来对所有数据文件及控制文件进行恢复,并且只使用保存在文件系统上的归档及在线日志。
为啥我把控制文件做了还原(COPY),在用户管理下做恢复控制文件时不报错呢?难道是11G版本的原因?一般会有提示:要加using the backup controlfiel;子句。
如下提示:
sys@OCM> recover database;
ORA-00283: recovery session canceled due to errors
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done
但本次不完全恢复的实验没提示以上的错语,容易误导我以为恢复成功,结果恢复的结果不对。。。。有点意思!!!!!!!!!!!!