[20160405]bbed修改文件头.txt

[20160405]bbed修改文件头.txt

--以前做过一次,重复测试:
http://blog.itpub.net/267265/viewspace-746222/

如果数据库数据文件损坏,并且archivelog损坏,这样无法完全恢复,如果仅仅某个数据文件的scn与其他文件不同步,导致该数据文件无法mount.
正常可以像odu之类的工具恢复.但是在实际上如果修改数据文件的scn保持同步,这样数据库可以正常打开,选择常规的方法imp/exp以及expdp/impdp
方式恢复,这样虽然丢失一部分数据,至少一定程度减少损失.

--以前测试有点乱.

1.环境:
--冷备份数据库:

$ cp tea01.dbf tea01.dbf_ORG

 

SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name BOOK

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    770      SYSTEM               ***     /mnt/ramdisk/book/system01.dbf
2    1580     SYSAUX               ***     /mnt/ramdisk/book/sysaux01.dbf
3    1435     UNDOTBS1             ***     /mnt/ramdisk/book/undotbs01.dbf
4    500      USERS                ***     /mnt/ramdisk/book/users01.dbf
5    346      EXAMPLE              ***     /mnt/ramdisk/book/example01.dbf
6    100      SUGAR                ***     /mnt/ramdisk/book/sugar01.dbf
7    1        TEA                  ***     /mnt/ramdisk/book/tea01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    400      TEMP                 32767       /mnt/ramdisk/book/temp01.dbf

SYS@book> select * from scott.empx where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 YYYY       CLERK           7902 1980-12-17 00:00:00        800                    20

SYS@book> update scott.empx set ename='ZZZZ' where EMPNO=7369;
1 row updated.

SYS@book> commit ;
Commit complete.

alter system archive log current ;
/
/
/

2.假设现在数据库破坏,tea文件仅仅存在旧的备份,看看是否online看看.
SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

$ cp tea01.dbf tea01.dbf_0405
$ mv tea01.dbf_ORG tea01.dbf

--模拟归档丢失.
$ cd /u01/app/oracle/archivelog/
$ mv book book.xxx
$ mkdir book

3.测试:

SYS@book> startup
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'

--都是归档,无法恢复.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ----------------
    1        13227502431 2016-04-05 11:33:18                7       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227502431 2016-04-05 11:33:18             1834       13227286650 ONLINE              1004 NO  /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227502431 2016-04-05 11:33:18           923328       13227286650 ONLINE               924 NO  /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227502431 2016-04-05 11:33:18            16143       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/users01.dbf    USERS
    5        13227502431 2016-04-05 11:33:18           952916       13227286650 ONLINE               921 NO  /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227502431 2016-04-05 11:33:18          1314508       13227286650 ONLINE               937 NO  /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227500866 2016-03-31 08:53:17      13227207527       13227286650 ONLINE                25 NO  /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

SYS@book> @ &r/10to16 13227502431
10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146bab5f 0x5fab6b14-03000000

SYS@book> @ &r/10to16 13227500866
10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146ba542 0x42a56b14-03000000

BBED> p kcvfh.kcvfhckp.kcvcpscn.kscnbas dba 7,1
ub4 kscnbas                                 @484      0x146ba542

BBED> p kcvfh.kcvfhckp.kcvcpscn.kscnbas dba 1,1
ub4 kscnbas                                 @484      0x146bab5f

BBED> assign dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas = dba 1,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas;
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
ub4 kscnbas                                 @484      0x146bab5f

BBED> sum apply dba 7.1
BBED-00205: illegal or out of range DBA (File 0, Block 7)

BBED> sum apply dba 7,1
Check value for File 7, Block 1:
current = 0x0b12, required = 0x0b12

BBED> verify dba 7,1
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/tea01.dbf
BLOCK = 1


DBVERIFY - Verification complete

Total Blocks Examined         : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing   (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing   (Index): 0
Total Blocks Empty            : 0
Total Blocks Marked Corrupt   : 0
Total Blocks Influx           : 0
Message 531 not found;  product=RDBMS; facility=BBED

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ---------------
    1        13227502431 2016-04-05 11:33:18                7       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227502431 2016-04-05 11:33:18             1834       13227286650 ONLINE              1004 NO  /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227502431 2016-04-05 11:33:18           923328       13227286650 ONLINE               924 NO  /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227502431 2016-04-05 11:33:18            16143       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/users01.dbf    USERS
    5        13227502431 2016-04-05 11:33:18           952916       13227286650 ONLINE               921 NO  /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227502431 2016-04-05 11:33:18          1314508       13227286650 ONLINE               937 NO  /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227502431 2016-03-31 08:53:17      13227207527       13227286650 ONLINE                25 NO  /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

SYS@book> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'


SYS@book> recover datafile 7 ;
Media recovery complete.
SYS@book> alter database open ;
Database altered.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                            TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------- ---------------
    1        13227502434 2016-04-05 11:43:01                7       13227286650 ONLINE              1009 YES /mnt/ramdisk/book/system01.dbf  SYSTEM
    2        13227502434 2016-04-05 11:43:01             1834       13227286650 ONLINE              1005 YES /mnt/ramdisk/book/sysaux01.dbf  SYSAUX
    3        13227502434 2016-04-05 11:43:01           923328       13227286650 ONLINE               925 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
    4        13227502434 2016-04-05 11:43:01            16143       13227286650 ONLINE              1009 YES /mnt/ramdisk/book/users01.dbf   USERS
    5        13227502434 2016-04-05 11:43:01           952916       13227286650 ONLINE               922 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
    6        13227502434 2016-04-05 11:43:01          1314508       13227286650 ONLINE               938 YES /mnt/ramdisk/book/sugar01.dbf   SUGAR
    7        13227502434 2016-04-05 11:43:01      13227207527       13227286650 ONLINE                32 YES /mnt/ramdisk/book/tea01.dbf     TEA
7 rows selected.

--自动修复CHECKPOINT_COUNT记数.视乎11.2.0.4不再需要修改CHECKPOINT_COUNT.

SYS@book> select * from scott.empx where rownum<=1;
       EMPNO ENAME      JOB                MGR HIREDATE                     SAL         COMM       DEPTNO
------------ ---------- --------- ------------ ------------------- ------------ ------------ ------------
        7369 YYYY       CLERK             7902 1980-12-17 00:00:00          800                        20

--不过修改都丢失了.还原:
$ mv tea01.dbf_0405 tea01.dbf
$ cd /u01/app/oracle/archivelog/
$ mv book book.test
$ mv book.xxx/ book

SYS@book> startup mount
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
SYS@book> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'


SYS@book> recover datafile 7 ;
Media recovery complete.
SYS@book> alter database open ;

Database altered.

SYS@book> select * from scott.empx where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 ZZZZ       CLERK           7902 1980-12-17 00:00:00        800                    20

--OK,已经还原了.

--CHECKPOINT_COUNT的位置:

BBED> p kcvfh.kcvfhcpc dba 7,1
ub4 kcvfhcpc                                @140      0x00000023

BBED> p kcvfh.kcvfhcpc dba 1,1
ub4 kcvfhcpc                                @140      0x000003f3

SYS@book> @ &r/16to10 3f3
16 to 10 DEC
------------
        1011

SYS@book> @ &r/16to10 23
16 to 10 DEC
------------
          35

 

--实际上这样的测试存在许多问题,比如drop表,create表,这样在系统表空间存在定义,而数据文件已经丢失了.

你可能感兴趣的:([20160405]bbed修改文件头.txt)