oracle 的 BLOCK CHANGE TRACKING

aaqwsh發表於2011-05-14

10G版本開始,引入了BLOCK CHANGE TRACKING特性,這次算是真正的增量了。

當這個特性開啟後,ORACLE會建立一個trace檔案,並起用後臺程式CTWR記錄變化的資料塊,當需要增量備份的時候,就直接讀這個檔案獲得要備份的資料塊,速度確實是有質的飛躍(參考http://www.alidba.net/index.php/archives/51

 

 

--啟用BLOCK CHANGE TRACKING特性

SQL> alter database enable block change tracking using file '/data/ora10g/RACDBSTD/trace.dbf' reuse;

 

Database altered.

 

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

 

Total System Global Area  167772160 bytes

Fixed Size                  1218316 bytes

Variable Size              62916852 bytes

Database Buffers          100663296 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

 

--全備資料庫(這個全備好像需要再開啟BLOCK CHANGE TRACKING後,後面的增備才能利用到)

RMAN> run{

2>     allocate channel c1 device type disk format '/data/backup/db_fullb%u';

3>     backup incremental level 0 database ;

4> }

 

released channel: ORA_DISK_1

allocated channel: c1

channel c1: sid=141 devtype=DISK

 

Starting backup at 14-MAY-11

channel c1: starting incremental level 0 datafile backupset

channel c1: specifying datafile(s) in backupset

input datafile fno=00001 name=/data/ora10g/RACDBSTD/system.259.727735501

input datafile fno=00003 name=/data/ora10g/RACDBSTD/sysaux.261.727735559

input datafile fno=00002 name=/data/ora10g/RACDBSTD/undo01.DBF

input datafile fno=00005 name=/data/ora10g/RACDBSTD/users.264.727735605

channel c1: starting piece 1 at 14-MAY-11

channel c1: finished piece 1 at 14-MAY-11

piece handle=/data/backup/db_fullb17mcb0h7 tag=TAG20110514T182335 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:45

channel c1: starting incremental level 0 datafile backupset

channel c1: specifying datafile(s) in backupset

including current control file in backupset

channel c1: starting piece 1 at 14-MAY-11

channel c1: finished piece 1 at 14-MAY-11

piece handle=/data/backup/db_fullb18mcb0ik tag=TAG20110514T182335 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:02

Finished backup at 14-MAY-11

released channel: c1

 

--增量備份

SQL> drop table testtab purge;

 

Table dropped.

 

SQL> create table testtab  as select * from dba_objects where 1 = 2;

 

Table created.

 

SQL> insert into testtab select * from dba_objects;

 

44964 rows created.

 

SQL> commit;

 

Commit complete.

 

RMAN> run{

2> allocate channel c1 device type disk format '/data/backup/db_incb%u';

3> backup incremental level 1 database ;

4> };

 

allocated channel: c1

channel c1: sid=141 devtype=DISK

 

Starting backup at 14-MAY-11

channel c1: starting incremental level 1 datafile backupset

channel c1: specifying datafile(s) in backupset

input datafile fno=00001 name=/data/ora10g/RACDBSTD/system.259.727735501

input datafile fno=00003 name=/data/ora10g/RACDBSTD/sysaux.261.727735559

input datafile fno=00002 name=/data/ora10g/RACDBSTD/undo01.DBF

input datafile fno=00005 name=/data/ora10g/RACDBSTD/users.264.727735605

channel c1: starting piece 1 at 14-MAY-11

channel c1: finished piece 1 at 14-MAY-11

piece handle=/data/backup/db_incb19mcb0k0 tag=TAG20110514T182503 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:07

channel c1: starting incremental level 1 datafile backupset

channel c1: specifying datafile(s) in backupset

including current control file in backupset

channel c1: starting piece 1 at 14-MAY-11

channel c1: finished piece 1 at 14-MAY-11

piece handle=/data/backup/db_incb1amcb0k7 tag=TAG20110514T182503 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:02

Finished backup at 14-MAY-11

released channel: c1

 

 

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

 

Session altered.

 

SQL> select file#, incremental_level, completion_time, datafile_blocks ,blocks_read,

  2  trunc((blocks_read / datafile_blocks) * 100,2) as "read%",

  3  used_change_tracking

  4  from v$backup_datafile

  5  where incremental_level > 0

  6  order by completion_time;

 

     FILE# INCREMENTAL_LEVEL COMPLETION_TIME     DATAFILE_BLOCKS BLOCKS_READ      read% USE

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

         5                 1 2011-05-14 18:10:51             640         640        100 NO

         2                 1 2011-05-14 18:10:58            6400        6400        100 NO

         3                 1 2011-05-14 18:11:08           20480       20480        100 NO

         1                 1 2011-05-14 18:11:17           53760       53760        100 NO

         5                 1 2011-05-14 18:15:51             640         640        100 NO

         2                 1 2011-05-14 18:15:58            6400        6400        100 NO

         3                 1 2011-05-14 18:16:08           20480       20480        100 NO

         1                 1 2011-05-14 18:16:18           53760       53760        100 NO

         3                 1 2011-05-14 18:17:25           20480           1          0 YES

         1                 1 2011-05-14 18:17:25           53760           1          0 YES

         2                 1 2011-05-14 18:17:25            6400           1        .01 YES

 

     FILE# INCREMENTAL_LEVEL COMPLETION_TIME     DATAFILE_BLOCKS BLOCKS_READ      read% USE

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

         5                 1 2011-05-14 18:17:25             640           1        .15 YES

         1                 1 2011-05-14 18:25:07           53760         679       1.26 YES

         3                 1 2011-05-14 18:25:07           20480        2039       9.95 YES

         2                 1 2011-05-14 18:25:07            6400         419       6.54 YES

         5                 1 2011-05-14 18:25:07             640           1        .15 YES

 

16 rows selected.

 

SQL> shutdown abort

ORACLE instance shut down.

 

--刪除資料檔案

rm /data/ora10g/RACDBSTD/users.264.727735605

 

 

--恢復

RMAN> startup mount

 

Oracle instance started

database mounted

 

Total System Global Area     167772160 bytes

 

Fixed Size                     1218316 bytes

Variable Size                 62916852 bytes

Database Buffers             100663296 bytes

Redo Buffers                   2973696 bytes

 

RMAN> restore database;

 

Starting restore at 14-MAY-11

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=157 devtype=DISK

 

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /data/ora10g/RACDBSTD/system.259.727735501

restoring datafile 00002 to /data/ora10g/RACDBSTD/undo01.DBF

restoring datafile 00003 to /data/ora10g/RACDBSTD/sysaux.261.727735559

restoring datafile 00005 to /data/ora10g/RACDBSTD/users.264.727735605

channel ORA_DISK_1: reading from backup piece /data/backup/db_fullb17mcb0h7

channel ORA_DISK_1: restored backup piece 1

piece handle=/data/backup/db_fullb17mcb0h7 tag=TAG20110514T182335

channel ORA_DISK_1: restore complete, elapsed time: 00:00:46

Finished restore at 14-MAY-11

 

--recover 用到了增量備份

RMAN> recover database;

 

Starting recover at 14-MAY-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: /data/ora10g/RACDBSTD/system.259.727735501

destination for restore of datafile 00002: /data/ora10g/RACDBSTD/undo01.DBF

destination for restore of datafile 00003: /data/ora10g/RACDBSTD/sysaux.261.727735559

destination for restore of datafile 00005: /data/ora10g/RACDBSTD/users.264.727735605

channel ORA_DISK_1: reading from backup piece /data/backup/db_incb19mcb0k0

channel ORA_DISK_1: restored backup piece 1

piece handle=/data/backup/db_incb19mcb0k0 tag=TAG20110514T182503

channel ORA_DISK_1: restore complete, elapsed time: 00:00:03

 

starting media recovery

media recovery complete, elapsed time: 00:00:05

 

Finished recover at 14-MAY-11

 

RMAN> alter database open;

 

database opened

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/758322/viewspace-695271/,如需轉載,請註明出處,否則將追究法律責任。

相關文章