基於oracle 11.2.0.4 rman data file copy以及增量scn備份資料檔案持續變化系列之二

wisdomone1發表於2017-06-11
測試結論
1,歷史相關舊文
20170611星期日之基於oracle 11.2.0.4 rman data file copy以及增量scn備份資料檔案持續變化系列之一.js


2,在第一次增量SCN的DATA FILE RMAN備份之後的多次增量基於SCN的增量RMAN備份的起點SCN的來源為




SQL> conn /as sysdba
Connected.
SQL> select file#,checkpoint_change# from v$datafile where file#=9;


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5920877


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


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5920877




3,結合如上,資料檔案則可以一直基於初次的data file copy以及後續多次增量資料檔案RMAN備份,把資料拉平,達到最大的資料一致性         


測試明細


1,上次的v$backup_datafile資訊
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';


Session altered.


SQL> set linesize 300
SQL> select recid,file#,incremental_level,incremental_change#,checkpoint_change#,COMPLETION_TIME from v$backup_datafile where file#=9
  2  ;


     RECID      FILE# INCREMENTAL_LEVEL INCREMENTAL_CHANGE# CHECKPOINT_CHANGE# COMPLETION_TIME
---------- ---------- ----------------- ------------------- ------------------ -------------------
        11          9                 1             5889250            5914431 2017-06-11 16:29:44
        12          9                 1             5914431            5914455 2017-06-11 16:30:25


SQL> 


2,對資料檔案9進行datafile copy
[oracle@mygirl ~]$ rman target /


Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jun 11 18:52:35 2017


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


connected to target database: MYGIRL (DBID=2527996082)


RMAN> backup as copy datafile 9 tag 'datafile 9 copy note' format '/home/oracle/datafile_9_%u_%d.bak';


Starting backup at 11-JUN-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=/oracle/mygirl/tbs_obj01.dbf
output file name=/home/oracle/datafile_9_0qs6i1o4_MYGIRL.bak tag=DATAFILE 9 COPY NOTE RECID=13 STAMP=946407173
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 11-JUN-17


3,可見v$backup_datafile不記得對於datafile copy操作
SQL> select recid,file#,incremental_level,incremental_change#,checkpoint_change#,COMPLETION_TIME from v$backup_datafile where file#=9
  2  ;


     RECID      FILE# INCREMENTAL_LEVEL INCREMENTAL_CHANGE# CHECKPOINT_CHANGE# COMPLETION_TIME
---------- ---------- ----------------- ------------------- ------------------ -------------------
        11          9                 1             5889250            5914431 2017-06-11 16:29:44
        12          9                 1             5914431            5914455 2017-06-11 16:30:25


SQL> 




4,暫停下,先另啟一個主題,研究下資料檔案的scn可否在mount狀態下查檢視,可見在mount狀態也可以檢視資料檔案的scn
SQL> select open_mode from v$database;


OPEN_MODE
--------------------
READ WRITE


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


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5919972




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


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5919972




SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area 2137886720 bytes
Fixed Size                  2254952 bytes
Variable Size            2080376728 bytes
Database Buffers           50331648 bytes
Redo Buffers                4923392 bytes
Database mounted.




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


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5920457


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


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5920457




5,回到原來的主題上,繼續測試研究在首次基於v$datafile_copy確認之backup incremental from scn 5915956 datafile 9 format '/home/oracle/incr_bak_%u_%d.bak'所使用的scn後,之後每次增量備份的SCN從哪兒獲取


RMAN> backup as copy datafile 9  format '/home/oracle/datafile_9_copy_first_%u_%d.bak' tag 'datafile9_copy_first_1';


Starting backup at 11-JUN-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=/oracle/mygirl/tbs_obj01.dbf
output file name=/home/oracle/datafile_9_copy_first_0rs6i2lb_MYGIRL.bak tag=DATAFILE9_COPY_FIRST_1 RECID=14 STAMP=946408107
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 11-JUN-17






SQL> conn user_obj/system
Connected.
SQL> create table t_facebook(a int);


Table created.


SQL> insert into t_facebook values(1);


1 row created.


SQL> commit;


Commit complete.






SQL> set linesize 300
SQL> col name for a50
SQL> select recid,name,file#,incremental_level,checkpoint_time,checkpoint_change# from v$datafile_copy where file#=9;


     RECID NAME                                                    FILE# INCREMENTAL_LEVEL CHECKPOIN CHECKPOINT_CHANGE#
---------- -------------------------------------------------- ---------- ----------------- --------- ------------------
        10 /oracle/product/11.2.0/db_1/dbs/data_D-MYGIRL_I-25          9                   11-JUN-17            5913749
           27996082_TS-TBS_OBJ_FNO-9_0gs6hotj


        11                                                             9                   11-JUN-17            5914455
        12 /home/oracle/datafile_9_0ns6hr1i_MYGIRL.bak                 9                   11-JUN-17            5915956
        13 /home/oracle/datafile_9_0qs6i1o4_MYGIRL.bak                 9                   11-JUN-17            5919972
        14 /home/oracle/datafile_9_copy_first_0rs6i2lb_MYGIRL          9                   11-JUN-17            5920457
           .bak








[oracle@mygirl ~]$ rman target /


Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jun 11 19:15:07 2017


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


connected to target database: MYGIRL (DBID=2527996082)


RMAN> backup incremental from scn 5920457 datafile 9 format '/home/oracle/incr_bak_5920457_%u_%d.bak'; 


Starting backup at 11-JUN-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 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=00009 name=/oracle/mygirl/tbs_obj01.dbf
channel ORA_DISK_1: starting piece 1 at 11-JUN-17
channel ORA_DISK_1: finished piece 1 at 11-JUN-17
piece handle=/home/oracle/incr_bak_5920457_0ss6i31u_MYGIRL.bak tag=TAG20170611T191510 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting 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 11-JUN-17
channel ORA_DISK_1: finished piece 1 at 11-JUN-17
piece handle=/home/oracle/incr_bak_5920457_0ts6i31v_MYGIRL.bak tag=TAG20170611T191510 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JUN-17






SQL> conn user_obj/system
Connected.
SQL> create table t_newly(a int);


Table created.


SQL> insert into t_newly values(1);


1 row created.


SQL> commit;


Commit complete.






SQL> conn /as sysdba
Connected.
SQL> select file#,checkpoint_change# from v$datafile where file#=9;


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5920877


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


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
         9            5920877






[oracle@mygirl ~]$ rman target /


Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jun 11 19:18:08 2017


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


connected to target database: MYGIRL (DBID=2527996082)


RMAN> backup incremental from scn 5920877 datafile 9 format '/home/oracle/incr_bak_5920877_%u_%d.bak'; 


Starting backup at 11-JUN-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 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=00009 name=/oracle/mygirl/tbs_obj01.dbf
channel ORA_DISK_1: starting piece 1 at 11-JUN-17
channel ORA_DISK_1: finished piece 1 at 11-JUN-17
piece handle=/home/oracle/incr_bak_5920877_0us6i39f_MYGIRL.bak tag=TAG20170611T191911 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting 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 11-JUN-17
channel ORA_DISK_1: finished piece 1 at 11-JUN-17
piece handle=/home/oracle/incr_bak_5920877_0vs6i39h_MYGIRL.bak tag=TAG20170611T191911 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JUN-17






SQL> host mv /oracle/mygirl/tbs_obj01.dbf /oracle/mygirl/tbs_obj01.dbf.origbak


SQL> conn user_obj/system
Connected.


SQL> create table t_mod1(a int);


Table created.


SQL> insert into t_mod1 values(1);
insert into t_mod1 values(1)
            *
ERROR at line 1:
ORA-01116: error in opening database file 9
ORA-01110: data file 9: '/oracle/mygirl/tbs_obj01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3




[oracle@mygirl ~]$ rman target /


Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jun 11 19:21:38 2017


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


connected to target database: MYGIRL (DBID=2527996082)


RMAN> sql 'alter database datafile 9 offline';


using target database control file instead of recovery catalog
sql statement: alter database datafile 9 offline






RMAN> restore datafile 9 from tag 'datafile9_copy_first_1';


Starting restore at 11-JUN-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK


channel ORA_DISK_1: restoring datafile 00009
input datafile copy RECID=14 STAMP=946408107 file name=/home/oracle/datafile_9_copy_first_0rs6i2lb_MYGIRL.bak
destination for restore of datafile 00009: /oracle/mygirl/tbs_obj01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00009
output file name=/oracle/mygirl/tbs_obj01.dbf RECID=0 STAMP=0
Finished restore at 11-JUN-17






RMAN> recover datafile 9 from tag 'TAG20170611T191510';


Starting recover at 11-JUN-17
using channel ORA_DISK_1


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


Finished recover at 11-JUN-17






RMAN> recover datafile 9 from tag 'TAG20170611T191911';


Starting recover at 11-JUN-17
using channel ORA_DISK_1


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


Finished recover at 11-JUN-17




RMAN> sql 'alter database datafile 9 online';


sql statement: alter database datafile 9 online




[oracle@mygirl ~]$ sqlplus user_obj/system


SQL*Plus: Release 11.2.0.4.0 Production on Sun Jun 11 19:32:40 2017


Copyright (c) 1982, 2013, Oracle.  All rights reserved.




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select * from t_newly;


         A
----------
         1






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

相關文章