如何從另一個節點上將Rman備份恢復到本地不同的目錄結構中
環境條件
- Rman備份在節點1上
- 數據庫不得不將備份恢復到節點2上
- 節點2和節點1上的目錄結構並不相同。
- Rman備份不得不傳輸到節點2的新的位置上進行使用。
- 數據庫備份恢復需要將數據文件恢復到節點2的新的目錄結構中。
假設
- 數據庫備份在節點1的/node1/database/backup
- 數據文件在節點1的/node1/database/prod
- 數據庫備份需要放到節點2的位置/node2/database/backup
- 據庫文件在節點2的恢復位置爲/node2/database/prod
解決方法步驟 (基本步驟對10g以後版本都適用)
1) 對節點1上的數據庫使用rman進行備份。
$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Feb 13 00:29:33 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10G (DBID=3932056136)
RMAN> backup database plus archivelog;
Starting backup at 13-FEB-07
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=143 recid=109 stamp=614392105
channel ORA_DISK_1: starting piece 1 at 13-FEB-07
channel ORA_DISK_1: finished piece 1 at 13-FEB-07
piece handle=/node1/database/backup/o1_mf_annnn_TAG20070213T002825_2x21kbds
_.bkp tag=TAG20070213T002825 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 13-FEB-07
Starting backup at 13-FEB-07
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00003 name=/node1/database/prod/sysaux01.dbf
input datafile fno=00001 name=/node1/database/prod/system01.dbf
input datafile fno=00002 name=/node1/database/prod/undotbs01.dbf
input datafile fno=00004 name=/node1/database/prod/users01.dbf
input datafile fno=00005 name=/node1/database/prod/1.dbf
input datafile fno=00006 name=/node1/database/prod/sysaux02.dbf
input datafile fno=00007 name=/node1/database/prod/undotbs02.dbf
channel ORA_DISK_1: starting piece 1 at 13-FEB-07
channel ORA_DISK_1: finished piece 1 at 13-FEB-07
piece handle=/node1/database/backup/o1_mf_nnndf_TAG20070213T002827_2x21kd12
_.bkp tag=TAG20070213T002827 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 13-FEB-07
Starting backup at 13-FEB-07
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=144 recid=110 stamp=614392165
channel ORA_DISK_1: starting piece 1 at 13-FEB-07
channel ORA_DISK_1: finished piece 1 at 13-FEB-07
piece handle=/node1/database/backup/o1_mf_annnn_TAG20070213T002925_2x21m6ty
_.bkp tag=TAG20070213T002925 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 13-FEB-07
Starting Control File and SPFILE Autobackup at 13-FEB-07
piece handle=/u01/oracle/product/ora10g/dbs/c-3932056136-20070213-02 comment=NONE
Finished Control File and SPFILE Autobackup at 13-FEB-07
RMAN> exit
2) 將備份文件傳輸到節點2上:
- 數據庫備份片位置/node2/database/backup
- 控制文件備份片位置/node2/database/backup
- 參數文件如init.ora文件默認位置$ORACLE_HOME/dbs
3) 在節點2上,編輯修改pfile並調整相應環境參數,如:
- user_dump_dest =
- background_dump_dest =
- control_files =
4) 修改好pfile並適配好。設置好Oracle在系統上的環境變量,並在將數據庫啓動到nomount狀態。在節點2上啓動rman:
[oracle@test-br test]$ export ORACLE_HOME=/u01/oracle/product/ora10g
[oracle@test-br test]$ export ORACLE_SID=ora10g
[oracle@test-br test]$ export PATH=$ORACLE_HOME/bin:$PATH
[oracle@test-br test]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Feb 13 00:36:55 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
Oracle instance started
Total System Global Area 205520896 bytes
Fixed Size 1218508 bytes
Variable Size 75499572 bytes
Database Buffers 121634816 bytes
Redo Buffers 7168000 bytes
5) 從備份片中恢復控制文件
RMAN> restore controlfile from '/node2/database/backup/c-3932056136-20070213-02';
Starting restore at 13-FEB-07
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete,
elapsed time: 00:00:02
output filename=/node2/database/prod/control01.ctl
Finished restore at 13-FEB-07
6) mount數據庫
RMAN > alter database mount
7) 將從節點1傳輸過來的備份片進行catalog
RMAN> catalog backuppiece '/node2/database/backup/o1_mf_annnn_TAG20070213T002925_2x21m6ty_.bkp';
RMAN> catalog backuppiece '/node2/database/backup/o1_mf_annnn_TAG20070213T002825_2x21kbds_.bkp';
RMAN> catalog backuppiece '/node2/database/backup/o1_mf_nnndf_TAG20070213T002827_2x21kd12_.bkp';
8) 使用以下命令瞭解可用的歸檔日誌備份的序號。這可以幫助我們將數據庫恢復直到最近的歸檔日誌的位置爲止。
我們假設備份中最新的歸檔日誌序號爲50.
RMAN > list backup of archivelog all;
9) 對重做日誌文件進行重命名,這樣就可以在新的目錄位置下打開數據庫。
SQL> alter database rename file '/node1/database/prod/redo01.log' to '/node2/database/prod/redo01.log';
......
......
......
10) 現在將數據庫文件恢復到新位置並進行恢復。這裏我們使用SET UNTIL SEQUENCE語句將數據庫恢復到50號歸檔日誌。
RMAN> run
{
set until sequence 51;
set newname for datafile 1 to '/node2/database/prod/sys01.dbf';
set newname for datafile 2 to '/node2/database/prod/undotbs01.dbf';
set newname for datafile 3 to '/node2/database/prod/sysaux01.dbf';
set newname for datafile 4 to '/node2/database/prod/users01.dbf';
set newname for datafile 5 to '/node2/database/prod/1.dbf';
set newname for datafile 6 to '/node2/database/prod/sysaux02.dbf';
set newname for datafile 7 to '/node2/database/prod/undotbs02.dbf';
restore database;
switch datafile all;
recover database;
alter database open resetlogs;
}
11) 確認臨時文件建立及位置
確認臨時文件目錄位置,如果需要則進行重建:
SQL> select * from v$tempfile;
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE 'new tempfile path filename' REUSE;