[20180109]如何通过备份确定dbid和dbname.txt
--//如果仅仅存在备份集合,如何确定这个数据库的dbid和dbname呢?很简单,通过另外一个数据库使用rman的catalog命令就可以知道备份
--//集原来数据库的dbid和dbname,通过测试来说明:
1.环境:
SCOTT@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
2.假设备份在目录/home/oracle/backup/
$ ls -l /home/oracle/backup/spfile_01soahbi_1_1
-rw-r----- 1 oracle oinstall 98304 2018-01-10 09:22:58 /home/oracle/backup/spfile_01soahbi_1_1
--//注:这个是其它机器的spfile文件备份。
--//使用catalog注册:
RMAN> catalog start with '/home/oracle/backup/spfile_01soahbi_1_1';
using target database control file instead of recovery catalog
searching for all files that match the pattern /home/oracle/backup/spfile_01soahbi_1_1
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/backup/spfile_01soahbi_1_1
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
no files cataloged
List of Files Which Where Not Cataloged
=======================================
File Name: /home/oracle/backup/spfile_01soahbi_1_1
RMAN-07518: Reason: Foreign database file DBID: 1476428194 Database Name: ORCL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--//注意看下划线。检查:
SYS@orcl> select dbid from v$database ;
DBID
----------
1476428194
--//正好对上。
3.其它方法:
SYS@book> @ &r/10to16 1476428194
10 to 16 HEX REVERSE16
-------------- ------------------
00000580081a2 0xa2810058
$ xxd -c 16 spfile_01soahbi_1_1 | egrep -i "a281 0058|ORCL" | head -2
0004010: 0772 0000 0004 200b 0004 200b a281 0058 .r.... ... ....X
0004020: 4f52 434c 0000 0000 6c7c 0100 0000 0000 ORCL....l|......
--//dbname前面的4个字节就是dbid。如果你查询数据文件:
SYS@book> select dbid from v$database;
DBID
------------
1337401710
SYS@book> @ &r/10to16 1337401710
10 to 16 HEX REVERSE16
-------------- ------------------
000004fb7216e 0x6e21b74f
--//通过bbed观察:
BBED> p dba 6,1 kcvfhhdr.kccfhdbi
ub4 kccfhdbi @28 0x4fb7216e
BBED> p /d dba 6,1 kcvfhhdr.kccfhdbi
ub4 kccfhdbi @28 1337401710
BBED> p /d dba 6,1 kcvfhhdr.kccfhdbn
text kccfhdbn[0] @32 66
text kccfhdbn[1] @33 79
text kccfhdbn[2] @34 79
text kccfhdbn[3] @35 75
text kccfhdbn[4] @36 32
text kccfhdbn[5] @37 32
text kccfhdbn[6] @38 32
text kccfhdbn[7] @39 32
BBED> p /c dba 6,1 kcvfhhdr.kccfhdbn
text kccfhdbn[0] @32 B
text kccfhdbn[1] @33 O
text kccfhdbn[2] @34 O
text kccfhdbn[3] @35 K
text kccfhdbn[4] @36 .
text kccfhdbn[5] @37 .
text kccfhdbn[6] @38 .
text kccfhdbn[7] @39 .
--//在文件头偏移28字节处是dbid,接着就是dbname,可以看到dbname最长8个字符。数据文件内存保存的是BOOK加4个空格。
--//可以发现找一个数据库使用rman的catalog命令就可以知道这些信息。另外一点不同版本或者os是否可行,这个不测试了。