1. 程式人生 > >創建RMAN備份 恢復目錄數據庫

創建RMAN備份 恢復目錄數據庫

efault 只讀表空間 table oracl files 最好 本地 let rac

這是前段時間給客戶做的RMAN備份策略,今天有時間整理出來,希望對大家有些幫助,如有不對的地方歡迎大家給予指點,謝謝!



創建成恢復目錄數據庫

如果不是在本地配置RMAN 恢復目錄,

在一臺WINDOW2000電腦上安裝ORACLE數據庫,最好保證數據庫版本與目標數據庫的版本想同。

建立RMAN 數據庫用戶及表空間:

RECOVER CATALOG 表空間(cattbs):1G
系統表空間: 100M
UNDO表空間: 100M
臨時表空間(TEMP): 100M

用以下命令創建RMAN 用戶並授予權限:

Create user rman identified rman default tablespace cattbs temporary tablespace temp;


授予權限:
Grant connect, resource to rman;
Grant recovery_catalog_owner to rman

創建恢復目錄:

進入RMN 如果恢復目錄與目標數據庫不在同一臺機子上,用以下:


Rman catalog [email protected]

/* */

Rman> create catalog

C:/rman target [email protected] catalog rman /rman
Rman> register database;



如果想重新註冊,查詢數 據字典DB 得到DB_KEY與DB_ID 執行DBMS_RCVAT.UNREGISTERDATABASE 命令取消註冊。重新註冊。

Sql> conn rman/rman

Sql> select * from db;


Sql> exec dbms_rcvcat.unregisterdatabase(DB_KEY,DB_ID);



Rman> resync catalog;

每半年做一個數據庫的全備份(包含只讀表空間)
每個月做一次零級備份(不包含只讀表空間)
每個星期做一次一級備份
每天做一個二級備份


數據庫全備份腳本:
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag ‘dbfull‘ format ‘/backup/ncfc/full%d_%p_%t‘ database ;
sql ‘alter system archive log current‘ ;
backup format /backup/ncfc/dbL0/dbL0%d_%p_%t.arc‘ filesperset 5 archivelog all delete input;
release channel c1;
release channel c2;
release channel c3;
}



零級備份腳本(只讀表空間除外)
run {
allocate channel c1 type disk maxpiecesize =20G;
allocate channel c2 type disk maxpiecesize =20G;
allocate channel c3 type disk maxpiecesize =20G;
backup incremental level 0 filesperset 10 tag ‘dbL0‘ format ‘/backup/ncfc/dbL0/dbL0%u_%p_%c ‘ database skip readonly;
sql ‘alter system archive log current‘ ;
backup format ‘/backup/ncfc/dbL0/arch%u_%p_%c.arc‘ filesperset 5 archivelog from time "sysdate-1" all;
release channel c1;
release channel c2;
release channel c3;
}

一級備份腳本
run {
allocate channel c1 type disk maxpiecesize =20G;
allocate channel c2 type disk maxpiecesize =20G;
allocate channel c3 type disk maxpiecesize =20G;
backup incremental level 1 filesperset 5 tag ‘dbL1‘ format ‘/backup/ncfc/dbL1/dbL1%d_%p_%t ‘ ddatabase skip readonly;
sql ‘alter system archive log current‘ ;
backup format ‘/backup/ncfc/dbL1/dbL1%d_%p_%t.arc‘ filesperset 5 archivelog from time "sysdate-1" all;
release channel c1;
release channel c2;
release channel c3;
}

二級備份腳本
run {
allocate channel c1 type disk maxpiecesize =20G;
allocate channel c2 type disk maxpiecesize =20G;
allocate channel c3 type disk maxpiecesize =20G;
backup incremental level 2 filesperset 5 tag ‘dbL2‘ format ‘/backup/ncfc/dbL2/dbL2%u_%p_%c‘ ddatabase skip readonly;
sql ‘alter system archive log current‘ ;
backup format ‘/backup/ncfc/dbL2/dbL2%d_%p_%t.arc‘ filesperset 5 archivelog from time "sysdate-1" all;
release channel c1;
release channel c2;
release channel c3;
}


歸檔文件備份腳本
run {
allocate channel dev1 type disk maxpiecesize =20G;
allocate channel dev2 type disk maxpiecesize =20G;
allocate channel dev3 type disk maxpiecesize =20G;
sql ‘alter system archive log current‘ ;
backup format ‘/backup/ncfc/arc/arch%u_%p_%c ‘ archivelog from time "sysdate-1" all;
release channel dev1;
release channel dev2;
release channel dev3;
}


表空間備份腳本(以users表空間為例)
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup tag ‘tabsp‘ format ‘/backup/ncfc/tabsp/tabsp%u_%p_%c‘ tablespace users;
sql ‘alter system archive log current‘ ;
backup format ‘e:\oradata\%d_%p_%t.arc‘ filesperset 5 archivelog all delete input;
release channel c1;
release channel c2;
release channel c3;
}


則每天所需要備份的數據量只有一天的改變量。而做恢復時最多只要恢復當月的一個零級備份+三個一級備份+6個二級備份+當天的歸檔文件。如果不能接受這樣的恢復時間,就只能夠減少零級備份之間的時間間隔(如可以每個星期做一個零級備份,這樣恢復時最多只需要恢復一個星期的數據量)。

備份CATALOG數據庫(數據庫邏輯輸出)
exp pafile=exp.dat
其中exp.dat如下
userid=rman/rman
file=rmanexp.dmp

創建RMAN備份 恢復目錄數據庫