RMAN中各種檔案的恢復方法

leon830216發表於2014-02-23
支援資料庫版本:10gR2,11gR2

1. 完全介質恢復

# 資料庫需要在 mount 狀態

1-1. 掛載資料庫
RMAN> startup mount;

1-2. 執行恢復
RMAN> restore database;
# delete archivelog 會刪除恢復期間產生的歸檔, 不影響之前的歸檔
# maxsize 指定恢復過程中產生歸檔的上限大小, 達到上限會自行刪除
RMAN> recover database delete archivelog maxsize 10m skip tablespace temp;
RMAN> alter database open;


2. 恢復表空間或資料檔案

2-1. 表空間
# 資料庫可以在 mount 也可以在 open 狀態
RMAN> sql 'alter tablespace users offline';
RMAN> restore tablespace users;
RMAN> recover tablespace users;
RMAN> sql 'alter tablespace users online';

2-2. 資料檔案
# 資料庫可以在 mount 也可以在 open 狀態
RMAN> sql 'alter datafile 5 offline';
RMAN> restore datafile 5;
RMAN> recover datafile 5;
RMAN> sql 'alter datafile 5 online';

RMAN> sql 'alter datafile 5 offline';
RMAN> run {
set newname for datafile 5 to '/data/users01.dbf';
restore datafile 5;
switch datafile 5;
recover datafile 5;
}
RMAN> sql 'alter tablespace users online';

2-2. 歸檔日誌
# 恢復資料檔案時, RMAN 會自動恢復並應用歸檔日誌, 一般情況不需要手動恢復
# 預設恢復到 log_archive_dest_1 下
RMAN> restore archivelog sequence 22
RMAN> restore archivelog sequence between 22 and 23;

# 恢復到其他路徑
RMAN> run {
set archivelog destination to '/arch1';
restore archivelog sequence between 21 and 22;
set archivelog destination to '/arch1';
restore archivelog sequence between 23 and 24;
}


3. 恢復控制檔案

3-1. 從自動備份中恢復
RMAN> set dbid=xxxxxxxxx;
RMAN> startup nomount;

# 恢復控制檔案到 control_files 路徑下
RMAN> restore controlfile from autobackup;
# 恢復控制檔案到任意路徑下
RMAN> restore controlfile to '/data/control01.ctl' from autobackup;
# 若之前修改過自動備份的路徑, 則恢復前需要手動設定自動備份路徑
RMAN> set controlfile autoback format for device type disk to '/data/%F';
RMAN> restore controlfile from autobackup;

3-2. 從備份集中恢復
RMAN> set dbid=xxxxxxxxx;
RMAN> startup nomount;
RMAN> restore controlfile from '/data/xxxxxxxxxxxxxxxxxxxxx';
RMAN> recover database;
RMAN> alter database open resetlogs;


4. 初始化引數檔案
RMAN> set dbid=xxxxxxxxx;
RMAN> startup nomount;
RMAN> restore spfile from autobackup;
RMAN> restore spfile to '/data/xxxxxx' from autobackup;
RMAN> restore spfile to '/data/xxxxxx' from '/back/xxxxxx';

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

相關文章