rman 異機恢復指令碼(路徑不一致)

shawnloong發表於2015-07-17
由於之前寫rman 指令碼的時候需要手動去修改一些路徑很麻煩,沒辦法做此指令碼方便大家。注此指令碼使用前提資料庫已經mount,也就是已經恢復了引數檔案及控制檔案

點選(此處)摺疊或開啟

  1. #Decription: general rman scription
  2. #Author by:netdata
  3. #Date:2015-07-17
  4. #!/bin/bash
  5. $ORACLE_HOME/bin/sqlplus -s " / as sysdba" <<eof >file1.log
  6. set head off;
  7. set feedback;
  8. select name from v\$datafile;
  9. exit;
  10. eof
  11. #
  12. for file in `cat file1.log`; do
  13.   file=`basename $file`;
  14.   echo "'"'/oradata/xyxdb/xyxdb/'$file"'">>newfile.log;
  15. done
  16. #
  17. for file in `cat file1.log`; do
  18.   echo "'"$file"'">>newfile1.log;
  19. done
  20. #
  21. while read -u3 i && read -u4 j;do
  22.   echo " set newname for datafile "$i" to "$j";">>rman1.log;
  23. done 3<newfile1.log 4<newfile.log
  24. #
  25. $ORACLE_HOME/bin/sqlplus -s " / as sysdba" <<eof >maxsn.log
  26. set head off;
  27. set feedback;
  28. select * from (select next_change# from v\$archived_log order by next_change# desc) where rownum=1;
  29. exit;
  30. eof
  31. #
  32. #生成rman指令碼
  33. max_sn=`sed -e 's/^[ \t]*//g' maxsn.log | grep -v '^$'`
  34. echo $max_sn
  35. awk 'BEGIN{print"run {"}END{print "restore database;";print "switch datafile all;";print "recover database until scn '$max_sn';";print "}"}1' rman1.log>restore.rman
  36. rm -rf newfile.log newfile1.log rman1.log file1.log
  37. #rman nocatalog target / cmdfile=restore.rman log restore`date +%Y%m%d`.log

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

相關文章