[20161031]rman备份与数据文件OS块.txt

简介: [20161031]rman备份与数据文件OS块.txt --每个数据文件都有一个OS块,位于数据文件的第1块(也是0块).通过bbed无法访问: BBED> set dba 7,0 BBED-00205: illegal or out of range DB...

[20161031]rman备份与数据文件OS块.txt

--每个数据文件都有一个OS块,位于数据文件的第1块(也是0块).通过bbed无法访问:

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


BBED> set dba 7,1
        DBA             0x01c00001 (29360129 7,1)

BBED> dump
File: /mnt/ramdisk/book/tea01.dbf (7)
Block: 1                                                    Offsets:    0 to   63                                               Dba:0x01c00001
------------------------------------------------------------------------------------------------------------------------------------------------
0ba20000 0100c001 00000000 00000104 14b50000 00000000 0004200b 6e21b74f 424f4f4b 00000000 6a4b0000 000f0000 00200000 07000300 00000000 00000000

<64 bytes per line>

--可以通过如下方法查看在bbed:

BBED> set file 7 block 0
        FILE#           7
        BLOCK#          0

BBED> dump
File: /mnt/ramdisk/book/tea01.dbf (7)
Block: 0                                                    Offsets:    0 to   63                                               Dba:0x01c00000
------------------------------------------------------------------------------------------------------------------------------------------------
00a20000 0000c0ff 00000000 00000000 66f50000 00200000 000f0000 7d7c7b7a a0810000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
                                                                ~~~~~~~~
<64 bytes per line>

--//使用查看二进制的工具可以发现:
$ xxd -c 16 -l 128 tea01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000  ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a  f?.. ......}|{z
                                       ~~~~~~~~~
0000020: a081 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
}
--你可以看到1个特征串7d7c7b7a。
--如果你建立一个数据文件,实际上从os看文件大小是30M+8k.

CREATE TABLESPACE SUGAR DATAFILE
  '/mnt/ramdisk/book/sugar01.dbf' SIZE 30M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
NOLOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

$ ls -l sugar01.dbf
-rw-r----- 1 oracle oinstall 31465472 2016-10-31 08:49:39 sugar01.dbf

--30*1024*1024+8192=31465472 .
--如果想了解更多细节,可以参考http://www.killdb.com/2011/09/05/%e4%b8%8d%e5%ae%8c%e5%85%a8%e8%af%a6%e8%a7%a3os-block-header.html

--//简单介绍这些,看看rman是否备份这个块。注意不要在生产系统做这样的测试:

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

RMAN> delete backupset ;
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=68 device type=DISK
specification does not match any backup in the repository

--在一些空地方插入一些垃圾数据,在偏移0x100=256位置替换A1B2C3D4E5。
$ bvi -s 8192 -b 0 /mnt/ramdisk/book/sugar01.dbf


$ xxd -c 16 -l 320 sugar01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000  ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a  f?.. ......}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000100: 4131 4232 4333 4434 4535 0000 0000 0000  A1B2C3D4E5......
0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
}

--//注意:千万不要在生产系统做这样的测试,另外这样并不会影响数据库的启动。关闭数据库,重启看看。

2.备份数据文件:

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

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.
Database opened.

--你可以检查A1B2C3D4E5字符串 依旧存在。

$ strings -t d sugar01.dbf  | grep 'A1B2C3'
    256 A1B2C3D4E5

$ strings -t x sugar01.dbf  | grep 'A1B2C3'
    100 A1B2C3D4E5

--可以发现在偏移量256位置出现A1B2C3D4E5.

RMAN> backup datafile 6 format '/u01/backup/d6_A_%U' ;

Starting backup at 2016-10-31 09:19:56
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-10-31 09:19:57
channel ORA_DISK_1: finished piece 1 at 2016-10-31 09:19:58
piece handle=/u01/backup/d6_A_0hrjnqlt_1_1 tag=TAG20161031T091957 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-10-31 09:19:58

--//检查备份可以发现,没有出现A1B2C3D4E5字符串。
$ strings -t d /u01/backup/d6_A_0hrjnqlt_1_1 | grep A1B2


$ strings -t d /u01/backup/d6_A_0hrjnqlt_1_1 | grep "}|{z"
     28 }|{z

$ xxd -c 16 -l 320 /u01/backup/d6_A_0hrjnqlt_1_1
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000  ......?........
0000010: a2fa 0000 0020 0000 c400 0000 7d7c 7b7a  .?.. ..?..}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
}

--//你可以发现rman的备份集合也有OS块。按照链接http://www.killdb.com/2011/09/05/%e4%b8%8d%e5%ae%8c%e5%85%a8%e8%af%a6%e8%a7%a3os-block-header.html,
--//offset 0x18-0x19 对应的datafile的大小,实际上是block个数.

$ xxd -c 16 -l 320 sugar01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000  ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a  f?.. ......}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000  ................

--f00 = 3840, 数据文件大小30M,30*1024*1024/8192=3840.正好对上。

$ xxd -c 16 -l 320 /u01/backup/d6_A_0hrjnqlt_1_1
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000  ......?........
0000010: a2fa 0000 0020 0000 c400 0000 7d7c 7b7a  .?.. ..?..}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000  ................
}

$ ls -l /u01/backup/d6_A_0hrjnqlt_1_1
-rw-r----- 1 oracle oinstall 1613824 2016-10-31 09:19:57 /u01/backup/d6_A_0hrjnqlt_1_1

--c4 = 196, 备份文件大小1613824, 1613824/8192=197,这样扣除1个OS块,大小也是196.也能对上,就是讲备份集也存在1个OS块。

3.做一个恢复看看。

SYS@book> alter tablespace sugar offline ;
Tablespace altered.

$ mv sugar01.dbf sugar01.dbf_20161031

RMAN> restore tablespace sugar ;
Starting restore at 2016-10-31 09:37:10
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to /mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/d6_A_0hrjnqlt_1_1
channel ORA_DISK_1: piece handle=/u01/backup/d6_A_0hrjnqlt_1_1 tag=TAG20161031T091957
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2016-10-31 09:37:12

$ xxd -c 16 -l 320 sugar01.dbf
0000000: 00a2 0000 0000 c0ff 0000 0000 0000 0000  ......?........
0000010: 66f5 0000 0020 0000 000f 0000 7d7c 7b7a  f?.. ......}|{z
0000020: a081 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................

--你可以发现恢复数据文件头没有A1B2字符串。}

RMAN> recover tablespace sugar ;
Starting recover at 2016-10-31 09:37:37
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2016-10-31 09:37:37

SYS@book> alter tablespace sugar online ;
Tablespace altered.

--从以上测试可以证明rman并没有备份数据文件的OS块。

4.做一个strace看看:

$ strace -f -o /tmp/bb.txt rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Oct 31 09:41:54 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: BOOK (DBID=1337401710)

RMAN> backup datafile 6 format '/u01/backup/d6_B_%U' ;
Starting backup at 2016-10-31 09:42:23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-10-31 09:42:24
channel ORA_DISK_1: finished piece 1 at 2016-10-31 09:42:25
piece handle=/u01/backup/d6_B_0irjns00_1_1 tag=TAG20161031T094224 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-10-31 09:42:25


$ grep pread /tmp/bb.txt | grep ", 0"
3053  pread(259, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053  pread(259, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053  pread(260, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053  pread(260, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053  pread(261, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192
3053  pread(261, "\0\242\0\0\0\0\300\377\0\0\0\0\0\0\0\0f\365\0\0\0 \0\0\0\17\0\0}|{z"..., 8192, 0) = 8192

$ grep pwrite /tmp/bb.txt | grep ", 0"
$ grep pwrite /tmp/bb.txt | grep ", 8192"
3053  pwrite(258, "\v\242\0\0\1\0\200\1\0\0\0\0\0\0\1\4\276\250\0\0\0\0\0\0\0\4 \vn!\267O"..., 8192, 8192) = 8192
3053  pwrite(259, "\23\242\0\0\1\0\0\0K\364#\0\0\0\1\4\257I\0\0\0\4 \v\0\4 \vn!\267O"..., 1040384, 8192) = 1040384

$ grep pwrite /tmp/bb.txt | grep "= 8192"
3053  pwrite(258, "\v\242\0\0\1\0\200\1\0\0\0\0\0\0\1\4\276\250\0\0\0\0\0\0\0\4 \vn!\267O"..., 8192, 8192) = 8192

--从以上跟踪看,有读第0块的操作,没有出现一次写的操作。也就是rman不备份这数据文件OS块。

目录
相关文章
|
5月前
|
Python
python如何使用os模块进行文件和目录操作?
python如何使用os模块进行文件和目录操作?
|
7月前
|
存储 Linux Python
Python分享之路径与文件 (os.path包, glob包)
Python分享之路径与文件 (os.path包, glob包)
|
7月前
|
Unix Go
Golang 语言的标准库 os 包怎么操作目录和文件?
Golang 语言的标准库 os 包怎么操作目录和文件?
28 0
|
7月前
|
Linux Shell Go
《Linux操作系统编程》 第五章 文件和文件系统: 了解文件和文件系统的概念和特性,掌握Linux文件系统的基本操作
《Linux操作系统编程》 第五章 文件和文件系统: 了解文件和文件系统的概念和特性,掌握Linux文件系统的基本操作
71 0
|
9天前
|
Go API 开发者
Golang深入浅出之-文件与目录操作:os与path/filepath包
【4月更文挑战第26天】Go语言标准库`os`和`path/filepath`提供文件读写、目录操作等功能。本文涵盖`os.Open`, `os.Create`, `os.Mkdir`, `filepath.Join`等API的使用,强调了文件关闭、路径处理、并发写入和权限问题的处理,并给出实战代码示例,帮助开发者高效、安全地操作文件与目录。注意使用`defer`关闭文件,`filepath`处理路径分隔符,以及通过同步机制解决并发写入冲突。
25 2
|
5月前
|
存储 数据库 数据安全/隐私保护
【王道考研操作系统】—文件的基本操作
【王道考研操作系统】—文件的基本操作
|
6月前
|
开发者 Windows
什么是 Windows 操作系统 DLL 文件的 Side-by-Side Assemblies 技术
什么是 Windows 操作系统 DLL 文件的 Side-by-Side Assemblies 技术
52 0
|
6月前
|
API UED Windows
什么是 Windows 操作系统的 DLL 文件
什么是 Windows 操作系统的 DLL 文件
89 0
|
6月前
|
域名解析 缓存 网络协议
编辑 windows 操作系统 local host 文件的注意事项
编辑 windows 操作系统 local host 文件的注意事项
111 0
|
7月前
|
缓存 BI Linux
《Linux操作系统编程》第九章 数据查找和筛选工具 : 了解流编辑器sed和报表生成器awk的简单使用
《Linux操作系统编程》第九章 数据查找和筛选工具 : 了解流编辑器sed和报表生成器awk的简单使用
55 0