ITPub博客

首页 > 数据库 > Oracle > [20190517]rman tape compressed.txt

[20190517]rman tape compressed.txt

原创 Oracle 作者:lfree 时间:2019-05-22 09:25:07 0 删除 编辑

[20190517]rman tape compressed.txt


--//前一段测试rman选择压缩备份时,如果备份单个数据文件小于64M-3*8K时,先建立大小64M文件,最后会回收到自己的备份大小.

--//链接:[20190509]rman备份的疑问5.txt

--//测试也说明开始建立的文件时稀疏文件,自己有1个奇怪的想法,如果使用磁带方式,磁带是流式设备,oracle的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


CREATE TABLESPACE T01 DATAFILE '/mnt/ramdisk/book/t01.dbf' SIZE 40M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT

LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT MANUAL;


ALTER DATABASE DATAFILE '/mnt/ramdisk/book/t01.dbf' RESIZE 65512K;


create table t01 tablespace  t01 as select rownum id ,lpad('A',32,'A') name from dual connect by level<=7e5;


2.测试:

--//说明我没有磁带,不过oracle提供模式磁带库的方式(实际上现在许多知名的备份软件实际上使用虚拟磁带库)。

CONFIGURE CHANNEL DEVICE TYPE SBT PARMS  'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=/u01/backup)';

CONFIGURE DEFAULT DEVICE TYPE TO SBT_TAPE ;

CONFIGURE CONTROLFILE AUTOBACKUP OFF;

CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 5M;


--//执行如下:

RMAN> CONFIGURE CHANNEL DEVICE TYPE SBT PARMS  'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=/u01/backup)';

new RMAN configuration parameters:

CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS  'SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=/u01/backup)';

new RMAN configuration parameters are successfully stored


RMAN> CONFIGURE DEFAULT DEVICE TYPE TO SBT_TAPE ;


old RMAN configuration parameters:

CONFIGURE DEFAULT DEVICE TYPE TO DISK;

new RMAN configuration parameters:

CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';

new RMAN configuration parameters are successfully stored


RMAN> CONFIGURE CONTROLFILE AUTOBACKUP OFF;


old RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP OFF;

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP OFF;

new RMAN configuration parameters are successfully stored


RMAN> CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 1M;


new RMAN configuration parameters:

CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 1 M;

new RMAN configuration parameters are successfully stored



--//还原脚本:

--//CONFIGURE CHANNEL DEVICE TYPE SBT_TAPE clear;

--//CONFIGURE DEFAULT DEVICE TYPE TO DISK;


--//建立测试脚本:

$ cat ts.sh

#! /bin/bash

file=$1

>| /tmp/xx_${file}

>| /tmp/yy_${file}

strace -ftt -x -o /tmp/tt_${file}.txt rman target / <<< "backup as compressed backupset datafile "$file" format \"/u01/backup/T_"${file}"_%U\" ;" &

seq 30 | xargs -I{} echo "ls -l /u01/backup/T_${file}_*;sleep 0.5" | bash 2>/dev/null| ts.awk >> /tmp/xx_${file} 2>/dev/null &

seq 30 | xargs -I{} echo "stat -c '%s %b %B' /u01/backup/T_${file}_*;sleep 0.5" | bash  2>/dev/null | ts.awk >> /tmp/yy_${file} 2>/dev/null &

wait


$ . ts.sh 9


Recovery Manager: Release 11.2.0.4.0 - Production on Wed May 22 08:46:31 2019


Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.


connected to target database: BOOK (DBID=1337401710)


RMAN>

Starting backup at 2019-05-22 08:46:34

using target database control file instead of recovery catalog

allocated channel: ORA_SBT_TAPE_1

channel ORA_SBT_TAPE_1: SID=59 device type=SBT_TAPE

channel ORA_SBT_TAPE_1: WARNING: Oracle Test Disk API

channel ORA_SBT_TAPE_1: starting compressed full datafile backup set

channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set

input datafile file number=00009 name=/mnt/ramdisk/book/t01.dbf

channel ORA_SBT_TAPE_1: starting piece 1 at 2019-05-22 08:46:36

channel ORA_SBT_TAPE_1: finished piece 1 at 2019-05-22 08:46:37

piece handle=/u01/backup/T_9_2tu25tnc_1_1 tag=TAG20190522T084635 comment=API Version 2.0,MMS Version 8.1.3.0

channel ORA_SBT_TAPE_1: backup set complete, elapsed time: 00:00:01

Finished backup at 2019-05-22 08:46:37


RMAN>


Recovery Manager complete.

[1]   Done                    strace -ftt -x -o /tmp/tt_${file}.txt rman target / <<< "backup as compressed backupset datafile "$file" format \"/u01/backup/T_"${file}"_%U\" ;"

[2]-  Done                    seq 30 | xargs -I{} echo "ls -l /u01/backup/T_${file}_*;sleep 0.5" | bash 2> /dev/null | ts.awk >> /tmp/xx_${file} 2> /dev/null

[3]+  Done                    seq 30 | xargs -I{} echo "stat -c '%s %b %B' /u01/backup/T_${file}_*;sleep 0.5" | bash 2> /dev/null | ts.awk >> /tmp/yy_${file} 2> /dev/null


$ ls -l  Oracle_Disk_SBT_Catalog T_9_2tu25tnc_1_1

-rw-r--r-- 1 oracle oinstall    3360 2019-05-22 08:46:36 Oracle_Disk_SBT_Catalog

-rw-r--r-- 1 oracle oinstall 8388624 2019-05-22 08:46:36 T_9_2tu25tnc_1_1


$ cat /tmp/xx_9

[2019-05-22 08:46:36] -rw-r--r-- 1 oracle oinstall 4194320 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:37] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:37] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:38] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:38] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:39] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:39] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:40] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:40] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:41] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:41] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:42] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:42] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:43] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:43] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:44] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:44] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:45] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:45] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1

[2019-05-22 08:46:46] -rw-r--r-- 1 oracle oinstall 8388624 May 22 08:46 /u01/backup/T_9_2tu25tnc_1_1


$ cat /tmp/yy_9

[2019-05-22 08:46:36] 4194320 8208 512

[2019-05-22 08:46:37] 8388624 16416 512

[2019-05-22 08:46:37] 8388624 16416 512

[2019-05-22 08:46:38] 8388624 16416 512

[2019-05-22 08:46:38] 8388624 16416 512

[2019-05-22 08:46:39] 8388624 16416 512

[2019-05-22 08:46:39] 8388624 16416 512

[2019-05-22 08:46:40] 8388624 16416 512

[2019-05-22 08:46:40] 8388624 16416 512

[2019-05-22 08:46:41] 8388624 16416 512

[2019-05-22 08:46:41] 8388624 16416 512

[2019-05-22 08:46:42] 8388624 16416 512

[2019-05-22 08:46:42] 8388624 16416 512

[2019-05-22 08:46:43] 8388624 16416 512

[2019-05-22 08:46:43] 8388624 16416 512

[2019-05-22 08:46:44] 8388624 16416 512

[2019-05-22 08:46:44] 8388624 16416 512

[2019-05-22 08:46:45] 8388624 16416 512

[2019-05-22 08:46:45] 8388624 16416 512

[2019-05-22 08:46:46] 8388624 16416 512

--//4194320/1024/1024 = 4.0000152587890625

0.0000152587890625*1024*1024  = 16

--//你可以发现备份文件集并没有建立稀疏文件.而且一开始就建立大小大于4M+16字节的文件.

--//8388624/1024/1024 = 8.00001525878906250000,最后大小是压缩的.


$ strings T_9_2tu25tnc_1_1 | grep AAAAAAAAAAAAAAAAAAAAAAAA|wc

  64579  109753 2336114


--//有点奇怪的是仅仅看到AAAAAAAAAAAAAAAAAAAAAAAA是64579,应该至少7E5.

--//700000-64579  = 635421有这么多AAAAA涉及压缩.


SCOTT@book> select sum(bytes)/1024/1024 from dba_extents where file_id=9;

SUM(BYTES)/1024/1024

--------------------

                  33


--//33M.这么讲实际上还是存在可以实现压缩的.


$ strings -t d T_9_2tu25tnc_1_1 | grep AAAAAAAAAAAAAAAAAAAAAAAA| tail

4193914  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4193955  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4193996  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194037  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194078  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194119  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194160  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194201  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194242  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,

4194283  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


--//最后1个AAAAA出现的位置在4194283,4194283/1024/1024 = 3.99997997283935546875,前面4M之内.

--//也就是可以大致推断前面4M是不压缩的,后面才压缩.不然建立的备份文件不会是8M.


3.重新测试:

$ cat dx.sql

drop tablespace t&1 including contents and datafiles;

CREATE TABLESPACE T&1 DATAFILE '/mnt/ramdisk/book/T&1..dbf' SIZE 40M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON;

create table t&1 tablespace t&1 as select rownum id ,to_char(rownum,'FM000000')||lpad('&&2',26,'&&2') name from dual connect by level<=7e5;


SCOTT@book> @ dx.sql 01 B

old   1: drop tablespace t&1 including contents and datafiles

new   1: drop tablespace t01 including contents and datafiles


Tablespace dropped.


old   1: CREATE TABLESPACE T&1 DATAFILE '/mnt/ramdisk/book/T&1..dbf' SIZE 40M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON

new   1: CREATE TABLESPACE T01 DATAFILE '/mnt/ramdisk/book/T01.dbf' SIZE 40M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON


Tablespace created.


old   1: create table t&1 tablespace t&1 as select rownum id ,to_char(rownum,'FM000000')||lpad('&&2',26,'&&2') name from dual connect by level<=6e5

new   1: create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('B',26,'B') name from dual connect by level<=6e5


Table created.


--//删除前面的备份重复测试.

--//RMAN> delete backupset ;


$ . ts.sh 9

Recovery Manager: Release 11.2.0.4.0 - Production on Wed May 22 09:07:27 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: BOOK (DBID=1337401710)

RMAN>

Starting backup at 2019-05-22 09:07:30

using target database control file instead of recovery catalog

allocated channel: ORA_SBT_TAPE_1

channel ORA_SBT_TAPE_1: SID=114 device type=SBT_TAPE

channel ORA_SBT_TAPE_1: WARNING: Oracle Test Disk API

channel ORA_SBT_TAPE_1: starting compressed full datafile backup set

channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set

input datafile file number=00009 name=/mnt/ramdisk/book/T01.dbf

channel ORA_SBT_TAPE_1: starting piece 1 at 2019-05-22 09:07:32

channel ORA_SBT_TAPE_1: finished piece 1 at 2019-05-22 09:07:33

piece handle=/u01/backup/T_9_2uu25uuk_1_1 tag=TAG20190522T090732 comment=API Version 2.0,MMS Version 8.1.3.0

channel ORA_SBT_TAPE_1: backup set complete, elapsed time: 00:00:01

Finished backup at 2019-05-22 09:07:33


RMAN>


Recovery Manager complete.

[1]   Done                    strace -ftt -x -o /tmp/tt_${file}.txt rman target / <<< "backup as compressed backupset datafile "$file" format \"/u01/backup/T_"${file}"_%U\" ;"

[2]-  Done                    seq 30 | xargs -I{} echo "ls -l /u01/backup/T_${file}_*;sleep 0.5" | bash 2> /dev/null | ts.awk >> /tmp/xx_${file} 2> /dev/null

[3]+  Done                    seq 30 | xargs -I{} echo "stat -c '%s %b %B' /u01/backup/T_${file}_*;sleep 0.5" | bash 2> /dev/null | ts.awk >> /tmp/yy_${file} 2> /dev/null


SELECT set_count

        ,device_type

        ,TYPE

        ,filename

        ,buffer_size

        ,buffer_count

        ,open_time

        ,close_time

    FROM v$backup_async_io

   where set_count=94

ORDER BY set_count

        ,TYPE

        ,open_time

        ,close_time;


 SET_COUNT DEVICE_TYPE       TYPE      FILENAME                       BUFFER_SIZE BUFFER_COUNT OPEN_TIME           CLOSE_TIME

---------- ----------------- --------- ------------------------------ ----------- ------------ ------------------- -------------------

        94 DISK              AGGREGATE                                          0            0 2019-05-22 09:07:32 2019-05-22 09:07:32

        94 DISK              INPUT     /mnt/ramdisk/book/T01.dbf          1048576           16 2019-05-22 09:07:32 2019-05-22 09:07:32


$ head -2 /tmp/xx_9  /tmp/yy_9

==> /tmp/xx_9 <==

[2019-05-22 09:07:32] -rw-r--r-- 1 oracle oinstall 4194320 May 22 09:07 /u01/backup/T_9_2uu25uuk_1_1

[2019-05-22 09:07:32] -rw-r--r-- 1 oracle oinstall 8388624 May 22 09:07 /u01/backup/T_9_2uu25uuk_1_1


--//(8388624-4194320)/1024/1024 = 4


==> /tmp/yy_9 <==

[2019-05-22 09:07:32] 4194320 8208 512

[2019-05-22 09:07:32] 8388624 16416 512


$ strings -t d T_9_2uu25uuk_1_1 | grep BBBBBBBBBBBBB| tail

4193913 % 062236BBBBBBBBBBBBBBBBBBBBBBBBBB,

4193954 $ 062235BBBBBBBBBBBBBBBBBBBBBBBBBB,

4193995 # 062234BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194036 o 062233BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194077 ! 062232BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194118   062231BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194160  062230BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194201  062229BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194242  062228BBBBBBBBBBBBBBBBBBBBBBBBBB,

4194283  062227BBBBBBBBBBBBBBBBBBBBBBBBBB


SCOTT@book> select rowid,t01.* from t01 where id=062227;

ROWID                      ID NAME

------------------ ---------- ----------------------------------------

ACgY2MAAJAAAAH/AAA      62227 062227BBBBBBBBBBBBBBBBBBBBBBBBBB


SCOTT@book> @ rowid ACgY2MAAJAAAAH/AAA

    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT

---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------

  42044812          9        511          0  0x24001FF           9,511                alter system dump datafile 9 block 511 ;


--//在dba=9,511位置.511*8192 = 4186112 ,行号=0,数据从块底部开始插入.所以tail看到的最后1行是行号0.


$ ls -l T_9_2uu25uuk_1_1

-rw-r--r-- 1 oracle oinstall 8388624 2019-05-22 09:07:32 T_9_2uu25uuk_1_1


--//可以看出使用磁盘模拟还是可以压缩的,仅仅前面4M不压缩(注我仅仅测试备份集包含单个文件的情况)为什么一些虚拟带库不支持压缩呢?

--//另外视乎虚拟带库的文件建立按照4M大小建立的.

--//看来应该建议他们测试看看,是否支持压缩方式.


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2645144/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    2435
  • 访问量
    6216329