RMAN學(xué)習(xí)筆記02——常用設(shè)置
?
?
??? 昨天學(xué)習(xí)了RMAN環(huán)境的搭建以及登錄的方法,今天學(xué)習(xí)一下RMAN中的一些設(shè)置、常用命令、以及參數(shù)的意義。工欲善其事,必先利其器嘛。總的來說RMAN的參數(shù)并不是非常復(fù)雜,基本上一天時間的學(xué)習(xí)可以基本掌握,再接下去就是要通過實踐來強(qiáng)化記憶和了解實際用法了。
?
?
1、打開和關(guān)閉數(shù)據(jù)庫:
?
基礎(chǔ)知識回顧:
?
Oracle的啟動過程分為三個階段:
① 啟動數(shù)據(jù)庫實例:讀取定義啟動參數(shù)的文件、分配SGA區(qū)、啟動后臺進(jìn)程
② 加載數(shù)據(jù)庫文件:讀取參數(shù)文件指定的控制文件、將數(shù)據(jù)庫文件與已啟動實例關(guān)聯(lián)
③ 打開數(shù)據(jù)庫:打開聯(lián)機(jī)數(shù)據(jù)文件、日志文件
?
數(shù)據(jù)庫啟動可分為:
① startup:正常方式啟動實例、加載數(shù)據(jù)庫文件、打開數(shù)據(jù)庫
② startup force:強(qiáng)制打開數(shù)據(jù)庫
③ startup mount:只啟動實例,不打開數(shù)據(jù)庫(用于切換模式、恢復(fù)數(shù)據(jù)等)
④ alter database open:startup mount后打開數(shù)據(jù)庫
?
數(shù)據(jù)庫關(guān)閉可分為:
① shutdown normal:正常關(guān)閉,必須等所有用戶退出后才關(guān)閉
② shutdown immediate:立即關(guān)閉,所有正在處理的事務(wù)回退
③ shutdown abort:異常關(guān)閉,馬上關(guān)閉數(shù)據(jù)庫,但不對事務(wù)進(jìn)行處理
?
由于備份一般需要在關(guān)閉數(shù)據(jù)庫的情況下操作,所以RMAN具有直接打開和關(guān)閉數(shù)據(jù)庫的功能。
所有操作指令與sqlplus下的命令完全相同。
?
?
2、常用命令
?
①
要使用操作系統(tǒng)命令:
?
RMAN> host;
?
Microsoft Windows XP [版本 5.1.2600]
(C) 版權(quán)所有 1985-2001 Microsoft Corp.
?
C:\Documents and Settings\wangxiaoqi>
?
與SqlPlus中不同的是,RMAN中host后面必須加“;”
?
② 使用SQL命令:
?
RMAN> SQL 'ALTER SYSTEM ARCHIVE LOG ALL';
?
但是使用SQL命令的限制比較多,主要是針對數(shù)據(jù)庫級的操作,很多的SQL語句都是無法使用的
因此最好的方法是先host登錄到OS,再sqlplus進(jìn)入SQL:
?
RMAN> host;
?
Microsoft Windows XP [版本 5.1.2600]
(C) 版權(quán)所有 1985-2001 Microsoft Corp.
?
C:\Documents and Settings\wangxiaoqi>sqlplus wangxiaoqi/wangxiaoqi
?
SQL*Plus: Release 9.2.0.1.0 - Production on Thu Sep 18 14:30:03 2008
?
Copyright (c) 1982, 2002, Oracle Corporation.? All rights reserved.
?
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
?
SQL>
?
?
3、
首先列出所有指標(biāo):
?
RMAN> show all;
using target database controlfile instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:\ORACLE\ORA92\DATABASE\SNCFDODO.ORA';# default
?
?
4、
配置自動通道數(shù):
?
RMAN> show device type;
?
RMAN configuration parameters are:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default
RMAN> configure device type disk parallelism 2; --表示并行數(shù)
?
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
??? 指定在以后的備份與恢復(fù)中,將采用并行度為2,同時開啟2個通道進(jìn)行備份與恢復(fù),當(dāng)然也可以在run中指定通道來決定備份與恢復(fù)的并行程度。并行的數(shù)目決定了開啟通道的個數(shù)。如果指定了通道配置,將采用指定的通道,如果沒有指定通道,將采用默認(rèn)通道配置。有點(diǎn)兒繞是吧,我來給你白話一把。
?
??? 默認(rèn)情況下,自動分配通道的并行度為1,如果你通過設(shè)置PARALLELISM設(shè)置了并行通道為2,那么在run塊中,如果你沒有單獨(dú)通過ALLOCATE CHANNEL命令指定通道,它會默認(rèn)使用2條并行通道,如果你在run命令塊中指定了數(shù)個ALLOCATE CHANNEL,那么rman在執(zhí)行備份命令時會以你設(shè)置的channel為準(zhǔn),而不管configure中配置了多少個并行通道。需要注意的一點(diǎn)是,在backup命令中有一個FILESPERSET參數(shù),該參數(shù)是指rman建立的每個備份集中所能包含的備份片段(即磁盤文件)的最大數(shù),該參數(shù)默認(rèn)值為64,如果在執(zhí)行backup命令時沒有指定該參數(shù)值,那么rman會僅使用第一個通道來執(zhí)行備份,其它通道將處于空閑狀態(tài)。關(guān)于通道數(shù)與FILESPERSET值之間也有一個大小關(guān)系,邏輯稍顯復(fù)雜這些就不多廢話了,總之一條,filesperset值不要小于你設(shè)定的通道數(shù)。
?
RMAN> show device type;
?
RMAN configuration parameters are:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
?
若要清除對通道數(shù)的設(shè)置(其它參數(shù)同):
?
RMAN> configure device type disk clear;
?
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
RMAN configuration parameters are successfully reset to default value
starting full resync of recovery catalog
full resync complete
?
?
5、制定自動通道默認(rèn)設(shè)備:
?
RMAN> show default device type;
?
RMAN configuration parameters are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
?
RMAN> configure default device type to sbt; --磁帶備份
?
new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
RMAN> configure default device type clear;? --還原默認(rèn)設(shè)置
?
old RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
RMAN configuration parameters are successfully reset to default value
starting full resync of recovery catalog
full resync complete
?
?
6、配置磁盤:
?
RMAN> show channel;
?
RMAN configuration parameters are:
RMAN configuration has no stored or default parameters
?
RMAN> configure channel device type disk format 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
?
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT?? 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
RMAN>? configure channel 2 device type disk format 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
?
new RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT?? 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
RMAN> show channel;
?
RMAN configuration parameters are:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT?? 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT?? 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
?
注:%t代替時間戳;%s代替?zhèn)浞萁M號;%p代替?zhèn)浞萜?/font>
?
取消:
?
RMAN> configure channel 2 device type disk clear;
?
old RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT?? 'D:\oracle\oradata\dodo\rmanback\ora_%t_%s_%p';
old RMAN configuration parameters are successfully deleted
starting full resync of recovery catalog
full resync complete
?
?
7、控制文件配置:
?
啟動控制文件的自動備份:
?
RMAN> configure controlfile autobackup on;
?
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
RMAN> show controlfile autobackup;
?
RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
?
設(shè)置控制文件、服務(wù)器參數(shù)文件備份文件格式路徑:
?
RMAN> configure controlfile autobackup format for device type disk to 'D:\oracle
\oradata\dodo\rmanback\ctl_%F';? --F必須大寫
?
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'D:\oracle\orada
ta\dodo\rmanback\ctl_%F';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
?
8、保存策略:
?
保存策略分兩種
?
時間策略:決定至少有一個備份能恢復(fù)到指定的日期
?
RMAN> configure retention policy to recovery window of 3 days;
?
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
注:保證至少有一個備份能恢復(fù)到3天前的時間點(diǎn)上,之前備份標(biāo)注為obsolete
?
冗余策略:決定至少有幾個冗余的備份:
RMAN> configure retention policy to redundancy 3;
?
old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
?
注:至少需要有3個冗余備份,若多于3個,則以前備份標(biāo)記為obsolete
?
取消策略:
?
RMAN> configure retention policy to none;
?
查看策略:
?
RMAN> show retention policy
?
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
?
注:可以用 RMAN> report obsolete; 來查找當(dāng)前的obsolete備份。
?
?
9、備份優(yōu)化設(shè)置:
?
打開備份優(yōu)化:
RMAN> CONFIGURE BACKUP OPTIMIZATION ON;
關(guān)閉備份優(yōu)化:
RMAN> CONFIGURE BACKUP OPTIMIZATION OFF;
?
?
具體優(yōu)化機(jī)制比較復(fù)雜,需要注意以下兩點(diǎn):
①type只能選一種,不能disk和sbt都選
②BACKUP DATABASE或BACKUP ARCHIVELOG命令中帶有ALL或LIKE參數(shù)
?
?
?