主机:testdb IP:192.168.2.1
选择备份:/backup/databk/full*
目的:检测EMR数据库rman备份是否有效
关闭testdb上的旧数据库,删除与其相关的测试库数据
删除之前的实例his,确保恢复时不会发生冲突。
在生成环境上拷贝所有的备份文件到测试环境
[oracle@emr1 /backup/databak]#scp * 192.168.2.1:/backup
在EMR数据库中创建一份参数文件到本地拷给testdb
#sqlplus / as sysdba
SQL>create pfile=’/tmp/inittestdb.ora’ from spfile;
SQL>exit;
移动到数据库的参数文件目录下:$ORACLE_HOME/dbs/
[oracle@emr1 tmp]#ls inittestdb.ora
inittestdb.ora
将静态参数文件拷贝到测试环境:
[oracle@emr1 tmp]#scp inittestdb.ora 192.168.2.1:/home/oracle
4、修改静态参数文件
[oracle@testdb ~]#vim inittestdb.ora
根据测试虚拟机的硬件基础修改静态参数里面的内存设定,删除RAC相关的参数,添加redo转换参数。
将修改后的参数文件拷贝到数据库的dbs目录下:
[oracle@testdb ~]#cd $ORACLE_HOME/dbs
[oracle@testdb dbs]#cp /home/oracle/inittestdb.ora .
5、创建测试库恢复需要的目录
创建pfile文件中的相关目录
[oracle@testdb ~]#mkdir -pv /oracle/11.2.0/db/admin/jhemrv6/adump
[oracle@testdb ~]#mkdir -pv /oracle/jhemrv6
[oracle@testdb ~]#mkdir -pv /oracle/arch
6、RMAN恢复
连接rman:
[oracle@testdb dbs]#rman target /
启动到nomout状态,恢复rman备份的控制文件:
RMAN> startup nomount;
RMAN>restore controlfile from ‘/backup/full_database_(控制文件备份大小为1.3M)’;
启动到mount状态,手动注册备份集:
RMAN>alter database mount;
RMAN>catalog start with ‘/backup/’;
恢复数据库:
restore.sh
ORACLE_SID=jhemrv6
ORACLE_HOME=/oracle/11.2.0/db/dbhome
PATH=/oracle/11.2.0/db/dbhome/bin:/usr/bin:$PATH
export ORACLE_SID ORACLE_HOME PATH
CMDFILE=/home/oracle/scripts20180914/restore.txt
LOGFILE=/home/oracle/scripts20180914/restore_`date +%y%m%d%H%M`.log
/oracle/11.2.0/db/dbhome/bin/rman target / nocatalog cmdfile $CMDFILE msglog $LOGFILE
restore.txt
run{
ALLOCATE CHANNEL d1 DEVICE TYPE disk;
ALLOCATE CHANNEL d2 DEVICE TYPE disk;
ALLOCATE CHANNEL d3 DEVICE TYPE disk;
ALLOCATE CHANNEL d4 DEVICE TYPE disk;
set newname for datafile 1 to '/oracle/jhemrv6/system01.dbf';
set newname for datafile 2 to '/oracle/jhemrv6/sysaux01.dbf';
set newname for datafile 3 to '/oracle/jhemrv6/undotbs01.dbf';
set newname for datafile 4 to '/oracle/jhemrv6/users01.dbf';
set newname for datafile 5 to '/oracle/jhemrv6/undotbs02.dbf';
set newname for datafile 6 to '/oracle/jhemrv6/undotbs03.dbf';
set newname for datafile 7 to '/oracle/jhemrv6/undotbs04.dbf';
set newname for datafile 8 to '/oracle/jhemrv6/jhemrv61.dbf';
set newname for datafile 9 to '/oracle/jhemrv6/jhemrv62.dbf';
set newname for datafile 10 to '/oracle/jhemrv6/jhemrv63.dbf';
set newname for datafile 11 to '/oracle/jhemrv6/report.dbf';
set newname for datafile 12 to '/oracle/jhemrv6/jhfile1.dbf';
set newname for datafile 13 to '/oracle/jhemrv6/jhfile2.dbf';
set newname for datafile 14 to '/oracle/jhemrv6/jhfile3.dbf';
set newname for datafile 15 to '/oracle/jhemrv6/jhcdr.dbf';
set newname for datafile 16 to '/oracle/jhemrv6/apjhemrv64.dbf';
set newname for datafile 17 to '/oracle/jhemrv6/jhfile4.dbf';
set newname for datafile 18 to '/oracle/jhemrv6/jhcdr4.dbf';
set newname for datafile 19 to '/oracle/jhemrv6/tsp_jhlcp.dbf';
restore database;
switch datafile all;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
以后台脚本运行的方式还原数据库:
nohup sh /home/oracle/scripts20180914/restore.sh > /home/oracle/scripts20180914/restore_20180914.out 2>&1 &
还原备份的归档日志用于恢复:
RMAN>restore archivelog all;
恢复数据库:
RMAN> recover database;
重置日志方式启动数据库:
RMAN>alter database open resetlogs;
恢复工作已经完成!
7、检查恢复是否成功
登录数据库查看是否恢复成功:
检查相关对象是否数据恢复成功:
Sql>alter system set local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.2.1)(PORT=1521))' scope=spfile;