且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

[20171121]rman使用copy image恢复.txt

更新时间:2022-08-15 08:29:01

[20171121]rman使用copy image恢复.txt

--//上个星期做数据文件块头恢复时,提到使用rman备份数据文件时,文件头数据库信息是最后写入备份集文件的,在filesperset=1的情况
--//下写入备份集文件中的倒数第2块就是文件头的备份.参考链接:

http://blog.itpub.net/267265/viewspace-2147297/=>[20171115]恢复数据文件块头4补充.txt

--//而且我最后还做了测试证明如果resotre数据文件,实际上文件头也是最后更新到数据文件的.

--//我当时的分析是oracle这样设计有它一定道理.因为没有正确写入文件头,dbv检查报坏块.这个数据文件是"无用".
--//另外一个原因就是假设restore时发生中断,而这个时候文件头已经前期正常写入,很可能可以online该数据文件.
--//而最后写入,保证这个restore的数据文件是完整的.

--//这个就带来另外的问题oracle的备份还有另外模式backup as copy实现image的拷贝,
--//我的测试:
--//先建立空文件,然后"格式化"新块,然后顺序从数据文件写入备份文件.也就是as copy备份方式不是最后写入文件头,我前面的推测错
--//误页.

--//继续测试恢复的情况:

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

$ cat dump_head.sh
#! /bin/bash
for i in $(seq 1000)
do
#   echo $i
    xxd -c32 -g 2 -s 8192 -l 32 $1 >> /tmp/sysaux_head.txt 2>/dev/null
    sleep 0.1
done

SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

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.

$ cd /mnt/ramdisk/book/
$ mv sysaux01.dbf sysaux01.dbf_20171120

2.测试:
--//首先启动dump_head.sh脚本,session 1:
$ rm /tmp/sysaux_head.txt
$ .  dump_head.sh /mnt/ramdisk/book/sysaux01.dbf

--//在sesion 2,在rman下执行恢复:
RMAN> restore datafile 2;
Starting restore at 2017-11-20 10:24:10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=14 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=28 device type=DISK

channel ORA_DISK_1: restoring datafile 00002
input datafile copy RECID=16 STAMP=960545822 file name=/home/oracle/backup/sysaux01.dbf
destination for restore of datafile 00002: /mnt/ramdisk/book/sysaux01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00002
output file name=/mnt/ramdisk/book/sysaux01.dbf RECID=0 STAMP=0
Finished restore at 2017-11-20 10:24:19

$ .  dump_head.sh /mnt/ramdisk/book/sysaux01.dbf
^C

3.检查/tmp/sysaux_head.txt文件:

$ uniq -c /tmp/sysaux_head.txt
     18 0002000: 00a2 0000 0100 8000 0000 0000 0000 0105 81a7 0000 0000 0000 0000 0000 0000 0000  ................................
     46 0002000: 0ba2 0000 0100 8000 0000 0000 0000 0104 3238 0000 0000 0000 0004 200b 6e21 b74f  ................28........ .n!.O

--//我又将脚本sleep 改成0.01.重复测试:
$ grep "^0002000" /tmp/sysaux_head.txt | uniq -c
      1 0002000: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
    119 0002000: 00a2 0000 0100 8000 0000 0000 0000 0105 81a7 0000 0000 0000 0000 0000 0000 0000  ................................
    208 0002000: 0ba2 0000 0100 8000 0000 0000 0000 0104 3238 0000 0000 0000 0004 200b 6e21 b74f  ................28........ .n!.O

--//resotre datafile 使用copy image,先建立空文件,然后"格式化"新块,然后顺序从备份文件写入数据文件.