您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何深入解析RMAN備份與恢復,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
RMAN備份與恢復深入解析
1.用示例說明兩種增量備份的差別
大家早上好,早上的陽光真是明媚,新的一天即將開始,下面我們來研究研究增量備份的奧妙:)
Incremental增量備份:中心思想就是減少備份的數據量,我們不需要在從頭開始備份了,只需要備份自上次已備份之后的數據塊即可。
關于Incremental增量備份級別:
Oracle 9i 共有五種級別 0 1 2 3 4,0級最高-4級最低,0級是1級的基礎以此類推。
Oracle 10g官方文檔明確指出增量備份只有0和1兩種級別(太多增量級別其實沒有太大的意義),不過實際執行增量操作時,仍然能夠指定多個級別,最大能夠支持4級增量備份。
Oracle 11g 增量備份只有0和1兩種級別。
Level 0級就是對數據庫一個全庫備份,增量備份必須從0級開始,也就是說必須要有一個全庫備份當基礎。
如果你是用“backup full database”命令做全庫備份oracle也不認為這是level 0的全庫備份,盡管是一樣的也要單獨做一次level 0。有了level 0當基礎才能有后面的level 1 level 2 level 3 level 4。如果你一上來比較沖動直接發出level 1備份,oracle會自動在level1前面加一個level 0,順序是先進行level 0備份再做level 1備份,一共做兩次備份。
關于Incremental增量備份類型:
(1)差異增量備份:備份上級及同級備份以來所有變化的數據塊,差異增量是默認增量備份方式
特點:觸發條件小于等于當前級別<=N 備份時間快,恢復時間慢
(2)累積增量備份:備份上級備份以來所有變化的塊。
特點:小于當前級別<N 備份時間慢,恢復時間快 C:代表累積
我們系統的備份策略(周策略),僅供參考,如有雷同心心相印,歐巴~阿加西
日期 差異增量 累積增量
星期天 0 0
星期一 2 2
星期二 2 2
星期三 1 1
星期四 2 2
星期五 2 2
星期六 2 2
星期日 0 0
下面我們實驗差異增量備份與累積增量備份~備份時間與恢復窗口優略性
差異增量備份
零級備份
backupincremental level 0 database;
創建表空間test1
創建表test1
一級差異備份
backupincremental level 1 database;
創建表空間test2
創建表test2
一級差異備份
backupincremental level 1 database;
記住當前的scn號(10000),我們刪除表test1和表test2,然后恢復到scn=10000那一刻,檢查表test1和表test2是否完整恢復回來,恢復窗口:恢復三個備份集 0+1+1+redo
begin go
0級全庫備份
RMAN> backup incremental level 0 database;
Starting backup at 10-MAY-13
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=00001name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00004name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-13
channel ORA_DISK_1: finished piece 1 at 10-MAY-13
piece handle= /u02/app/oracle/backup/DB_0lo99q5p_1_1 tag=TAG20130510T150112 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
Finished backup at 10-MAY-13
控制文件自動備份
Starting Control File and SPFILE Autobackup at 10-MAY-13
piece handle= /u02/app/oracle/backup/control/cf_c-1692458681-20130510-00 comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-13
操作系統側面檢查,順利備份沒有問題 good
[oracle@leonarding1 backup]$ ll
total 983928
drwxr-xr-x 2 oracle oinstall 4096 May 10 15:02 control
-rw-r----- 1 oracle asmadmin 1007534080 May 10 15:02 DB_0lo99q5p_1_1
[oracle@leonarding1 control]$ ll
total 9632
-rw-r----- 1 oracle asmadmin 9863168 May 10 15:02cf_c-1692458681-20130510-00
創建test1表空間
SYS@LEO1>create tablespace test1 datafile'/u02/app/oracle/oradata/LEO1/test1_01.dbf' size 20m autoextend off;
Tablespace created.
創建test1表
SYS@LEO1>conn leo1/leo1
Connected.
LEO1@LEO1>create table test1 tablespace test1 as select * fromdba_objects;
Table created.
LEO1@LEO1>select checkpoint_change# from v$database; 每做完一個動作我們都記錄下SCN號
CHECKPOINT_CHANGE#
------------------
1079203
1級差異備份
RMAN> backup incremental level 1 database;
Starting backup at 10-MAY-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=00001name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003 name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00006name=/u02/app/oracle/oradata/LEO1/test1_01.dbf 這次多了test1表空間
input datafile file number=00004name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-13
channel ORA_DISK_1: finished piece 1 at 10-MAY-13
piece handle=/u02/app/oracle/backup/DB_0no99r4r_1_1 tag=TAG20130510T151746comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:15
Finished backup at 10-MAY-13
Starting Control File and SPFILE Autobackup at 10-MAY-13
piece handle=/u02/app/oracle/backup/control/cf_c-1692458681-20130510-01comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-13
創建test2表空間
LEO1@LEO1>create tablespace test2 datafile'/u02/app/oracle/oradata/LEO1/test2_01.dbf' size 20m autoextend off;
Tablespace created.
創建test2表
LEO1@LEO1>create table test2 tablespace test2 as select * fromdba_objects;
Table created.
LEO1@LEO1>select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1079213
再次1級差異備份
RMAN> backup incremental level 1 database;
Starting backup at 10-MAY-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=00001name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00006name=/u02/app/oracle/oradata/LEO1/test1_01.dbf
input datafile file number=00007 name=/u02/app/oracle/oradata/LEO1/test2_01.dbf 這次又多了test1表空間
input datafile file number=00004name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-13
channel ORA_DISK_1: finished piece 1 at 10-MAY-13
piece handle=/u02/app/oracle/backup/DB_0qo99s79_1_1 tag=TAG20130510T153609comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:05
Finished backup at 10-MAY-13
Starting Control File and SPFILE Autobackup at 10-MAY-13
piece handle=/u02/app/oracle/backup/control/cf_c-1692458681-20130510-03comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-13
SYS@LEO1>select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1084254
SYS@LEO1>alter system switch logfile; 我們做一次日志切換從2 -> 3
System altered.
SYS@LEO1>archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/app/oracle/archdata
Oldest online log sequence 1
Next log sequence to archive 3
Current log sequence 3
SYS@LEO1>alter system switch logfile; 為了保險我們再切一次,當前日志序號為4
System altered.
SYS@LEO1>conn leo1/leo1
Connected.
LEO1@LEO1>drop table test1 purge; 我們刪除test1和test2表
Table dropped.
LEO1@LEO1>drop table test2 purge;
Table dropped.
現在我們想恢復到沒刪除之前的狀態,有2種方法(1)恢復到scn=1084254 (2)恢復到sequence=3
檢查一下備份集集
RMAN> list backupset;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19 Incr 0 960.85M DISK 00:01:21 10-MAY-13
BP Key: 19 Status: AVAILABLE Compressed: NO Tag: TAG20130510T150112
Piece Name:/u02/app/oracle/backup/DB_0lo99q5p_1_1
List of Datafiles in backup set 19
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- -------------
1 0 Incr 1081294 10-MAY-13/u02/app/oracle/oradata/LEO1/system01.dbf
2 0 Incr 1081294 10-MAY-13/u02/app/oracle/oradata/LEO1/sysaux01.dbf
3 0 Incr 1081294 10-MAY-13/u02/app/oracle/oradata/LEO1/undotbs01.dbf
4 0 Incr 1081294 10-MAY-13/u02/app/oracle/oradata/LEO1/users01.dbf
5 0 Incr 1081294 10-MAY-13/u02/app/oracle/oradata/LEO1/leo1.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
20 Full 9.39M DISK 00:00:01 10-MAY-13
BP Key: 20 Status: AVAILABLE Compressed: NO Tag: TAG20130510T150238
Piece Name:/u02/app/oracle/backup/control/cf_c-1692458681-20130510-00
SPFILE Included: Modificationtime: 30-APR-13
SPFILE db_unique_name: LEO1
Control File Included: Ckp SCN:1081329 Ckp time: 10-MAY-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21 Incr 1 19.38M DISK 00:02:08 10-MAY-13
BP Key: 21 Status: AVAILABLE Compressed: NO Tag: TAG20130510T151746
Piece Name:/u02/app/oracle/backup/DB_0no99r4r_1_1
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- -------------
1 1 Incr 1083510 10-MAY-13/u02/app/oracle/oradata/LEO1/system01.dbf
2 1 Incr 1083510 10-MAY-13/u02/app/oracle/oradata/LEO1/sysaux01.dbf
3 1 Incr 1083510 10-MAY-13/u02/app/oracle/oradata/LEO1/undotbs01.dbf
4 1 Incr 1083510 10-MAY-13/u02/app/oracle/oradata/LEO1/users01.dbf
5 1 Incr 1083510 10-MAY-13/u02/app/oracle/oradata/LEO1/leo1.dbf
6 1 Incr 1083510 10-MAY-13/u02/app/oracle/oradata/LEO1/test1_01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22 Full 9.39M DISK 00:00:01 10-MAY-13
BP Key: 22 Status: AVAILABLE Compressed: NO Tag: TAG20130510T152002
Piece Name: /u02/app/oracle/backup/control/cf_c-1692458681-20130510-01
SPFILE Included: Modificationtime: 10-MAY-13
SPFILE db_unique_name: LEO1
Control File Included: Ckp SCN:1083563 Ckp time: 10-MAY-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
23 Full 9.39M DISK 00:00:02 10-MAY-13
BP Key: 23 Status: AVAILABLE Compressed: NO Tag: TAG20130510T152849
Piece Name: /u02/app/oracle/backup/control/cf_c-1692458681-20130510-02
SPFILE Included: Modificationtime: 10-MAY-13
SPFILE db_unique_name: LEO1
Control File Included: Ckp SCN:1084027 Ckp time: 10-MAY-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
24 Incr 1 9.90M DISK 00:02:00 10-MAY-13
BP Key: 24 Status: AVAILABLE Compressed: NO Tag: TAG20130510T153609
Piece Name:/u02/app/oracle/backup/DB_0qo99s79_1_1
List of Datafiles in backup set 24
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- -------------
1 1 Incr 1084375 10-MAY-13/u02/app/oracle/oradata/LEO1/system01.dbf
2 1 Incr 1084375 10-MAY-13 /u02/app/oracle/oradata/LEO1/sysaux01.dbf
3 1 Incr 1084375 10-MAY-13/u02/app/oracle/oradata/LEO1/undotbs01.dbf
4 1 Incr 1084375 10-MAY-13/u02/app/oracle/oradata/LEO1/users01.dbf
5 1 Incr 1084375 10-MAY-13/u02/app/oracle/oradata/LEO1/leo1.dbf
6 1 Incr 1084375 10-MAY-13/u02/app/oracle/oradata/LEO1/test1_01.dbf
7 1 Incr 1084375 10-MAY-13/u02/app/oracle/oradata/LEO1/test2_01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
25 Full 9.39M DISK 00:00:01 10-MAY-13
BP Key: 25 Status: AVAILABLE Compressed: NO Tag: TAG20130510T153814
Piece Name:/u02/app/oracle/backup/control/cf_c-1692458681-20130510-03
SPFILE Included: Modificationtime: 10-MAY-13
SPFILE db_unique_name: LEO1
Control File Included: Ckp SCN:1084436 Ckp time: 10-MAY-13
從這個size大小上就可以看出 960.85M->19.38M->9.90M咱們做的都是增量備份,那么好現在開始恢復
SYS@LEO1>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@LEO1>startup mount 啟動mount狀態恢復
ORACLE instance started.
Total System Global Area 471830528bytes
Fixed Size 2214456bytes
Variable Size 184550856 bytes
Database Buffers 276824064bytes
Redo Buffers 8241152bytes
Database mounted.
RMAN 進行基于SCN號不完全恢復
RMAN> restore database until scn 1084254;
Starting restore at 10-MAY-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
creating datafile file number=7name=/u02/app/oracle/oradata/LEO1/test2_01.dbf
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/u02/app/oracle/oradata/LEO1/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to/u02/app/oracle/oradata/LEO1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to/u02/app/oracle/oradata/LEO1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to/u02/app/oracle/oradata/LEO1/leo1.dbf
channel ORA_DISK_1: reading from backup piece /u02/app/oracle/backup/DB_0lo99q5p_1_1 從0級備份開始恢復
channel ORA_DISK_1: piece handle=/u02/app/oracle/backup/DB_0lo99q5p_1_1tag=TAG20130510T150112
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
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 00006 to/u02/app/oracle/oradata/LEO1/test1_01.dbf
channel ORA_DISK_1: reading from backup piece /u02/app/oracle/backup/DB_0no99r4r_1_1 再恢復1級
channel ORA_DISK_1: piece handle=/u02/app/oracle/backup/DB_0no99r4r_1_1tag=TAG20130510T151746
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 10-MAY-13
RMAN> recover database until scn 1084254; 同步scn號
Starting recover at 10-MAY-13
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:/u02/app/oracle/oradata/LEO1/system01.dbf
destination for restore of datafile 00002:/u02/app/oracle/oradata/LEO1/sysaux01.dbf
destination for restore of datafile 00003:/u02/app/oracle/oradata/LEO1/undotbs01.dbf
destination for restore of datafile 00004:/u02/app/oracle/oradata/LEO1/users01.dbf
destination for restore of datafile 00005:/u02/app/oracle/oradata/LEO1/leo1.dbf
channel ORA_DISK_1: reading from backup piece/u02/app/oracle/backup/DB_0no99r4r_1_1
channel ORA_DISK_1: piece handle=/u02/app/oracle/backup/DB_0no99r4r_1_1tag=TAG20130510T151746
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
starting media recovery
archived log for thread 1 with sequence 1 is already on disk as file/u02/app/oracle/archdata/1_1_814107939.dbf
archived log file name=/u02/app/oracle/archdata/1_1_814107939.dbf thread=1sequence=1
media recovery complete, elapsed time: 00:00:02
Finished recover at 10-MAY-13
RMAN> alter database open resetlogs; 非一致性打開
database opened
累積增量備份
零級備份
backup incremental level 0 cumulative database;
創建表空間test3
創建表test3
一級累積備份
backup incremental level 1 cumulative database;
創建表空間test4
創建表test4
一級累積備份
backup incremental level 1 cumulative database;
記住當前的sequence號,我們刪除表test3和表test4,然后恢復到sequence那一刻,檢查表test3和表test4是否完整恢復回來,恢復窗口:恢復兩個備份集 0+1(最后一次備份)+redo
下面我們就做的快一點啦
RMAN> backup incremental level 0 cumulative database; 0級累積增量備份
Starting backup at 10-MAY-13
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=00001 name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00006name=/u02/app/oracle/oradata/LEO1/test1_01.dbf
input datafile file number=00007name=/u02/app/oracle/oradata/LEO1/test2_01.dbf
input datafile file number=00004name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-13
channel ORA_DISK_1: finished piece 1 at 10-MAY-13
piece handle=/u02/app/oracle/backup/DB_0to99v4v_1_1 tag=TAG20130510T162607comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
Finished backup at 10-MAY-13
Starting Control File and SPFILE Autobackup at 10-MAY-13
piece handle=/u02/app/oracle/backup/control/cf_c-1692458681-20130510-05comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-13
創建表空間和表test3
LEO1@LEO1>create tablespace test3 datafile'/u02/app/oracle/oradata/LEO1/test3_01.dbf' size 20m autoextend off;
Tablespace created.
LEO1@LEO1>create table test3 tablespace test3 as select * fromdba_objects;
Table created.
1級累積備份
RMAN> backup incremental level 1 cumulative database;
Starting backup at 10-MAY-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=00001name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00006name=/u02/app/oracle/oradata/LEO1/test1_01.dbf
input datafile file number=00007name=/u02/app/oracle/oradata/LEO1/test2_01.dbf
input datafile file number=00008name=/u02/app/oracle/oradata/LEO1/test3_01.dbf
input datafile file number=00004 name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-13
channel ORA_DISK_1: finished piece 1 at 10-MAY-13
piece handle= /u02/app/oracle/backup/DB_0vo99vgi_1_1 tag=TAG20130510T163217 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:05
Finished backup at 10-MAY-13
Starting Control File and SPFILE Autobackup at 10-MAY-13
piece handle=/u02/app/oracle/backup/control/cf_c-1692458681-20130510-06comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-13
創建表空間和表test4
LEO1@LEO1>create tablespace test4 datafile'/u02/app/oracle/oradata/LEO1/test4_01.dbf' size 20m autoextend off;
Tablespace created.
LEO1@LEO1>create table test4 tablespace test4 as select * fromdba_objects;
Table created.
再一次1級累積備份
RMAN> backup incremental level 1 cumulative database;
Starting backup at 10-MAY-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=00001name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005 name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00006name=/u02/app/oracle/oradata/LEO1/test1_01.dbf
input datafile file number=00007name=/u02/app/oracle/oradata/LEO1/test2_01.dbf
input datafile file number=00008 name=/u02/app/oracle/oradata/LEO1/test3_01.dbf
input datafile file number=00009name=/u02/app/oracle/oradata/LEO1/test4_01.dbf
input datafile file number=00004name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAY-13
channel ORA_DISK_1: finished piece 1 at 10-MAY-13
piece handle= /u02/app/oracle/backup/DB_11o99vpa_1_1 tag=TAG20130510T163657 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 10-MAY-13
Starting Control File and SPFILE Autobackup at 10-MAY-13
piece handle=/u02/app/oracle/backup/control/cf_c-1692458681-20130510-07comment=NONE
Finished Control File and SPFILE Autobackup at 10-MAY-13
SYS@LEO1>drop table test3 purge;
SYS@LEO1>drop table test4 purge;
切換2次日志
SYS@LEO1>alter system switch logfile;
System altered.
SYS@LEO1>alter system switch logfile;
System altered.
SYS@LEO1>archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/app/oracle/archdata
Oldest online log sequence 3
Next log sequence to archive 5
Current log sequence 5
我們只需恢復到sequence=4即可
RMAN 進行基于sequence號不完全恢復
SYS@LEO1>shutdown immediate
SYS@LEO1>startup mount
RMAN> restore database until sequence 4 thread 1; 一直恢復到4號歸檔日志
Starting restore at 10-MAY-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 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/u02/app/oracle/oradata/LEO1/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to/u02/app/oracle/oradata/LEO1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to/u02/app/oracle/oradata/LEO1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to/u02/app/oracle/oradata/LEO1/leo1.dbf
channel ORA_DISK_1: restoring datafile 00006 to/u02/app/oracle/oradata/LEO1/test1_01.dbf
channel ORA_DISK_1: restoring datafile 00007 to/u02/app/oracle/oradata/LEO1/test2_01.dbf
channel ORA_DISK_1: reading from backup piece/u02/app/oracle/backup/DB_0to99v4v_1_1
channel ORA_DISK_1: piece handle= /u02/app/oracle/backup/DB_0to99v4v_1_1 tag=TAG20130510T162607
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05
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 00008 to/u02/app/oracle/oradata/LEO1/test3_01.dbf
channel ORA_DISK_1: restoring datafile 00009 to/u02/app/oracle/oradata/LEO1/test4_01.dbf
channel ORA_DISK_1: reading from backup piece/u02/app/oracle/backup/DB_11o99vpa_1_1
channel ORA_DISK_1: piece handle= /u02/app/oracle/backup/DB_11o99vpa_1_1 tag=TAG20130510T163657
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 10-MAY-13
RMAN> recover database until sequence 4 thread 1;
Starting recover at 10-MAY-13
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:/u02/app/oracle/oradata/LEO1/system01.dbf
destination for restore of datafile 00002:/u02/app/oracle/oradata/LEO1/sysaux01.dbf
destination for restore of datafile 00003: /u02/app/oracle/oradata/LEO1/undotbs01.dbf
destination for restore of datafile 00004:/u02/app/oracle/oradata/LEO1/users01.dbf
destination for restore of datafile 00005:/u02/app/oracle/oradata/LEO1/leo1.dbf
destination for restore of datafile 00006: /u02/app/oracle/oradata/LEO1/test1_01.dbf
destination for restore of datafile 00007:/u02/app/oracle/oradata/LEO1/test2_01.dbf
channel ORA_DISK_1: reading from backup piece/u02/app/oracle/backup/DB_11o99vpa_1_1
channel ORA_DISK_1: piece handle= /u02/app/oracle/backup/DB_11o99vpa_1_1 tag=TAG20130510T163657
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file/u02/app/oracle/archdata/1_3_815069267.dbf
archived log file name=/u02/app/oracle/archdata/1_3_815069267.dbf thread=1sequence=3
media recovery complete, elapsed time: 00:00:01
Finished recover at 10-MAY-13
RMAN> alter database open resetlogs; 打開數據庫
database opened
LEO1@LEO1>select count(*) from test3; 完整恢復回來啦
COUNT(*)
----------
71894
LEO1@LEO1>select count(*) from test4;
COUNT(*)
----------
71895
大家肯定會發現一個有趣的現象,我們備份集順序DB_0to99v4v_1_1->DB_0vo99vgi_1_1->DB_11o99vpa_1_1
-rw-r----- 1 oracle asmadmin 1023426560 May 10 16:27 DB_0to99v4v_1_1
-rw-r----- 1 oracle asmadmin 10493952 May 10 16:34 DB_0vo99vgi_1_1
-rw-r----- 1 oracle asmadmin 20193280 May 10 16:38 DB_11o99vpa_1_1
而我們恢復順序DB_0to99v4v_1_1->DB_11o99vpa_1_1,沒有中間的DB_0vo99vgi_1_1,這就是累積增量備份的特色,當進行備份時它要去找比它自己級別小的基準點進行增量備份,因此DB_11o99vpa_1_1是從0級一直備到最新狀態(包括DB_0vo99vgi_1_1)又根據Oracle優先使用備份集恢復,用完所有備份集后,在應用歸檔日志恢復,因為備份集效率比歸檔快很多,這一原則,我們可以直接使用DB_11o99vpa_1_1備份集進行恢復了。
小結:情深深雨蒙蒙~風吹草低見牛羊,示例說明兩種增量備份的差別實驗已經完成,大家從這些實驗中學習到東西了嘛!應該說這兩種增量各有千秋,適合不同的應用場景,如何更好的使用它們,要根據你項目能夠接受的備份及恢復程度而定,好了我們明天見goodbye 親。
2.演示用catalog數據庫作為RMAN的資料庫對數據庫進行一次全備份
上面我們說過RMAN元數據可以放在控制文件中,其實還可以放在catalog數據庫中,catalog庫是個什么東東呢?我們簡單的闡述一下它個功能。
1. catalog庫統一管理RMAN備份信息即元數據信息,如果沒有catalog庫,就把RMAN備份信息寫入控制文件
2. 目標數據庫必須注冊到catalog庫中才能使用
3. 控制文件恢復成本越來越低,降低了catalog庫使用。
4. 控制文件不能保留超過一年以上的備份信息,catalog可卻可以。
5. catalog庫可以同時保存n臺數據庫的備份信息,降低管理成本,提升管理效率
1.創建表空間catalog1 用于存儲rman備份信息,創建表空間代表【catalog庫】
LEO1@LEO1>create tablespace catalog1 datafile'/u02/app/oracle/oradata/LEO1/catalog1_01.dbf' size 20m autoextend off;
Tablespace created.
2.創建用戶cl_admin并指定默認的表空間catalog1
LEO1@LEO1>create user cl_admin identified by cl_admin defaulttablespace catalog1;
User created.
3.將recovery_catalog_owner角色授予給cl_admin用戶,才能提供維護和查詢恢復目錄的權限
LEO1@LEO1>grant connect,resource,recovery_catalog_owner to cl_admin;
Grant succeeded.
LEO1@LEO1>select * from dba_roles where role like '%RECOVER%';
ROLE PASSWORD AUTHENTICAT
------------------------------ -------- -----------
RECOVERY_CATALOG_OWNER NO NONE
LEO1@LEO1>conn / as sysdba
Connected.
SYS@LEO1>select * from role_sys_privs whererole='RECOVERY_CATALOG_OWNER'; 查看這個角色具有哪些系統權限->11個權限
ROLE PRIVILEGE ADM
------------------------------ -------------------------------------------
RECOVERY_CATALOG_OWNER CREATE SYNONYM NO
RECOVERY_CATALOG_OWNER CREATE CLUSTER NO
RECOVERY_CATALOG_OWNER ALTERSESSION NO
RECOVERY_CATALOG_OWNER CREATE DATABASE LINK NO
RECOVERY_CATALOG_OWNER CREATE SESSION NO
RECOVERY_CATALOG_OWNER CREATE TABLE NO
RECOVERY_CATALOG_OWNER CREATE SEQUENCE NO
RECOVERY_CATALOG_OWNER CREATEPROCEDURE NO
RECOVERY_CATALOG_OWNER CREATE VIEW NO
RECOVERY_CATALOG_OWNER CREATE TYPE NO
RECOVERY_CATALOG_OWNER CREATE TRIGGER NO
11 rows selected.
4.進入rman創建恢復目錄catalog庫
[oracle@leonarding1 backup]$ rman catalog cl_admin/cl_admin 以恢復目錄所有者身份登錄rman
Recovery Manager: Release 11.2.0.1.0 - Production on Sat May 11 09:06:292013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to recovery catalog database 連接到恢復目錄數據庫
RMAN> create catalog tablespace catalog1; 用catalog1表空間代表catalog庫
recovery catalog created
5.target庫注冊到catalog庫
[oracle@leonarding1 backup]$ rman target sys/oracle catalogcl_admin/cl_admin
Recovery Manager: Release 11.2.0.1.0 - Production on Sat May 11 09:15:102013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: LEO1 (DBID=1692458681) 必須以SYS身份登錄,不能以普通用戶身份登錄,否則不能注冊
connected to recovery catalog database 同時也連接到了catalog庫
RMAN> register database; 把target庫->注冊->catalog庫,誰注冊了誰的備份信息才能存到catalog庫
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
6.在數據庫中確認注冊成功,看看哪些數據庫注冊到catalog庫了
[oracle@leonarding1 ~]$ sqlplus cl_admin/cl_admin
CL_ADMIN@LEO1>col name for a6
CL_ADMIN@LEO1>select * from rc_database; 從這個視圖上我們就可以看到leo1庫已經注冊到catalog中了
DB_KEY DBINC_KEY DBID NAME RESETLOGS_CHANGE# RESETLOGS
---------- ---------- ---------- ------ ----------------- ---------
2 4 1692458681 LEO1 1086803 10-MAY-13
7.取消注冊
RMAN> unregister database; 從恢復目錄庫中取消目標數據庫的注冊
8.全庫備份
RMAN> backup as compressed backupset full database include currentcontrolfile plus archivelog delete all input;
Starting backup at 11-MAY-13
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=38 STAMP=814107533
input archived log thread=1 sequence=7 RECID=36 STAMP=814105467
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_15o9bs9s_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_6_814098124.dbf RECID=38STAMP=814107533
archived log file name=/u02/app/oracle/archdata/1_7_814098124.dbf RECID=36STAMP=814105467
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=39 STAMP=815067081
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_16o9bs9t_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_1_814107939.dbf RECID=39STAMP=815067081
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=8 RECID=37 STAMP=814105539
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_17o9bsa1_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_8_814098124.dbf RECID=37STAMP=814105539
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=40 STAMP=815067673
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_18o9bsa2_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_2_814107939.dbf RECID=40STAMP=815067673
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=43 STAMP=815070347
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_19o9bsa3_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_1_815069267.dbf RECID=43STAMP=815070347
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=41 STAMP=815067752
input archived log thread=1 sequence=4 RECID=42 STAMP=815069267
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1ao9bsa4_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_3_814107939.dbf RECID=41STAMP=815067752
archived log file name=/u02/app/oracle/archdata/1_4_814107939.dbf RECID=42STAMP=815069267
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=44 STAMP=815070349
input archived log thread=1 sequence=3 RECID=45 STAMP=815071289
input archived log thread=1 sequence=4 RECID=46 STAMP=815071321
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1bo9bsa5_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_2_815069267.dbf RECID=44STAMP=815070349
archived log file name=/u02/app/oracle/archdata/1_3_815069267.dbf RECID=45STAMP=815071289
archived log file name=/u02/app/oracle/archdata/1_4_815069267.dbf RECID=46STAMP=815071321
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=48 STAMP=815130519
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1co9bsa9_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_1_815071959.dbf RECID=48STAMP=815130519
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=47 STAMP=815071959
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1do9bsag_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_5_815069267.dbf RECID=47STAMP=815071959
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=49 STAMP=815132985
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1eo9bsai_1_1 tag=TAG20130511T094947comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_2_815071959.dbf RECID=49STAMP=815132985
Finished backup at 11-MAY-13
Starting backup at 11-MAY-13
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=00001name=/u02/app/oracle/oradata/LEO1/system01.dbf
input datafile file number=00002name=/u02/app/oracle/oradata/LEO1/sysaux01.dbf
input datafile file number=00003name=/u02/app/oracle/oradata/LEO1/undotbs01.dbf
input datafile file number=00005 name=/u02/app/oracle/oradata/LEO1/leo1.dbf
input datafile file number=00006name=/u02/app/oracle/oradata/LEO1/test1_01.dbf
input datafile file number=00007name=/u02/app/oracle/oradata/LEO1/test2_01.dbf
input datafile file number=00008 name=/u02/app/oracle/oradata/LEO1/test3_01.dbf
input datafile file number=00009name=/u02/app/oracle/oradata/LEO1/test4_01.dbf
input datafile file number=00010name=/u02/app/oracle/oradata/LEO1/catalog1_01.dbf
input datafile file number=00004 name=/u02/app/oracle/oradata/LEO1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1fo9bsaj_1_1 tag=TAG20130511T095011comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
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 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1go9bsdi_1_1 tag=TAG20130511T095011comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-MAY-13
Starting backup at 11-MAY-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=50 STAMP=815133109
channel ORA_DISK_1: starting piece 1 at 11-MAY-13
channel ORA_DISK_1: finished piece 1 at 11-MAY-13
piece handle=/u02/app/oracle/backup/DB_1ho9bsdm_1_1 tag=TAG20130511T095150comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u02/app/oracle/archdata/1_3_815071959.dbf RECID=50STAMP=815133109
Finished backup at 11-MAY-13
Starting Control File and SPFILE Autobackup at 11-MAY-13
piece handle=/u02/app/oracle/backup/control/cf_c-1692458681-20130511-01comment=NONE
Finished Control File and SPFILE Autobackup at 11-MAY-13
這些備份信息就會保存在catalog數據庫中,你可以同時保存n臺數據庫的備份信息,請注意一點,catalog庫也會有crash風險,如果這些備份信息丟失那么所有備份集就會失效,因此catalog庫也需要備份。
備份與恢復是數據庫的一個核心模塊,幾乎沒有見過無需備份的庫,RMAN是oracle專用級備份與恢復工具,幾乎可以完成所有的備份任務,是我們DBA的利器。
RMAN backupset catalog 全庫備份 差異增量備份 累積增量備份
關于如何深入解析RMAN備份與恢復就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。