oracle异目录自动恢复(bakbone netvault)

本文详细介绍了数据库备份历史记录的查看方法及恢复数据库的具体步骤,包括脚本创建、执行及关键参数设置,确保数据库能够成功从指定备份点恢复。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、查看备份历史记录

1.检查备份服务器的机器名server name;

2. 点击NVBU Console进入bakbone主菜单界面


3.点击restore选项,进入restore菜单


4. 选择相应的备份客户端,查看oracle APM备份历史记录


5.选择需要恢复的时间点,如果想恢复最近时间点,选择第一个


6.点击restore options,查看该备份集的详细信息,只需要查看控制文件和spfile所在的备份块



这里查看到:

spfile的备份块是:

NHCTR:#3058:nhdb1:2024_787037415:RMANINCRMTAL LVL 0 NHSI_1340793023

控制文件的备份块是:

NHCTR:#3058:nhdb1:2026_787037440:RMANINCRMTAL LVL 0 NHSI_1340793023


二、恢复数据库

1.创建脚本:

yesno(){
while true
do
   echo "the above  input is correct?yes/no"
   read input
   ret=`echo $input | tr '[a-z]' '[A-Z]' | cut -c1`
   case $ret in
      Y)  return 0;;
      N) read -p  "set new value:" $*;;
      Q)  exit 1;;
      *)  echo "Your input is error.";;
   esac
   done
}
echo "please enter the backup fileset of spfile:"
read spset
yesno spset
echo "please enter the backup fileset of controlfile:"
read  ctlset
yesno ctlset
echo "please enter the new directory of database files:"
read  newdir
yesno  newdir
file_dest=$newdir/$ORACLE_SID
flashdir=$newdir/fast_recovery_area
archdir=$newdir/arch
mkdir -p  $file_dest $flashdir $archdir
#check directory maked
if [ $? -ne 0 ]; then
echo "at `date` mkdir failed!please check the permission!" >  err.log
exit 1
fi
rman target / nocatalog <<EOF
startup nomount;
run{
allocate channel ch00 type 'sbt_tape';
send 'NV_BACKUP_SERVER=NHCTR';
restore spfile to '$file_dest/spfile.ora' from '$spset';
release channel ch00;
}
EOF
#check restore spfile
if [ $? -ne 0 ]; then
echo "at `date` restore spfile failed!" >>  err.log
sqlplus "/as sysdba"  <<EOF
shutdown immediate;
EOF
rm -rf $file_dest $flashdir $archdir
exit 1
fi
sqlplus "/as sysdba"  <<EOF
create pfile='$file_dest/init.ora' from spfile='$file_dest/spfile.ora';
shutdown immediate;
EOF
sed -e '/*.control_files/d' -e '/*.db_recovery_file_dest=/d' -e '/*.log_archive_dest/d' -e '/*.db_create_file_dest/d' $file_dest/init.ora > $file_dest/init$ORACLE_SID.ora
echo "*.control_files='$file_dest/control01.ctl','$file_dest/control02.ctl'" >> $file_dest/init$ORACLE_SID.ora
echo "*.db_recovery_file_dest=$flashdir" >> $file_dest/init$ORACLE_SID.ora
echo "*.log_archive_dest_1='location=$archdir'" >> $file_dest/init$ORACLE_SID.ora
rman target / nocatalog <<EOF
startup nomount pfile='$file_dest/init$ORACLE_SID.ora';
run{
allocate channel ch00 type 'sbt_tape';
send 'NV_BACKUP_SERVER=NHCTR';
restore controlfile from '$ctlset';
}
alter database mount;
EOF
#check restore controlfile
if [ $? -ne 0 ]; then
echo "at `date` restore controlfile failed!" >>  err.log
sqlplus "/as sysdba"  <<EOF
shutdown immediate;
EOF
rm -rf $file_dest $flashdir $archdir
exit 1
fi
echo "spool rename_log.sql" > script.sql
echo "set feedback off pagesize 0 heading off linesize 200 echo off" >> script.sql
echo  "select 'alter database rename file '''||member||''' to '''||'$file_dest'||substrb(member,instrb(member,'/', -1))||''';'from v\$logfile;" >> script.sql
echo "spool off" >> script.sql
echo "spool rename_dbfile.sql" >> script.sql
echo "set feedback off pagesize 0 heading off linesize 200 echo off" >> script.sql
echo "select 'set newname for datafile '||file#||' to ''$file_dest'||substrb(name,instrb(name,'/', -1)) ||''';'from v\$datafile;" >>script.sql
echo "spool off" >> script.sql
sqlplus "/as sysdba"  <<EOF
@script.sql
@rename_log.sql
EOF
#check rename scripts
if [ $? -ne 0 ]; then
echo "at `date` rename database files failed!" >>  err.log
exit 1
fi
echo "rman target / nocatalog <<EOF" > rman_restore.sh
echo "run " >> rman_restore.sh
echo  "{ allocate channel ch00 type 'sbt_tape';" >> rman_restore.sh
echo  "send 'NV_BACKUP_SERVER=NHCTR';" >> rman_restore.sh
cat rename_dbfile.sql >> rman_restore.sh
echo  "restore database;" >> rman_restore.sh
echo "switch datafile all;" >> rman_restore.sh
echo "recover database;" >> rman_restore.sh
echo "release channel ch00;" >> rman_restore.sh
echo "}" >> rman_restore.sh
echo "EOF" >> rman_restore.sh
sh rman_restore.sh
sqlplus "/as sysdba"  <<EOF
recover  database using backup controlfile until cancel;
AUTO
alter database open resetlogs;
EOF
#check open database successfully
if [ $? -ne 0 ]; then
echo "at `date` open database failed!" >>  err.log
exit 1
fi
echo "database $ORACLE_SID has restored successfully"

2.       赋予执行权限

$chmod +x restore.sh

 3.       执行脚本

$./restore.sh

  输入:

please enter the backup fileset of spfile

NHCTR:#3058:nhdb1:2024_787037415:RMANINCRMTAL LVL 0 NHSI_1340793023

 please enter the backup fileset of controlfile

NHCTR:#3058:nhdb1:2026_787037440:RMANINCRMTAL LVL 0 NHSI_1340793023

 echo "please enter the new directory of database files:"

/backup/oradata





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值