暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

oracle block change tracking

原创 范计杰 2020-06-10
2015

概述

Block ChangeTracking 是Oracle 10g里推出的特性,该特性是通过在块更改跟踪文件中记录更改的块,从而提高增量备份的性能(备份时不再需要扫描整个数据文件,只扫描Block ChangeTracking 跟踪到的自己前备份以后修改过的块)。
Block ChangeTracking以下监控BC

打开、关闭块 Block ChangeTracking

----打开块修改跟踪
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING  using file '/arch/block_change_track.f' reuse;
--OMF时可以不指定文件名
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

----查询块修改跟踪
SQL> SELECT status, filename FROM V$BLOCK_CHANGE_TRACKING;

STATUS     FILENAME
---------- ---------------------------------------------------------
ENABLED    /arch/block_change_track.f

----关闭块修改跟踪
ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;

关于 Block ChangeTracking 一些说明

  1. BCT LOG是一个bitmap结构
  2. 怎么估算BCT LOG的大小
    参考MOS文档, RMAN 10g : How To Size the Block Change Tracking File (Doc ID 306112.1)
    = <# of redo threads> * (# of old backups + 2) * (size of db/250000)
    Let’s take an example of a 500 GB database, with only one thread, and having eight backups kept
    in RMAN. The repository for this will require a block change tracking file of 20 MB.
    Threads * (number of old backups+2) * (database size in bytes/250000) = 20 MB
    The amount of data that each bit in the change tracking file covers is 32KB. That’s 262144 bits.
    That is where the 1/250000 figure comes from. This is the ratio of the size of one bitmap in the
    change tracking file, to the size of the database data that the bitmap covers. And, because we
    keep up to 8 levels of bitmap history in the file, plus the current bitmap, that reduces the ratio
    to about 1/30000, per enabled thread.

Dividing 1TB by 30000, you get 30 MB, per TB, per enabled thread.

So the parameters we use to determine the block change tracking file are:

  • Database size
  • Number of enabled threads
  • Number of old backups. (The block change tracking file keeps a record of all changes between previous backups, up to eight in total)
  1. BCT跟踪每次备份之后的块变化,最多记录8次备份之后的块变化(8个bitmap),第9次备份时会重用最早的bitmap.在制定备份策略时应注意该限制。
    8次的限制受隐藏参数“_bct_bitmaps_per_file”控制,默认8.
    个人猜测BCT逻辑结构如下:
    每个位图结构保存SCN+BITMAP, 记录备份时MIN(CHECKPOINT_CHANGE#)之后所有的块变化
    BACKUP 1 FROM SCN1+BITMAP
    BACKUP 2 FROM SCN2+BITMAP
    BACKUP 3 FROM SCN3+BITMAP
    BACKUP 4 FROM SCN4+BITMAP
    BACKUP 5 FROM SCN5+BITMAP
    BACKUP 6 FROM SCN6+BITMAP
    BACKUP 7 FROM SCN7+BITMAP
    BACKUP 8 FROM SCN7+BITMAP
    备份时是否能利用上BCT取决于增量备份的FROM SCN,差异增量备份从是需要找上次备份以来变化的块,所以不受次数限制,累计增量备份需要找到0级备份之后变化的块,如果增量备份次数过多,导致8次BITMAP不能实现该目的则需要扫描整个数据文件。
  2. RAC 环境 BCT LOG必须保存在共享存储中
  3. BCT LOG由CTWR(Change TrackingWriter)进程维护
  4. 当BCT LOG意外丢失后,禁用再启用即可

测试验证前面的一些疑问

1、在这种情情况下是否可以利用上BCT提高增量备份效率。
2、做基于SCN增量备份如果使用了BCT,是否会基于bullb做增量,会备份fulla->fullb之间的变化的数据块吗?
3、ORACLE跳着应用增量备份会检查吗?
测试记录

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING  using file '/arch/block_change_track.f' reuse;


Database altered.

SQL> SELECT status, filename FROM V$BLOCK_CHANGE_TRACKING;

STATUS     FILENAME
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ENABLED    /arch/block_change_track.f

---创建用户
SQL> create user dbmt identified by dbmt default tablespace users;

User created.

SQL> grant dba to dbmt;

Grant succeeded.

SQL> @ls users

TABLESPACE_NAME                   FILE_ID FILE_NAME                                                                        EXT         MB      MAXSZ
------------------------------ ---------- -------------------------------------------------------------------------------- --- ---------- ----------
USERS                                   4 /oracle/app/oracle/oradata/orcl11g/users01.dbf                                   YES          5   32767.98

---创建新的表空间
SQL> create tablespace users2 datafile '/oracle/app/oracle/oradata/orcl11g/users201.dbf' size 20m;

Tablespace created.

--创建两个表,分别存放于不同的表空间,USERS,USERS2
SQL> create table dbmt.test1(id number,c varchar2(100)) tablespace users;

Table created.

SQL> create table dbmt.test2(id number,c varchar2(100)) tablespace users2;

Table created.

SQL> @seg dbmt.test

    SEG_MB OWNER    SEGMENT_NAME       SEGMENT_TYPE         SEG_TABLESPACE_NAME                BLOCKS     HDRFIL     HDRBLK
---------- -------- ------------------ -------------------- ------------------------------ ---------- ---------- ----------
         0 DBMT     TEST1              TABLE                USERS                                   8          4        170
         0 DBMT     TEST2              TABLE                USERS2                                  8          5        130
         
SQL> alter system checkpoint;

System altered.


--取SCN,下次增量备份基于该SCN 
SQL> select min(checkpoint_change#) from v$datafile;

MIN(CHECKPOINT_CHANGE#)
-----------------------
                 964924


---第一次level 0备份full_lv0_n1


RMAN> backup  incremental level=0  as compressed backupset database tag='full_lv0_n1'  format '/data/backup/full_lv0_%U.bak';


Starting backup at 10-JUN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=39 device type=DISK
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/app/oracle/oradata/orcl11g/system01.dbf
input datafile file number=00002 name=/oracle/app/oracle/oradata/orcl11g/sysaux01.dbf
input datafile file number=00003 name=/oracle/app/oracle/oradata/orcl11g/undotbs01.dbf
input datafile file number=00005 name=/oracle/app/oracle/oradata/orcl11g/users201.dbf
input datafile file number=00004 name=/oracle/app/oracle/oradata/orcl11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JUN-20
channel ORA_DISK_1: finished piece 1 at 10-JUN-20
piece handle=/data/backup/full_lv0_05v2e7a3_1_1.bak tag=FULL_LV0_N1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 10-JUN-20
channel ORA_DISK_1: finished piece 1 at 10-JUN-20
piece handle=/data/backup/full_lv0_06v2e7cf_1_1.bak tag=FULL_LV0_N1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JUN-20



---还原第一次0级备份
SQL> create pfile='/home/oracle/pfile.ora' from spfile;

File created.


modify 

*.control_files='/data/test/control01.ctl'
*.audit_file_dest='/oracle/app/oracle/admin/test/adump'
*.db_name='orcl11g'
*.db_unique_name='test'

mkdir -p /arch/test
mkdir -p /oracle/app/oracle/admin/test/adump


export ORACLE_SID=test

sqlplus / as sysdba
startup nomount pfile='/home/oracle/pfile.ora'

export ORACLE_SID=test
rman target /



RMAN> restore controlfile from '/data/backup/full_lv0_06v2e7cf_1_1.bak';

Starting restore at 10-JUN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/data/test/control01.ctl
Finished restore at 10-JUN-20

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> 

run{
set newname for datafile  1 to '/data/test/system01.dbf' ;
set newname for datafile  2 to '/data/test/sysaux01.dbf' ;
set newname for datafile  3 to '/data/test/undotbs01.dbf';
set newname for datafile  4 to '/data/test/users01.dbf'  ;
set newname for datafile  5 to '/data/test/users201.dbf'  ;
restore database;
switch  datafile all; 
}

RMAN> run{
2> set newname for datafile  1 to '/data/test/system01.dbf' ;
3> set newname for datafile  2 to '/data/test/sysaux01.dbf' ;
4> set newname for datafile  3 to '/data/test/undotbs01.dbf';
5> set newname for datafile  4 to '/data/test/users01.dbf'  ;
6> set newname for datafile  5 to '/data/test/users201.dbf'  ;
7> restore database;
8> switch  datafile all; 
9> }

executing command: SET NEWNAME


executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 10-JUN-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

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 00001 to /data/test/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /data/test/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /data/test/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /data/test/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /data/test/users201.dbf
channel ORA_DISK_1: reading from backup piece /data/backup/full_lv0_05v2e7a3_1_1.bak
channel ORA_DISK_1: piece handle=/data/backup/full_lv0_05v2e7a3_1_1.bak tag=FULL_LV0_N1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 10-JUN-20

datafile 1 switched to datafile copy
input datafile copy RECID=6 STAMP=1042751326 file name=/data/test/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=1042751326 file name=/data/test/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=1042751327 file name=/data/test/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=1042751327 file name=/data/test/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=10 STAMP=1042751327 file name=/data/test/users201.dbf

RMAN> 


--rename redo log

alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo01.log' to '/data/redo01.log';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo02.log' to '/data/redo02.log';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo03.log' to '/data/redo03.log';


SQL> alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo01.log' to '/data/redo01.log';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo02.log' to '/data/redo02.log';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo03.log' to '/data/redo03.log';

Database altered.

SQL> 
Database altered.

SQL> 
Database altered.

----第一个表insert数据

insert into dbmt.test1 values (1,'test_lv0_n1');
commit;
alter system checkpoint;

SQL> insert into dbmt.test1 values (1,'test_lv0_n1');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system checkpoint;

System altered.

SQL> select min(checkpoint_change#) from v$datafile;

MIN(CHECKPOINT_CHANGE#)
-----------------------
                 966041


---做第二次level 0备份full_lv0_n2

backup  incremental level=0  as compressed backupset database tag='full_lv0_n2'  format '/data/backup/full_lv0_n2_%U.bak';

RMAN> backup  incremental level=0  as compressed backupset database tag='full_lv0_n2'  format '/data/backup/full_lv0_n2_%U.bak';

Starting backup at 10-JUN-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/app/oracle/oradata/orcl11g/system01.dbf
input datafile file number=00002 name=/oracle/app/oracle/oradata/orcl11g/sysaux01.dbf
input datafile file number=00003 name=/oracle/app/oracle/oradata/orcl11g/undotbs01.dbf
input datafile file number=00005 name=/oracle/app/oracle/oradata/orcl11g/users201.dbf
input datafile file number=00004 name=/oracle/app/oracle/oradata/orcl11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JUN-20
channel ORA_DISK_1: finished piece 1 at 10-JUN-20
piece handle=/data/backup/full_lv0_n2_07v2e822_1_1.bak tag=FULL_LV0_N2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 10-JUN-20
channel ORA_DISK_1: finished piece 1 at 10-JUN-20
piece handle=/data/backup/full_lv0_n2_08v2e835_1_1.bak tag=FULL_LV0_N2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JUN-20


--第二个表INSERT数据

insert into dbmt.test2 values (1,'test_lv0_n2');
commit;
alter system checkpoint;


select min(checkpoint_change#) from v$datafile;


SQL> insert into dbmt.test2 values (1,'test_lv0_n2');

1 row created.

SQL> commit;
alter system checkpoint;

Commit complete.

SQL> 

System altered.

SQL> SQL> select min(checkpoint_change#) from v$datafile;

MIN(CHECKPOINT_CHANGE#)
-----------------------
                 966148
                 

---第一次增量备份
---提示: 使用from scn的增量备份集,不记录到控制文件中
backup  incremental from scn  964924   as compressed backupset database tag='incr_lv1_n1'  format '/data/backup/incr_lv1_n1_%U.bak';

RMAN> backup  incremental from scn  964924   as compressed backupset database tag='incr_lv1_n1'  format '/data/backup/incr_lv1_n1_%U.bak';


Starting backup at 10-JUN-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/app/oracle/oradata/orcl11g/system01.dbf
input datafile file number=00002 name=/oracle/app/oracle/oradata/orcl11g/sysaux01.dbf
input datafile file number=00003 name=/oracle/app/oracle/oradata/orcl11g/undotbs01.dbf
input datafile file number=00005 name=/oracle/app/oracle/oradata/orcl11g/users201.dbf
input datafile file number=00004 name=/oracle/app/oracle/oradata/orcl11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-JUN-20
channel ORA_DISK_1: finished piece 1 at 10-JUN-20
piece handle=/data/backup/incr_lv1_n1_09v2e87p_1_1.bak tag=INCR_LV1_N1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01  <<<<这里可以看到增量备份1秒就完成了,说明用到了BCT特性
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 10-JUN-20
channel ORA_DISK_1: finished piece 1 at 10-JUN-20
piece handle=/data/backup/incr_lv1_n1_0av2e87r_1_1.bak tag=INCR_LV1_N1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JUN-20



--注册增量备份,应用增量备份

catalog backuppiece '/data/backup/incr_lv1_n1_09v2e87p_1_1.bak';


RMAN> catalog backuppiece '/data/backup/incr_lv1_n1_09v2e87p_1_1.bak';

cataloged backup piece
backup piece handle=/data/backup/incr_lv1_n1_09v2e87p_1_1.bak RECID=3 STAMP=1042751796


RMAN> recover database;

Starting recover at 10-JUN-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /data/test/system01.dbf
destination for restore of datafile 00002: /data/test/sysaux01.dbf
destination for restore of datafile 00003: /data/test/undotbs01.dbf
destination for restore of datafile 00004: /data/test/users01.dbf
destination for restore of datafile 00005: /data/test/users201.dbf
channel ORA_DISK_1: reading from backup piece /data/backup/incr_lv1_n1_09v2e87p_1_1.bak
channel ORA_DISK_1: piece handle=/data/backup/incr_lv1_n1_09v2e87p_1_1.bak tag=INCR_LV1_N1
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03

starting media recovery

unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/10/2020 21:17:11
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 964978




---read only 打开库,验证该增量是否包含full_lv0_n1,full_lv0_n2之前的数据变化。

SQL> alter database open read only;
alter database open read only
*
ERROR at line 1:
ORA-16004: backup database required recovery
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/data/test/system01.dbf'


SQL> 

SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1             964951
         2             964951
         3             964951
         4             964951
         5             964951

SQL> select file#,checkpoint_change# from v$datafile_header;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1             966164
         2             966164
         3             966164
         4             966164
         5             966164

---需要还原增量备份时的控制文件

SQL> startup nomount pfile='/home/oracle/pfile.ora' force
ORACLE instance started.

Total System Global Area  626327552 bytes
Fixed Size                  2255832 bytes
Variable Size             234882088 bytes
Database Buffers          385875968 bytes
Redo Buffers                3313664 bytes
SQL> 


MAN> restore controlfile from '/data/backup/incr_lv1_n1_0av2e87r_1_1.bak';

RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database: 
ORA-03135: connection lost contact
Process ID: 2343
Session ID: 18 Serial number: 11

Starting restore at 10-JUN-20
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================

RMAN> exit


Recovery Manager complete.
[oracle@db1 ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jun 10 21:21:06 2020

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

connected to target database: ORCL11G (not mounted)

RMAN> restore controlfile from '/data/backup/incr_lv1_n1_0av2e87r_1_1.bak'; <<<<

Starting restore at 10-JUN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/data/test/control01.ctl
Finished restore at 10-JUN-20


---restore控制文件后一定要rename datafile,redo log!!! 防止对源库文件写入

SQL> alter database mount;

Database altered.

alter database rename file '/oracle/app/oracle/oradata/orcl11g/system01.dbf' to '/data/test/system01.dbf';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/sysaux01.dbf' to '/data/test/sysaux01.dbf';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/undotbs01.dbf' to '/data/test/undotbs01.dbf';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/users01.dbf' to '/data/test/users01.dbf';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/users201.dbf' to '/data/test/users201.dbf';


alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo01.log' to '/data/redo01.log';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo02.log' to '/data/redo02.log';
alter database rename file '/oracle/app/oracle/oradata/orcl11g/redo03.log' to '/data/redo03.log';




SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1             966164
         2             966164
         3             966164
         4             966164
         5             966164

SQL> select file#,checkpoint_change# from v$datafile_header;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1             966164
         2             966164
         3             966164
         4             966164
         5             966164



SQL> alter database open read only;
alter database open read only
*
ERROR at line 1:
ORA-16004: backup database required recovery
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/data/test/system01.dbf'



RMAN> recover database;

Starting recover at 10-JUN-20
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database: 
ORA-19922: there is no parent row with id 0 and level 1


starting media recovery

unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/10/2020 21:29:51
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 966164

SQL> alter database open read only;

Database altered.



---验证该增量是否包含full_lv0_n1,full_lv0_n2之前的数据变化。

--test1,test2的记录都在哦
SQL> select * from dbmt.test1;

        ID C
---------- ----------------------------------------------------------------------------------------------------
         1 test_lv0_n1

SQL> select * from dbmt.test2;

        ID C
---------- ----------------------------------------------------------------------------------------------------
         1 test_lv0_n2

SQL> 


---下面验证增量备份时 FROM SCN <第一次LEVEL 0时的SCN,是否还会使用BCT

level 0 backup scn 964924
backup  incremental from scn  964923   as compressed backupset database tag='incr_lv1_n1'  format '/data/backup/incr_lv1_n1_%U.bak';



---多执行几次level 1增量备份

SQL> insert into dbmt.test1 values (9,'test1_1');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system checkpoint;

System altered.



backup  incremental level 1   as compressed backupset database  format '/data/backup/incr_lv1_t_%U.bak';


SQL> insert into dbmt.test1 values (9,'test1_2');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system checkpoint;

System altered.



---list backup

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
26      Incr 1  88.00K     DISK        00:00:01     10-JUN-20      
        BP Key: 26   Status: AVAILABLE  Compressed: YES  Tag: TAG20200610T214745
        Piece Name: /data/backup/incr_lv1_t_1nv2ea41_1_1.bak
  List of Datafiles in backup set 26
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1    1  Incr 1007443    10-JUN-20 /oracle/app/oracle/oradata/orcl11g/system01.dbf
  2    1  Incr 1007443    10-JUN-20 /oracle/app/oracle/oradata/orcl11g/sysaux01.dbf
  3    1  Incr 1007443    10-JUN-20 /oracle/app/oracle/oradata/orcl11g/undotbs01.dbf
  4    1  Incr 1007443    10-JUN-20 /oracle/app/oracle/oradata/orcl11g/users01.dbf
  5    1  Incr 1007443    10-JUN-20 /oracle/app/oracle/oradata/orcl11g/users201.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27      Incr 1  1.05M      DISK        00:00:01     10-JUN-20      
        BP Key: 27   Status: AVAILABLE  Compressed: YES  Tag: TAG20200610T214745
        Piece Name: /data/backup/incr_lv1_t_1ov2ea43_1_1.bak
  SPFILE Included: Modification time: 10-JUN-20
  SPFILE db_unique_name: ORCL11G
  Control File Included: Ckp SCN: 1007444      Ckp time: 10-JUN-20

RMAN> 

----跳着应用增量备份,看ORACLE检查不?
---经测试,oracle会检查,不可以跳过增量份集去recover
RMAN> catalog backuppiece '/data/backup/incr_lv1_t_1nv2ea41_1_1.bak';

cataloged backup piece
backup piece handle=/data/backup/incr_lv1_t_1nv2ea41_1_1.bak RECID=7 STAMP=1042753744

RMAN> recover database;

Starting recover at 10-JUN-20
using channel ORA_DISK_1

starting media recovery

unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/10/2020 21:49:07
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 966165


--把之前的备份集被上后可以正常recover
catalog backuppiece '/data/backup/incr_lv1_t_1lv2ea1n_1_1.bak';


RMAN> catalog backuppiece '/data/backup/incr_lv1_t_1lv2ea1n_1_1.bak';

cataloged backup piece
backup piece handle=/data/backup/incr_lv1_t_1lv2ea1n_1_1.bak RECID=8 STAMP=1042753989

RMAN> recover database;

Starting recover at 10-JUN-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /data/test/system01.dbf
destination for restore of datafile 00002: /data/test/sysaux01.dbf
destination for restore of datafile 00003: /data/test/undotbs01.dbf
destination for restore of datafile 00004: /data/test/users01.dbf
destination for restore of datafile 00005: /data/test/users201.dbf
channel ORA_DISK_1: reading from backup piece /data/backup/incr_lv1_t_1lv2ea1n_1_1.bak
channel ORA_DISK_1: piece handle=/data/backup/incr_lv1_t_1lv2ea1n_1_1.bak tag=TAG20200610T214631
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /data/test/system01.dbf
destination for restore of datafile 00002: /data/test/sysaux01.dbf
destination for restore of datafile 00003: /data/test/undotbs01.dbf
destination for restore of datafile 00004: /data/test/users01.dbf
destination for restore of datafile 00005: /data/test/users201.dbf
channel ORA_DISK_1: reading from backup piece /data/backup/incr_lv1_t_1nv2ea41_1_1.bak
channel ORA_DISK_1: piece handle=/data/backup/incr_lv1_t_1nv2ea41_1_1.bak tag=TAG20200610T214745
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery

unable to find archived log
archived log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/10/2020 21:53:14
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 966165


---应用增量备份,不会更新控制文件中文件的CHECKPOINT_CHANGE#

SQL> select file#,checkpoint_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1             966164
         2             966164
         3             966164
         4             966164
         5             966164

SQL> select file#,checkpoint_change# from v$datafile_header;

     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            1007443
         2            1007443
         3            1007443
         4            1007443
         5            1007443



backup  incremental from scn  964924   as compressed backupset database tag='incr_lv1_n1'  format '/data/backup/incr_lv1_n1_%U.bak';



---这里还遇到了一个问题,是我restore后新库没有禁用BCT,与源库共用一个BCT LOG,做recover导致源库宕
---禁用时还有一个坑,禁用这个动作会删除BCT LOG

Errors in file /oracle/app/oracle/diag/rdbms/orcl11g/orcl11g/trace/orcl11g_ctwr_2742.trc  (incident=12193):
ORA-00600: internal error code, arguments: [krccacp_badfile], [1007709], [0], [], [], [], [], [], [], [], [], []
Incident details in: /oracle/app/oracle/diag/rdbms/orcl11g/orcl11g/incident/incdir_12193/orcl11g_ctwr_2742_i12193.trc
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.
Errors in file /oracle/app/oracle/diag/rdbms/orcl11g/orcl11g/trace/orcl11g_ctwr_2742.trc:
ORA-00600: internal error code, arguments: [krccacp_badfile], [1007709], [0], [], [], [], [], [], [], [], [], []
CTWR (ospid: 2742): terminating the instance due to error 487
Wed Jun 10 21:54:39 2020
System state dump requested by (instance=1, osid=2742 (CTWR)), summary=[abnormal instance termination].
System State dumped to trace file /oracle/app/oracle/diag/rdbms/orcl11g/orcl11g/trace/orcl11g_diag_2702_20200610215439.trc
Dumping diagnostic data in directory=[cdmp_20200610215439], requested by (instance=1, osid=2742 (CTWR)), summary=[abnormal instance termination].
Instance terminated by CTWR, pid = 2742
Wed Jun 10 21:55:57 2020

piece handle=/data/backup/incr_lv1_n1_28v2eapq_1_1.bak tag=INCR_LV1_N1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 06/10/2020 21:59:22
ORA-19755: could not open change tracking file  <<<<<
ORA-19750: change tracking file: '/arch/block_change_track.f' <<<<<
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3



--当BCT LOG意外丢失后,禁用再启用即可

SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;

Database altered.

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING  using file '/arch/block_change_track.f' reuse;

Database altered.

SQL> 

诊断是否使用BCT

alter system set events ‘logon trace name krb_options level 26’;
–> take backup then disable tracing:
alter system set events ‘logon trace name krb_options off’;

trace 中搜索关键字
use change tracking for file

最后修改时间:2021-09-23 09:57:01
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论