1112catalog copy的資料檔案作為0級備份

lfree發表於2015-11-12

[20151112]catalog copy的資料檔案作為0級備份.txt

--使用熱備份模式備份的檔案是否可以作為0級備份呢?

--以前學習rman這部分內容時候有點混亂,無法理解為什麼使用rman backup as copy 的資料檔案與0級備份的資料檔案存在那些不同.
--是否使用熱備份以及backpup as copy備份的資料檔案是否可以作為0級備份.
--透過例子來說明:

1.測試環境:

SYS@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

SYS@book> alter  tablespace users begin  backup ;
Tablespace altered.

$ cp /mnt/ramdisk/book/users01.dbf /home/oracle/backup/

SYS@book> alter  tablespace users end  backup ;
Tablespace altered.

RMAN> list copy of tablespace users;
specification does not match any datafile copy in the repository

RMAN> list copy of datafile 4;
specification does not match any datafile copy in the repository

--可以發現使用熱備份模式的方式控制檔案不會記錄,畢竟這個os命令完成的備份,這也是淘汰熱備份模式主要原因.管理問題.

2.使用catalog註冊.

RMAN> catalog start with '/home/oracle/backup/users01.dbf';
searching for all files that match the pattern /home/oracle/backup/users01.dbf
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/backup/users01.dbf
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /home/oracle/backup/users01.dbf


RMAN> list copy of tablespace users;
List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
2       4    A 2015-11-12 09:20:23 1558886    2015-11-12 09:14:58
        Name: /home/oracle/backup/users01.dbf

--可以發現記錄的備份是按照copy方式做了.

RMAN> backup as copy datafile 4 format '/home/oracle/backup/datafile_4_%N.dbf';
Starting backup at 2015-11-12 09:27:07
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
output file name=/home/oracle/backup/datafile_4_USERS.dbf tag=TAG20151112T092707 RECID=3 STAMP=895570027
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-11-12 09:27:08

RMAN> list copy of datafile 4;
List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
3       4    A 2015-11-12 09:27:07 1559316    2015-11-12 09:27:07
        Name: /home/oracle/backup/datafile_4_USERS.dbf
        Tag: TAG20151112T092707

2       4    A 2015-11-12 09:20:23 1558886    2015-11-12 09:14:58
        Name: /home/oracle/backup/users01.dbf


3.理論講這些檔案可以作為0級備份:

RMAN> catalog datafilecopy '/home/oracle/backup/users01.dbf' level 0 ;
cataloged datafile copy

RMAN> list copy of datafile 4;

List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
3       4    A 2015-11-12 09:27:07 1559316    2015-11-12 09:27:07
        Name: /home/oracle/backup/datafile_4_USERS.dbf
        Tag: TAG20151112T092707

5       4    A 2015-11-12 09:30:59 1558886    2015-11-12 09:14:58
        Name: /home/oracle/backup/users01.dbf

--注意看key已經變成了5.

RMAN> BACKUP INCREMENTAL LEVEL 1 datafile 4 format '/home/oracle/backup/inc_user01_%U.dbf';

Starting backup at 2015-11-12 09:37:25
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-12 09:37:26
channel ORA_DISK_1: finished piece 1 at 2015-11-12 09:37:27
piece handle=/home/oracle/backup/inc_user01_08qm2kmm_1_1.dbf tag=TAG20151112T093725 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-12 09:37:27

$ ll /home/oracle/backup/
total 97440
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:27 datafile_4_USERS.dbf
-rw-r----- 1 oracle oinstall    40960 Nov 12 09:37 inc_user01_08qm2kmm_1_1.dbf
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:15 users01.dbf

RMAN> list backupset ;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
7       Incr 1  32.00K     DISK        00:00:00     2015-11-12 09:37:26
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20151112T093725
        Piece Name: /home/oracle/backup/inc_user01_08qm2kmm_1_1.dbf
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  4    1  Incr 1560000    2015-11-12 09:37:26 /mnt/ramdisk/book/users01.dbf

--檔案大小也可以說明問題.可以確定熱備份已經作為0級備份.

4.對比看看:
--使用增量0級備份看看:

RMAN> BACKUP INCREMENTAL LEVEL 0 datafile 4 format '/home/oracle/backup/inc0_user01_%U.dbf';
Starting backup at 2015-11-12 09:39:44
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-12 09:39:44
channel ORA_DISK_1: finished piece 1 at 2015-11-12 09:39:45
piece handle=/home/oracle/backup/inc0_user01_09qm2kr0_1_1.dbf tag=TAG20151112T093944 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-12 09:39:45

RMAN> host "ls -l /home/oracle/backup";
total 142088
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:27 datafile_4_USERS.dbf
-rw-r----- 1 oracle oinstall 45670400 Nov 12 09:39 inc0_user01_09qm2kr0_1_1.dbf
-rw-r----- 1 oracle oinstall    40960 Nov 12 09:37 inc_user01_08qm2kmm_1_1.dbf
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:15 users01.dbf
host command complete

RMAN> host "ls -l /mnt/ramdisk/book/users01.dbf";
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:39 /mnt/ramdisk/book/users01.dbf
host command complete

--注意看檔案大小,實際上0級備份與copy方式兩者存在不同.0級備份也是備份僅僅使用的塊,以這個備份為基礎,做1級備份,或者1級累積
--備份.實際上還可以在備份時選擇壓縮模式.

RMAN> BACKUP as compressed backupset  INCREMENTAL LEVEL 0 datafile 4  format '/home/oracle/backup/inc0_user01_%U.dbf';

Starting backup at 2015-11-12 09:49:01
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=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-12 09:49:01
channel ORA_DISK_1: finished piece 1 at 2015-11-12 09:49:02
piece handle=/home/oracle/backup/inc0_user01_0aqm2lcd_1_1.dbf tag=TAG20151112T094901 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-12 09:49:02

RMAN> host "ls -l /home/oracle/backup";
total 143452
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:27 datafile_4_USERS.dbf
-rw-r----- 1 oracle oinstall 45670400 Nov 12 09:39 inc0_user01_09qm2kr0_1_1.dbf
-rw-r----- 1 oracle oinstall  1392640 Nov 12 09:49 inc0_user01_0aqm2lcd_1_1.dbf
-rw-r----- 1 oracle oinstall    40960 Nov 12 09:37 inc_user01_08qm2kmm_1_1.dbf
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:15 users01.dbf
host command complete

-- 注意看檔案大小.

5.好了,現在刪除一些備份,僅僅留下as copy方式的備份:
RMAN> delete backupset 7,8,9;
using channel ORA_DISK_1
List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
7       7       1   1   AVAILABLE   DISK        /home/oracle/backup/inc_user01_08qm2kmm_1_1.dbf
8       8       1   1   AVAILABLE   DISK        /home/oracle/backup/inc0_user01_09qm2kr0_1_1.dbf
9       9       1   1   AVAILABLE   DISK        /home/oracle/backup/inc0_user01_0aqm2lcd_1_1.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/home/oracle/backup/inc_user01_08qm2kmm_1_1.dbf RECID=7 STAMP=895570646
deleted backup piece
backup piece handle=/home/oracle/backup/inc0_user01_09qm2kr0_1_1.dbf RECID=8 STAMP=895570784
deleted backup piece
backup piece handle=/home/oracle/backup/inc0_user01_0aqm2lcd_1_1.dbf RECID=9 STAMP=895571341
Deleted 3 objects

RMAN> delete copy of datafile 4 completed after '2015-11-12 09:30:59';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=394 device type=DISK
List of Datafile Copies
=======================
Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
5       4    A 2015-11-12 09:30:59 1558886    2015-11-12 09:14:58
        Name: /home/oracle/backup/users01.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted datafile copy
datafile copy file name=/home/oracle/backup/users01.dbf RECID=5 STAMP=895570259
Deleted 1 objects

RMAN> list copy of database;
List of Datafile Copies
=======================
Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
3       4    A 2015-11-12 09:27:07 1559316    2015-11-12 09:27:07
        Name: /home/oracle/backup/datafile_4_USERS.dbf
        Tag: TAG20151112T092707

RMAN> list backupset summary;
specification does not match any backup in the repository

--做1個增量1級備份:
RMAN> BACKUP INCREMENTAL LEVEL 1 datafile 4  format '/home/oracle/backup/inc1_user01_%U.dbf';
Starting backup at 2015-11-12 10:30:44
using channel ORA_DISK_1
no parent backup or copy of datafile 4 found
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-12 10:30:44
channel ORA_DISK_1: finished piece 1 at 2015-11-12 10:30:45
piece handle=/home/oracle/backup/inc1_user01_0bqm2nqk_1_1.dbf tag=TAG20151112T103044 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-12 10:30:45

RMAN> host "ls -l /home/oracle/backup";
total 93348
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:27 datafile_4_USERS.dbf
-rw-r----- 1 oracle oinstall 45670400 Nov 12 10:30 inc1_user01_0bqm2nqk_1_1.dbf
host command complete

--可以發現增量備份雖然是1級,因為不存在0級備份,備份檔案實際上是0級.as copy方式的備份沒有作為0級備份.

RMAN> list backupset ;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
10      Incr 0  43.55M     DISK        00:00:00     2015-11-12 10:30:44
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20151112T103044
        Piece Name: /home/oracle/backup/inc1_user01_0bqm2nqk_1_1.dbf
  List of Datafiles in backup set 10
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  4    0  Incr 1562428    2015-11-12 10:30:44 /mnt/ramdisk/book/users01.dbf

--注意看LV=0 , 表示0級備份,說明沒有指定as copy作為0級備份.

RMAN> BACKUP INCREMENTAL LEVEL 1 datafile 4  format '/home/oracle/backup/inc1_user01_%U.dbf';
Starting backup at 2015-11-12 10:34:13
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-12 10:34:13
channel ORA_DISK_1: finished piece 1 at 2015-11-12 10:34:14
piece handle=/home/oracle/backup/inc1_user01_0cqm2o15_1_1.dbf tag=TAG20151112T103413 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-12 10:34:14

RMAN> host "ls -l /home/oracle/backup";
total 93388
-rw-r----- 1 oracle oinstall 49815552 Nov 12 09:27 datafile_4_USERS.dbf
-rw-r----- 1 oracle oinstall 45670400 Nov 12 10:30 inc1_user01_0bqm2nqk_1_1.dbf
-rw-r----- 1 oracle oinstall    40960 Nov 12 10:34 inc1_user01_0cqm2o15_1_1.dbf
host command complete

RMAN> list backupset summary;


List of Backups
===============
Key     TY LV S Device Type Completion Time     #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
10      B  0  A DISK        2015-11-12 10:30:44 1       1       NO         TAG20151112T103044
11      B  1  A DISK        2015-11-12 10:34:13 1       1       NO         TAG20151112T103413

--注意看lv,第2次才是1級備份,前面第1次是0級備份(因為0級不存在).再看看這個as copy的備份能否作為0級備份.
RMAN> catalog datafilecopy '/home/oracle/backup/datafile_4_USERS.dbf' level 0 ;

cataloged datafile copy
datafile copy file name=/home/oracle/backup/datafile_4_USERS.dbf RECID=6 STAMP=895574253

RMAN> list datafilecopy all;
List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time
------- ---- - ------------------- ---------- -------------------
6       4    A 2015-11-12 10:37:33 1559316    2015-11-12 09:27:07
        Name: /home/oracle/backup/datafile_4_USERS.dbf
        Tag: TAG20151112T092707

--key變成了6.不過那裡能看出來這個copy備份作為0級備份呢?

RMAN> catalog datafilecopy '/home/oracle/backup/datafile_4_USERS.dbf' level 1 ;

cataloged datafile copy
datafile copy file name=/home/oracle/backup/datafile_4_USERS.dbf RECID=7 STAMP=895574636

--key變成了7. 還是不知道那裡能看出來這個copy備份作為1級備份呢?不知道那位知道.

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

相關文章