环境:
OS:Red Hat Linux As 5
DB:10.2.0.4
下面我们模拟归档日志丢失后的不完全恢复.
1.备份数据库
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup database format '/u02/rman_bak/full_%u_%T.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
2.执行不完全恢复,目的是使日志复位,这里的时间点是备份集生成后的时间点.
run{
set until time "to_date('2012-07-06 21:52:00','YYYY-MM-DD HH24:MI:SS')";
restore database;
recover database;
}
使日志复位
RMAN> alter database open resetlogs;
database opened
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 0
Next log sequence to archive 1
Current log sequence 1
3.再次备份数据,用来模拟日志丢失后的恢复
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup database format '/u02/rman_bak/full_%u_%T.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
4.模拟数据
SQL>connect scott/scott
SQL> create table tb_test
(
id number,
remark varchar2(30),
create_time date default sysdate
);
Table created.
SQL>connect / as sysdba
写入第一条记录,并生成归档日志1
SQL>insert into scott.tb_test values(1,'第一次切换',sysdate);
SQL>commit;
SQL>alter system switch logfile;
这个时候会生成归档日志1
[oracle@hxl 2012_07_06]$ ls
o1_mf_1_1_7zfx44j4_.arc
写入第二条记录,并生成归档日志2
SQL>insert into scott.tb_test values(2,'第二次切换',sysdate);
SQL>commit;
SQL>alter system switch logfile;
这个时候会生成归档日志2
[oracle@hxl 2012_07_06]$ ls -1
o1_mf_1_1_7zfx44j4_.arc
o1_mf_1_2_7zfxmbq9_.arc
写入第三条记录,并生成归档日志3
SQL>insert into scott.tb_test values(3,'第三次切换',sysdate);
SQL>commit;
SQL>alter system switch logfile;
这个时候会生成归档日志3
[oracle@hxl 2012_07_06]$ ls -1
o1_mf_1_1_7zfx44j4_.arc
o1_mf_1_2_7zfxmbq9_.arc
o1_mf_1_3_7zfy5jnz_.arc
写入第四条记录,并生成归档日志4
SQL>insert into scott.tb_test values(4,'第四次切换',sysdate);
SQL>commit;
SQL>alter system switch logfile;
这个时候会生成归档日志4
[oracle@hxl 2012_07_06]$ ls -1
o1_mf_1_1_7zfx44j4_.arc
o1_mf_1_2_7zfxmbq9_.arc
o1_mf_1_3_7zfy5jnz_.arc
o1_mf_1_4_7zfyth7x_.arc
5.我们使用不完全恢复恢复生成归档日志的时间点,记录该时间点'2012-07-06 22:50:00'
[oracle@hxl 2012_07_06]$ ls -al
total 14264
drwxr-x--- 2 oracle oinstall 4096 Jul 6 22:50 .
drwxr-x--- 11 oracle oinstall 4096 Jul 6 21:52 ..
-rw-r----- 1 oracle oinstall 9038848 Jul 6 22:21 o1_mf_1_1_7zfx44j4_.arc
-rw-r----- 1 oracle oinstall 5408256 Jul 6 22:30 o1_mf_1_2_7zfxmbq9_.arc
-rw-r----- 1 oracle oinstall 41984 Jul 6 22:39 o1_mf_1_3_7zfy5jnz_.arc
-rw-r----- 1 oracle oinstall 45568 Jul 6 22:50 o1_mf_1_4_7zfyth7x_.arc
6.模拟删除归档日志2和3,这里我是迁移到上级目录
[oracle@hxl 2012_07_06]$ mv o1_mf_1_2_7zfy5jnz_.arc ../
[oracle@hxl 2012_07_06]$ mv o1_mf_1_3_7zfy5jnz_.arc ../
7.执行不完全恢复
RMAN> shutdown immediate
RMAN> startup mount
run{
set until time "to_date('2012-07-06 22:50:00','YYYY-MM-DD HH24:MI:SS')";
restore database;
recover database;
}
恢复的过程中提示日志2和日志3找不到.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/06/2012 23:03:40
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 1 seq 3 lowscn 1543276 found to restore
RMAN-06025: no backup of log thread 1 seq 2 lowscn 1542333 found to restore
这个时候我们只能使用丢失的归档日志前的日志进行恢复.
RMAN>recover database until sequence=2 thread=1
RMAN> alter database open resetlogs;
查看表数据恢复情况
SQL> select * from scott.tb_test;
ID REMARK CREATE_TI
---------- ------------------------------ ---------
1 第一次切换 06-JUL-12
可以看出,只能恢复记录1,因为应用了归档日志1,日志2和日志3已经丢失,虽然日志4是存在的,但日志2和日志3丢失,导致日志中断,无法恢复中断日志后的日志.日志的连续性可以看作是一根生命线,中间某个日志中断了,生命线也就中断了,不完全恢复应用的日志只能应用到未中断前的日志.
说明:
通常不完全恢复有如下几种:
1.基于日志序列的不完全恢复,上面的例子就是基于序列的不完全恢复
2.基于推出的不完全恢复recover database until cancel,这种恢复会一直应用归档日志,直到丢失的归档.
先选择auto后选择cancel
-- The End --
阅读(4923) | 评论(0) | 转发(1) |