相关阅读: Oracle手工完全恢复案例(归档模式)
案例一:历史日志没有被覆盖1.首先把数据库切成非归档模式:
startup mountforce
alter database noarchivelog;
alter database open;
再次查看数据库模式
sys@SIQIAN11>archive log list
Database log mode No Archive Mode
Automaticarchival Disabled
Archivedestination /backup/arch
Oldest online log sequence 15
Current log sequence 17
2.冷备
3.查看当前日志信息
sys@SIQIAN11>select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
-------------------- --- ----------------
1 19 NO CURRENT
2 17 NO INACTIVE
3 18 NO INACTIVE
4.用test用户登录建表插入数据
test@SIQIAN11>create table t01(id int) tablespace test;
test@SIQIAN11>begin
2 for i in 1..10
3 loop
4 insert into t01 values(i);
5 end loop;
6 end;
7 /
commit;
再次查看当前日志
sys@SIQIAN11>select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ------------- ----------------
1 19 NO CURRENT
2 17 NO INACTIVE
3 18 NO INACTIVE
说明这次变化记录在了第1组日志中,此时日志没有被覆盖。
5.关库删除数据文件
shutdown abort
[oracle@siqian siqian11g]$ rm -f /u01/oradata/siqian11g/test01.dbf
6.起库并查看要恢复的数据文件
startup
出错:
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/oradata/siqian11g/test01.dbf'
查看要恢复的数据文件
sys@SIQIAN11>select file#,error from v$recover_file;
FILE# ERROR
---------- -----------------------------------------------------------------
1 UNKNOWNERROR
2 UNKNOWNERROR
3 UNKNOWNERROR
4 UNKNOWNERROR
5 UNKNOWNERROR
6 FILE NOT FOUND
6 rows selected.
7.还原数据文件并做恢复
[oracle@siqian siqian11g]$ cp /backup/cold/test01.dbf /u01/oradata/siqian11g/
sys@SIQIAN11>recover datafile 6;
Media recoverycomplete.
sys@SIQIAN11>alter database open;
8.验证
sys@SIQIAN11>select * from test.t01;
ID
----------
1
2
3
4
5
6
7
8
9
10
10 rows selected.
案例二:日志发生切换,历史日志被覆盖(只能作不完全恢复)承接上面的例子,这次做完一些操作后切日志使其切换。
模拟环境:
1.test用户登录再在t01表中插入若干数据
test@SIQIAN11>begin
2 for i in 11..20
3 loop
4 insert into t01 values(i);
5 end loop;
6 end;
7 /
PL/SQL procedure successfully completed.
commit;
2.查看当前日志信息
sys@SIQIAN11>select group#,sequence#,archived,first_change# from v$log;
GROUP# SEQUENCE# ARC FIRST_CHANGE#
-------------------- --- -------------
1 19 NO 2200111
2 20 NO 2225498
3 18 NO 2179197
也就是说刚才的变化记录在了第1组中
3.切换日志,使其被覆盖
alter system switch logfile;
多切几次然后再次查看:
sys@SIQIAN11>select group#,sequence#,archived,first_change# from v$log;
GROUP# SEQUENCE# ARC FIRST_CHANGE#
---------- ------------- -------------
1 22 NO 2226207
2 23 NO 2226211
3 21 NO 2226205
现在序列19已经被覆盖。
而且t01表中有20条记录。
4.关库删除相应的数据文件
shutdown abort
[oracle@siqian siqian11g]$ rm -f /u01/oradata/siqian11g/test01.dbf
5.起库并查看要恢复的数据文件
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: '/u01/oradata/siqian11g/test01.dbf'
sys@SIQIAN11>select file#,error from v$recover_file;
FILE# ERROR
---------------------------------------------------------------------------
1 UNKNOWN ERROR
2 UNKNOWN ERROR
3 UNKNOWN ERROR
4 UNKNOWN ERROR
5 UNKNOWN ERROR
6 FILE NOT FOUND
6 rows selected.