在备用主机做RMAN灾难恢复(目录路径不同)

OS:Oracle Linux 5.8 64bit
DB:11.2.0.4

原生产主机上数据库运行在归档模式上,备份脚本如下:

点击( 此处)折叠或打开

  1. run {
  2. allocate channel c1 device type disk ;
  3. allocate channel c2 device type disk ;
  4. backup database plus archivelog ;
  5. delete noprompt archivelog all ;
  6. release channel c1 ;
  7. release channel c2 ;
  8. }

RMAN已默认开启自动备份控制文件。

将备份(包括备份片和自动备份)传输到备用主机上(与源主机的路径相同)。

编辑RMAN脚本rman.cmd

点击( 此处)折叠或打开

  1. connect target /
  2. run {
  3. restore controlfile from '/oracledata/fra/APR/autobackup/2015_06_04/o1_mf_s_881495141_bpzlh6kd_.bkp' ;
  4. alter database mount;
  5. }

  6. run {
  7. SET NEWNAME FOR DATABASE TO '/oracledata/APR/datafile/%b' ;
  8. allocate channel c1 device type disk;
  9. allocate channel c2 device type disk;
  10. restore database;
  11. release channel c1;
  12. release channel c2;
  13. switch datafile all;
  14. }

  15. run {
  16. set until sequence 540 thread 1;
  17. recover database;
  18. alter database open resetlogs;
  19. }

注:
set newname for database:能直接更改数据库数据文件的目录路径,其中%b是变量,表示仅保留原来数据文件不包含路径的文件名,如C:\a\b.dbf就只有b.dbf。
set until sequence:在归档模式下备份不会备份活动状态下的redo log,但控制文件会记下最新活动状态下的redo log,因此需要设置备份的截止点(日志序列号)。
可以通过list backup by file找到sequence

点击( 此处)折叠或打开

  1. List of Archived Log Backups
  2. = = = = = = = = = = = = = = = = = = = = = = = = = = = =

  3. Thrd Seq     Low SCN    Low Time            BS Key S #Pieces #Copies Compressed Tag
  4. ---- ------- ---------- ------------------- ------- - ------- ------- ---------- ---
  5. 1    535     1443889    2015 -06 -04 10 :39 :24 12      X 1       1       NO         TAG20150604T110757
  6. 1    536     1445437    2015 -06 -04 11 :04 :21 13      X 1       1       NO         TAG20150604T110757
  7. 1    537     1445440    2015 -06 -04 11 :04 :24 13      X 1       1       NO         TAG20150604T110757
  8. 1    538     1445443    2015 -06 -04 11 :04 :28 14      X 1       1       NO         TAG20150604T110757
  9. 1 539 1445588    2015 -06 -04 11 :07 :57 17      A 1       1       NO         TAG20150604T114539

最大的sequence+1,可在原主机上确认,或者在备用主机上restore controlfile之后查找确认。
注:如果没有set until sequence,recover也许能够完成,但在open数据库时会报错

ORA-01152: file  string  was not restored from a sufficiently old backup

编辑完脚本后,运行

点击( 此处)折叠或打开

  1. nohup rman cmdfile =rman .cmd log =rman . log &



请使用浏览器的分享功能分享到微信等