由于之前写rman 脚本的时候需要手动去修改一些路径很麻烦,没办法做此脚本方便大家。注此脚本使用前提数据库已经mount,也就是已经恢复了参数文件及控制文件
-
#Decription: general rman scription
-
#Author by:netdata
-
#Date:2015-07-17
-
#!/bin/bash
-
$ORACLE_HOME/bin/sqlplus -s " / as sysdba" <<eof >file1.log
-
set head off;
-
set feedback;
-
select name from v\$datafile;
-
exit;
-
eof
-
#
-
for file in `cat file1.log`; do
-
file=`basename $file`;
-
echo "'"'/oradata/xyxdb/xyxdb/'$file"'">>newfile.log;
-
done
-
#
-
for file in `cat file1.log`; do
-
echo "'"$file"'">>newfile1.log;
-
done
-
#
-
while read -u3 i && read -u4 j;do
-
echo " set newname for datafile "$i" to "$j";">>rman1.log;
-
done 3<newfile1.log 4<newfile.log
-
#
-
$ORACLE_HOME/bin/sqlplus -s " / as sysdba" <<eof >maxsn.log
-
set head off;
-
set feedback;
-
select * from (select next_change# from v\$archived_log order by next_change# desc) where rownum=1;
-
exit;
-
eof
-
#
-
#生成rman脚本
-
max_sn=`sed -e 's/^[ \t]*//g' maxsn.log | grep -v '^$'`
-
echo $max_sn
-
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
-
rm -rf newfile.log newfile1.log rman1.log file1.log
-
#rman nocatalog target / cmdfile=restore.rman log restore`date +%Y%m%d`.log
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24486203/viewspace-1736180/
,如需转载,请注明出处,否则将追究法律责任。