oracle rman catalog

netwant發表於2011-04-02
oracle rman[@more@]

建立使用帶catalog的rman
大致步驟
1、 設定歸檔模式
2、 建立rman使用的表空間,建議300m
3、 建立rman使用的使用者並授權
4、 備份控制檔案,
alter database backup controlfile to trace
create pfile from spfile;
alter system set log_archive_dest_1='location=/archiverman' scope=spfile;
shutdown
startup mount
alter database archivelog;
alter database open;
create tablespace tbs_rman datafile '/opt/oracle/oradata/dba/tbs_rman.dbf' size 230m;
create user rman identified by rman default tablespace tbs_rman temporary tablespace temp;
grant recovery_catalog_owner to rman;
alter user rman quota unlimited on tbs_rman;
select * from session_privs;
select * from seesion_roles;
rman catalog
create catalog tablespace tbs_rman;
connect target
register database;

list backuoset; /*檢視備份集
list incarnation /*檢視化身
report schema; /*檢視庫結構
crosscheck backupset; /*檢視備份的有效性,EXPIRED
delete expired backupset;/*刪除過期的備份集
crosscheck copy; /*檢查copy
delete expired copy; /*刪除過期的copy
validate backupset; /*檢驗備份集是否能用。
delete expired backupset /*刪除過期的備份
crosscheck copy of archivelog all;
show all;
RMAN> configure controlfile autobackup on;

rman 可以做full,增量備份,備份單獨資料檔案等功能。
fullbackup 1
run{
2> allocate channel d1 device type disk; format'/opt/oracle/spfile.bak';
3> backup as compressed backupset
4> format '/opt/oracle/oradata/bak/full_%d%U'
5> tag='fullbak' including current controlfile;
6> channel=d1
7> database plus archivelog delete input;
8> }

fullbackup 2
RMAN> run {
2> allocate channel d1 device type disk;
3> backup as compressed backupset
4> format '/opt/oradata/oradata/rman/full_%d%U'
5> tag='fullbak'
6> channel=d1
7> database plus archivelog delete input;
8> }

incremental level=0
RMAN> run{
2> allocate channel d1 device type disk;
3> backup as compressed backupset
4> format='/opt/oradata/oradata/inc1_%d_%U'
5> tag='inc0'
6> incremental level=0
7> database;
8> }

bakcup datafile
RMAN> run{
2> allocate channel d1 device type disk;
3> backup as compressed backupset
4> format='/opt/oradata/oradata/df_%d_%U'
5> tag='dfile'
6> channel=d1
7> datafile 1;
8> }

backup arch from scn
run{
allocate channel d1 device type disk;
backup
format='/opt/oradtata/oradata/arch_%d_%U'
tag='arch'
channel=d1
archivelog from scn 1219672 ;
}

copy database
run{
allocate channel d1 device type disk;
backup as copy
format='/opt/oradata/oradata/copy_%d_%U'
tag='copybak'
database;
}

恢復規則:

nomount狀態:controlfile,all database file
mount狀態:system tablespace& online redo log file
mount、open狀態:non-system tbs & undo tbs

1、模擬丟失一個非system資料檔案。
刪除資料檔案,在資料庫裡alter database dataifle 4 online; 在rman 裡 report schema 可以看到file id
在rman裡輸入命令去恢復:
run{
allocate channel d1 devcie type disk;
sql "alter database datafile 4 offline"; ### 不執行這個,就會報獨佔錯誤。
restore datafile 4;
recover dataifle 4;
sql "alter database datafile 4 online";
}

2 模擬丟失undo資料檔案(undo不能offline,read-only)
sqlplus :
alter database offline;
alter database online;
rman:
run{
allocate channel d1 device type disk;
restore datafile 2;
recover datafile 2;
}
sql:select * from v$datafile;
recover datafile 2;
3 模擬系統表空間丟失:
首先把資料庫切換到mount狀態:
sql>startup mount force;
rman>run{
allocate channel d1 device type disk;
restore datafile 1;
recover datafile 1;
sql "alter database open";
}

4 控制檔案丟失:
sql:startup nomount force;
rman
run{
allocate channel d1 device type disk;
restore controlfile;
sql "alter database mount";
recover database;
sql "alter database open noresetlogs";
}

一個可以自動執行的指令碼:

[oracle@rac01 ~]$ ls
database fullbak.rcv full.sh
[oracle@rac01 ~]$ more full.sh
export ORACLE_BASE=/u01
export ORACLE_HOME=/u01/app/oracle
export ORACLE_SID=rac01
rman cmdfile = /home/oracle/fullbak.rcv
[oracle@rac01 ~]$ more fullbak.rcv
connect target /
run{
allocate channel d1 device type disk;
backup as compressed backupset
format '/u01/oradata/full_%d%U'
tag='fullbak'
channel=d1
database plus archivelog delete input;
}
[oracle@rac01 ~]$

大資料量的資料庫可能會碰到這樣的問題:由於某些原因造成本來該早上8點之前完成的備份沒有完成,結果造成正常業務造成很大影響。但是又不可能每天晚上看著本該自動執行的備份。

剛剛發現,原來rman有個duration引數可以使rman在指定時間無論完成與否都中止備份。

引用官方文件裡的例子:

For example, run the following command at 2:00 a.m. to specify that the backup
should run until 6:00 a.m.:
BACKUP
DURATION 4:00
TABLESPACE users;

繼續擴充套件 引數paptial和filesperset

BACKUP
DURATION 4:00 PARTIAL
TABLESPACE users
FILESPERSET 1;

上面的例子指定:每個檔案對應備份集,並且4小時備份如果沒有完成rman不會提示錯誤,而是提示哪個檔案還沒有備份,這樣一來可以手動將未備份的檔案重新備份。

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

相關文章