1
备份当前数据库
RMAN> backup database;
Starting backup at 14-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=211 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00009 name=/oracle/test/zxbig.dbf
input datafile fno=00001 name=/oracle/test/system1.dbf
input datafile fno=00003 name=/oracle/test/sysaux01.dbf
input datafile fno=00005 name=/oracle/test/zxa.dbf
input datafile fno=00008 name=/oracle/test/undotbs1.dbf
input datafile fno=00002 name=/oracle/test/zxb.dbf
input datafile fno=00007 name=/oracle/test/zxc.dbf
input datafile fno=00004 name=/oracle/test/users01.dbf
input datafile fno=00006 name=/oracle/test/test1.dbf
input datafile fno=00010 name=/oracle/test2.dbf
input datafile fno=00011 name=/oracle/test/jiujian1.dbf
channel ORA_DISK_1: starting piece 1 at 14-DEC-12
channel ORA_DISK_1: finished piece 1 at 14-DEC-12
piece handle=/oracle/app/db1/dbs/0hnssesq_1_1 tag=TAG20121214T221345 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:58
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 14-DEC-12
channel ORA_DISK_1: finished piece 1 at 14-DEC-12
piece handle=/oracle/app/db1/dbs/0inssf64_1_1 tag=TAG20121214T221345 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:06
Finished backup at 14-DEC-12
2
创建测试表
SQL> create table t5(a int) tablespace jiujian1;
Table created.
SQL> select table_name,tablespace_name from dba_tables where table_name='T5';
TABLE_NAME
TABLESPACE_NAME
------------------------------ ------------------------------
T5
JIUJIAN1
3
插入数据,切换日志,产生归档:
当前日志状态如下:
SQL> select group#,archived,sequence#,status from v$log;
GROUP# ARC SEQUENCE# STATUS
---------- --- ---------- ----------------
1 YES 2 INACTIVE
2 YES 3 INACTIVE
3 YES 1 INACTIVE
4 YES 4 INACTIVE
5 YES 5 INACTIVE
6 NO 6 CURRENT
6 rows selected.
6
号归档中的数据如下:
SQL> insert into t5 values(1);
1 row created.
SQL> insert into t5 values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
7
号归档中的数据如下:
SQL> insert into t5 values(3);
1 row created.
SQL> insert into t5 values(4);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
8
号归档中的数据如下:
SQL> insert into t5 values(6);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
9
号归档中的数据如下:
SQL> insert into t5 values(5);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
10
号归档中的数据如下:
System altered.
SQL> insert into t5 values(7);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
11
号归档中的数据如下:
SQL> insert into t5 values(8);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
12
号归档中的数据如下:
SQL> insert into t5 values(9);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
13
号归档中的数据如下:
SQL> insert into t5 values(10);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
14
号归档中的数据如下:
SQL> insert into t5 values(11);
1 row created.
SQL> insert into t5 values(12);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
15
号归档中的数据如下:
SQL> insert into t5 values(13);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into t5 values(14);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into t5 values(15);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
4
当前数据库日志状态如下:
SQL> select group#,archived,sequence#,status from v$log;
GROUP# ARC SEQUENCE# STATUS
---------- --- ---------- ----------------
1 NO 20 CURRENT
2 YES 15 INACTIVE
6 YES 18 INACTIVE
4 YES 16 INACTIVE
5 YES 17 INACTIVE
3 YES 19 INACTIVE
5
归档信息如下:
SEQUENCE#
NAME FIRST_CHANGE# NEXT_CHANGE#
----------
---------------------------------------- --------------------- --------------
2 /oracle/archive/1_2_801995401.dbf 2779672791 2779672793
3 /oracle/archive/1_3_801995401.dbf 2779672793 2779672795
4 /oracle/archive/1_4_801995401.dbf 2779672795 2779672800
5 /oracle/archive/1_5_801995401.dbf 2779672800 2779672803
1 /oracle/archive/1_1_801995401.dbf 2779649591 2779672791
6 /oracle/archive/1_6_801995401.dbf 2779672803 2779676487
7 /oracle/archive/1_7_801995401.dbf 2779676487 2779676511
8 /oracle/archive/1_8_801995401.dbf 2779676511 2779676528
9 /oracle/archive/1_9_801995401.dbf 2779676528 2779676537
10 /oracle/archive/1_10_801995401.dbf 2779676537 2779676545
11 /oracle/archive/1_11_801995401.dbf 2779676545 2779676556
12 /oracle/archive/1_12_801995401.dbf 2779676556 2779676566
13 /oracle/archive/1_13_801995401.dbf 2779676566 2779676577
14 /oracle/archive/1_14_801995401.dbf 2779676577 2779676609
15 /oracle/archive/1_15_801995401.dbf 2779676609 2779676672
16 /oracle/archive/1_16_801995401.dbf 2779676672 2779676682
17 /oracle/archive/1_17_801995401.dbf 2779676682 2779676694
18 /oracle/archive/1_18_801995401.dbf 2779676694 2779697187
19 /oracle/archive/1_19_801995401.dbf 2779697187 2779718874
二
恢复
(
模拟
8
、
9
、
10
号归档丢失
)
1
归档11
的第一个重做记录rba
地址
以及 low scn
REDO RECORD - Thread:1
RBA: 0x00000b.00000002.0010
LEN: 0x01ec VLD: 0x0d
SCN: 0x0000.a5ae7f87 SUBSCN: 3 12/14/2012 22:44:37
Low scn: 0x0000.a5ae7f81 (2779676545) 12/14/2012 22:44:21
Next scn: 0x0000.a5ae7f8c (2779676556) 12/14/2012 22:44:45
2
第一次恢复过程如下(由于丢失8
到10
号归档,所以数据文件11头部scn
只能推进到7
号归档的next scn
处)
RMAN>
restore tablespace jiujian1;
Starting restore at 16-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=210 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00011 to /oracle/test/jiujian1.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/db1/dbs/0hnssesq_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/app/db1/dbs/0hnssesq_1_1 tag=TAG20121214T221345
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 16-DEC-12
SQL>
recover tablespace jiujian1;
ORA-00279: change 2779674784 generated at 12/14/2012 22:13:47 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_6_801995401.dbf
ORA-00280: change 2779674784 for thread 1 is in sequence #6
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 2779676487 generated at 12/14/2012 22:42:00 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_7_801995401.dbf
ORA-00280: change 2779676487 for thread 1 is in sequence #7
ORA-00278: log file '/oracle/archive/1_6_801995401.dbf' no longer needed for
this recovery
ORA-00279: change 2779676511 generated at 12/14/2012 22:42:54 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_8_801995401.dbf
ORA-00280: change 2779676511 for thread 1 is in sequence #8
ORA-00278: log file '/oracle/archive/1_7_801995401.dbf' no longer needed for
this recovery
ORA-00308:
cannot open archived log '/oracle/archive/1_8_801995401.dbf'
ORA-27037:
unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
------------------------由于缺失归档恢复到此处时退出---------------------------------------------------------
SQL> select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 2779722454
2 2779722454
3 2779722454
4 2779722454
5 2779722454
6 2779722454
7 2779722454
8 2779722454
9 2779722454
10 2779722454
11 2779676511
3
通过bbed
调整数据文件11
头部的rba
值以及scn
值
RBA 调整为RBA: 0x00000b.00000002.0010
Scn 调整为 Low scn: 0x0000.a5ae7f81
[oracle@oracle ~]$ bbed parfile=bbed.para
Password: blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Sun Dec 16 20:10:04 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> set dba 11,1
DBA 0x02c00001 (46137345 11,1)
BBED> show
FILE# 11
BLOCK# 1
OFFSET 0
DBA 0x02c00001 (46137345 11,1)
FILENAME /oracle/test/jiujian1.dbf
BIFILE bifile.bbd
LISTFILE /oracle/filelist
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes
@484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0xa5ae7f5f
ub2 kscnwrp @488 0x0000
ub4 kcvcptim @492 0x2fce426e
ub2 kcvcpthr @496 0x0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0x00000008
ub4 kcrbabno @504 0x00000002
ub2 kcrbabof @508 0x0000
ub1 kcvcpetb[0] @512 0x02
ub1 kcvcpetb[1] @513 0x00
ub1 kcvcpetb[2] @514 0x00
ub1 kcvcpetb[3] @515 0x00
ub1 kcvcpetb[4] @516 0x00
ub1 kcvcpetb[5] @517 0x00
ub1 kcvcpetb[6] @518 0x00
ub1 kcvcpetb[7] @519 0x00
BBED> set offset 500
OFFSET 500
BBED> dump /v count 30
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 500 to 529 Dba:0x02c00001
-------------------------------------------------------
08000000 02000000 00000000 02000000 l ................
00000000 00000000 00000000 0000
l ..............
<16 bytes per line>
BBED> modify /x b
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 500 to 529 Dba:0x02c00001
------------------------------------------------------------------------
0b000000 02000000 00000000 02000000 00000000 00000000 00000000 0000
<32 bytes per line>
BBED> set offset +8
OFFSET 508
BBED> dump /v
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 508 to 537 Dba:0x02c00001
-------------------------------------------------------
00000000 02000000 00000000 00000000 l ................
00000000 00000000 00000000 0000
l ..............
<16 bytes per line>
BBED> modify /x 10
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 508 to 537 Dba:0x02c00001
------------------------------------------------------------------------
10000000 02000000 00000000 00000000 00000000 00000000 00000000 0000
<32 bytes per line>
BBED> set offset 500
OFFSET 500
BBED> dump /v
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 500 to 529 Dba:0x02c00001
-------------------------------------------------------
0b000000 02000000 10000000 02000000 l ................
00000000 00000000 00000000 0000
l ..............
BBED> set offset 484
OFFSET 484
BBED> dump /v
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 484 to 513 Dba:0x02c00001
-------------------------------------------------------
5f7faea5 00000000 6e42ce2f 01000000 l _.��....nB?....
0b000000 02000000 00000000 0200
l ..............
<16 bytes per line>
BBED> modify /x 81
File: /oracle/test/jiujian1.dbf (11)
Block: 1
Offsets: 484 to 513 Dba:0x02c00001
------------------------------------------------------------------------
817faea5
00000000 6e42ce2f 01000000 0b000000 02000000 00000000 0200
<32 bytes per line>
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes
@484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0xa5ae7f81
ub2 kscnwrp @488 0x0000
ub4 kcvcptim @492 0x2fce426e
ub2 kcvcpthr @496 0x0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0x0000000b
ub4 kcrbabno @504 0x00000002
ub2 kcrbabof @508 0x0010
ub1 kcvcpetb[0] @512 0x02
ub1 kcvcpetb[1] @513 0x00
ub1 kcvcpetb[2] @514 0x00
ub1 kcvcpetb[3] @515 0x00
ub1 kcvcpetb[4] @516 0x00
ub1 kcvcpetb[5] @517 0x00
ub1 kcvcpetb[6] @518 0x00
ub1 kcvcpetb[7] @519 0x00
BBED> sum apply
Check value for File 11, Block 1:
current = 0x8957, required = 0x8957
4
更改数据文件头部后第二次恢复过程如下:
SQL>
recover tablespace jiujian1;
ORA-00279: change 2779676545 generated at 12/14/2012 22:42:54 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_11_801995401.dbf
ORA-00280: change 2779676545 for thread 1 is in sequence #11
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 2779676556 generated at 12/14/2012 22:44:45 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_12_801995401.dbf
ORA-00280: change 2779676556 for thread 1 is in sequence #12
ORA-00278: log file '/oracle/archive/1_11_801995401.dbf' no longer needed for
this recovery
ORA-00279: change 2779676566 generated at 12/14/2012 22:45:09 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_13_801995401.dbf
ORA-00280: change 2779676566 for thread 1 is in sequence #13
ORA-00278: log file '/oracle/archive/1_12_801995401.dbf' no longer needed for
this recovery
ORA-00279: change 2779676577 generated at 12/14/2012 22:45:38 needed for thread
1
ORA-00289: suggestion : /oracle/archive/1_14_801995401.dbf
ORA-00280: change 2779676577 for thread 1 is in sequence #14
ORA-00278: log file '/oracle/archive/1_13_801995401.dbf' no longer needed for
this recovery
Log applied.
Media recovery complete.
日志中记录的恢复如下:
Sun Dec 16 20:16:37 2012
ALTER DATABASE RECOVER tablespace jiujian1
Sun Dec 16 20:16:37 2012
Media Recovery Start
parallel recovery started with 3 processes
ORA-279 signalled during: ALTER DATABASE RECOVER tablespace jiujian1 ...
Sun Dec 16 20:16:41 2012
ALTER DATABASE RECOVER
CONTINUE DEFAULT
Sun Dec 16 20:16:41 2012
Media Recovery Log /oracle/archive/1_11_801995401.dbf
ORA-279 signalled during: ALTER DATABASE RECOVER
CONTINUE DEFAULT ...
Sun Dec 16 20:16:41 2012
ALTER DATABASE RECOVER
CONTINUE DEFAULT
Sun Dec 16 20:16:41 2012
Media Recovery Log /oracle/archive/1_12_801995401.dbf
ORA-279 signalled during: ALTER DATABASE RECOVER
CONTINUE DEFAULT ...
Sun Dec 16 20:16:41 2012
ALTER DATABASE RECOVER
CONTINUE DEFAULT
Sun Dec 16 20:16:41 2012
Media Recovery Log /oracle/archive/1_13_801995401.dbf
ORA-279 signalled during: ALTER DATABASE RECOVER
CONTINUE DEFAULT ...
Sun Dec 16 20:16:41 2012
ALTER DATABASE RECOVER
CONTINUE DEFAULT
Sun Dec 16 20:16:41 2012
Media Recovery Log /oracle/archive/1_14_801995401.dbf
Sun Dec 16 20:16:41 2012
Recovery of Online Redo Log: Thread 1 Group 2 Seq 15 Reading mem 0
Mem# 0 errs 0: /oracle/app/db1/dbs/log2CRM.dbf
Mem# 1 errs 0: /oracle/CRM2/CRM/redo02b.log
Sun Dec 16 20:16:41 2012
Recovery of Online Redo Log: Thread 1 Group 4 Seq 16 Reading mem 0
Mem# 0 errs 0: /oracle/CRM2/CRM/redo04.log
Mem# 1 errs 0: /oracle/CRM2/CRM/redo04b.log
Sun Dec 16 20:16:41 2012
Recovery of Online Redo Log: Thread 1 Group 5 Seq 17 Reading mem 0
Mem# 0 errs 0: /oracle/CRM2/CRM/redo05.log
Mem# 1 errs 0: /oracle/CRM2/CRM/redo05b.log
Sun Dec 16 20:16:41 2012
Recovery of Online Redo Log: Thread 1 Group 6 Seq 18 Reading mem 0
Mem# 0 errs 0: /oracle/CRM2/CRM/redo06.log
Mem# 1 errs 0: /oracle/CRM2/CRM/redo06b.log
Sun Dec 16 20:16:41 2012
Recovery of Online Redo Log: Thread 1 Group 3 Seq 19 Reading mem 0
Mem# 0 errs 0: /oracle/CRM2/CRM/redo03.log
Mem# 1 errs 0: /oracle/CRM2/CRM/redo03b.log
Sun Dec 16 20:16:42 2012
Recovery of Online Redo Log: Thread 1 Group 1 Seq 20 Reading mem 0
Mem# 0 errs 0: /oracle/app/db1/dbs/log1CRM.dbf
Mem# 1 errs 0: /oracle/CRM2/CRM/redo01b.log
Sun Dec 16 20:16:42 2012
Media Recovery Complete (CRM)
Completed: ALTER DATABASE RECOVER
CONTINUE DEFAULT
recover
后表空间jiujian1
的信息如下:
数据文件/oracle/test/jiujian1.dbf
|
数据文件头部信息
|
控制文件中该数据文件信息
|
chkpt cnt: 30
Checkpointed at scn: 0x0000.a5af2789
|
Checkpoint cnt:30
Stop scn: 0x0000.a5af2789
|
控制文件中该数据文件信息如下:
DATA FILE #11:
(name #25) /oracle/test/jiujian1.dbf
creation size=128 block size=8192 status=0xe head=25 tail=25 dup=1
tablespace 21, index=11 krfil=11 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:30 scn: 0x0000.a5af278a 12/16/2012 20:05:54
Stop scn: 0x0000.a5af2789 12/16/2012 20:05:54
Creation Checkpointed at scn: 0x0000.a5ae1114 12/14/2012 06:45:04
thread:1 rba:(0xf.9.10)
数据文件头部信息如下:
V10 STYLE FILE HEADER:
Compatibility Vsn = 169869568=0xa200100
Db ID=3601019238=0xd6a33166, Db Name='CRM'
Activation ID=0=0x0
Control Seq=11951=0x2eaf, File size=128=0x80
File Number=11, Blksiz=8192, File Type=3 DATA
Tablespace #21 - JIUJIAN1 rel_fn:11
Creation
at scn: 0x0000.a5ae1114 12/14/2012 06:45:04
Backup taken at scn: 0x0000.00000000 01/01/1988 00:00:00 thread:0
reset logs count:0x2fcd7a89 scn: 0x0000.a5ae1637 reset logs terminal rcv data:0x0 scn: 0x0000.00000000
prev reset logs count:0x2fcce590 scn: 0x0000.a5adcde6 prev reset logs terminal rcv data:0x0 scn: 0x0000.00000000
recovered at 12/16/2012 20:16:49
status:0x0 root dba:0x00000000 chkpt cnt: 30 ctl cnt:29
begin-hot-backup file size: 0
Checkpointed at scn: 0x0000.a5af2789 12/16/2012 20:05:54
thread:1 rba:(0x14.795.10)
SQL>
alter database open;
Database altered.
验证如下:(可以看到仅仅丢失了8
、9
、10
号归档的数据6
、5
、7
)
SQL> select * from t5;
A
----------
1
2
3
4
8
9
10
11
12
13
14
15
12 rows selected.