天天看點

Oracle RMAN備份小結

Oracle RMAN備份恢複有兩種情況,一種是沒有catalog的,是使用控制檔案來存儲備份資料庫,另外一種是有catalog 的,這樣可以用目錄資料庫來存儲備份資料庫。

下面介紹下使用catalog 備份的步驟:

1. 在恢複目錄資料庫上建立一個表空間:create tablespace rcat_ts datafile '' size 15M;

2. 在恢複目錄資料庫上建立一個恢複使用者:create user rman identified rman temporary tablespace temp default tablespace rcat_ts quato unlimited on rcat_ts ;

3. 授予相關權限:grant recovery_catalog_owner to rman;

4. 在恢複目錄資料庫和目标資料庫上互相添加對方的tns資訊,友善在兩端都可以直接備份;

5. 登入恢複目錄資料庫,然後建立恢複目錄:

 rman catalog rman/[email protected]_1;

 create catalog;

6. 然後同時登入恢複目錄資料庫和目标資料庫(不管在哪個上面登入都可以):

rman target sys/[email protected]_2 catalog rman/[email protected]_1;(目标資料庫上要用sys登入)

register database; 注冊目标資料庫

7. 使用catalog有一個好處就是可以使用RMAN腳本,批量執行rman  command;

 create [global] script script_name {rman command}; 

加上global參數,說明恢複目錄上面的所有注冊資料庫都可以使用腳本,否則隻能對應的目标資料庫可以使用。

rman command一般可以有:

RMAN> backup database format '/u01/app/oracle/rmanbak/whole_%d_%U'; --備份整個資料庫

RMAN> backup as compressed backupset  database format '/u01/app/oracle/rmanbak/whole_%d_%U';

 --備份整個資料庫并壓縮備份集

RMAN> backup as copy datafile  format '/u01/app/oracle/rmanbak/df_%d_%U';

--備份資料檔案,類型為鏡像備份

RMAN> backup tablespace users,example format '/u01/app/oracle/rmanbak/tb_%d_%U';

--備份表空間

RMAN> backup tablespace temp; 

 --臨時表空間不需要備份(執行會報錯)

RMAN> backup current controlfile;

--單獨備份控制檔案及參數檔案

RMAN> backup datafile 4 include current controlfile;

--備份資料檔案時包含控制檔案

下面是備份歸檔日志檔案

備份歸檔日志時僅僅備份歸檔過的資料檔案(不備份聯機重做日志檔案)

備份歸檔日志時總是對歸檔日志做完整備份

RMAN對歸檔日志備份前會自動做一次日志切換,且從一組歸檔日志中備份未損壞的歸檔日志

RMAN會自動判斷哪些歸檔日志需要進行備份

歸檔日志的備份集不能包含其它類型的檔案

RMAN> backup

2> format '/u01/app/oracle/rmanbak/lf_%d_%U'

3> archivelog all delete input; --delete input 删除所有已經備份過的歸檔日志

RMAN> backup --此種寫法實作了上述相同的功能

2> archivelog all delete input

3> format '/u01/app/oracle/rmanbak/lf_%d_%U';

RMAN> backup archivelog sequence between 50 and 120 thread 1 delete input;

RMAN> backup archivelog from time "sysdate-15" until time "sysdate-7";

RMAN> backup

2> format '/u01/app/oracle/rmanbak/lf_%d_%U'

3> archivelog from sequence=80

4> delete input;

使用plus archivelog時備份資料庫完成的動作(backup database plus archivelog)

1.首先執行alter system archive log current 指令(對目前日志歸檔)

2.執行backup archivelog all 指令(對所有歸檔日志進行備份)

3.執行backup database指令中指定的資料檔案、表空間等

4.再次執行alter system archive log current

5.備份在備份操作期間産生的新的歸檔日志

--執行下面的指令,并觀察備份列出的資訊,可以看到使用plus archivelog時使用了上面描述的步驟來進行備份

RMAN> backup database plus archivelog

2> format '/u01/app/oracle/rmanbak/lg_%d_%U' delete input;

8. 使用run執行RMAN腳本:

run 

{

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

execute script script_name;

}

使用RMAN備份的操作連結:

http://blog.csdn.net/leshami/article/details/6032739

--備份資料檔案時包含控制檔案