您的位置:首页 > 其它

非归档模式下RMAN备份的异机恢复

2014-02-17 10:07 423 查看
1、 关键过程

备份源数据库

a) 创建备份目录,用root用户登录源数据库,执行下列命令:

vmsdb1:~ # mkdir /opt/orabak/
vmsdb1:~ # chmod 775 /opt/orabak/
vmsdb1:~ # chown oracle:oinstall /opt/orabak/

b) 备份数据库和控制文件:

vmsdb1:~ # su - oracle
oracle@vmsdb1:~> rman target /
Recovery Manager: Release 11.1.0.6.0 - Production on Thu May 3 13:14:11 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: VMSDB1 (DBID=2886533464)
RMAN> run {
#将数据库启动到mount状态
shutdown immediate;
startup mount;

#删除过期备份
crosscheck backup;
delete noprompt expired backup;

#备份数据库
allocate channel t1 type disk;
set limit channel t1 kbytes=1000000;
backup
incremental level 0
skip inaccessible
as compressed backupset
# recommended format
format '/opt/orabak/fullbackup_%T_%U.backup'
database;

#备份控制文件
backup current controlfile format '/opt/orabak/ctlfile_backup.backup';
release channel t1;

#打开数据库
alter database open;
}

c) 备份参数文件

oracle@vmsdb1:/opt/orabak>sqlplus / as sysdba
sql>create pfile='/opt/orabak/VMSDB1_init.ora' from spfile;

d) 备份口令文件

oracle@vmsdb1:/opt/orabak>cp $ORACLE_HOME/dbs/orapwvmsdb1 /opt/orabak

当前实例的口令文件,存放在$ORACLE_HOME/dbs/路径下,文件命规则是:orapw$ORACLE_SID。

将备份文件传送到目标数据库机器

a) 使用SCP传送到目的服务器:10.137.19.155,在传送备份文件前,需要在目标数据库上建立好对应的路径和赋权,具体命令可以参考下面“创建存储RMAN备份的目录”命令。

vmsdb1:/opt/orabak # tar -zcvf vmsdb1_backup.tar.gz ./
vmsdb1:/opt/orabak # scp vmsdb1_backup.tar.gz oracle@10.137.19.155:/opt/orabak

在目标单板上恢复数据库

a) 创建存储RMAN备份的目录

linux155:~ # mkdir /opt/orabak/
linux155:~ # chmod 775 /opt/orabak/
linux155:~ # chown oracle:oinstall /opt/orabak/

b) 创建实例vmsdb1的相关目录

linux155:~ # su - oracle
oracle@linux155:~>mkdir -p /opt/oracle/admin/vmsdb1/{adump,dpdump,hdump,pfile,scripts}
oracle@linux155:~>mkdir -p /opt/oracle/diag/rdbms/vmsdb1/vmsdb1/{alert,cdump,hm,incident,incpkg,ir,lck,metadata,stage,sweep,trace}

oracle@linux155:~>mkdir -p /opt/oracle/oradata/vmsdb1

源数据库中,vmsdb1数据库的数据文件存放路径是“/opt/oracle/oradata/vmsdb1”。

c) 创建口令文件

oracle@linux155:/opt/orabak> tar -zxvf vmsdb1_backup.tar.gz
oracle@linux155:/opt/orabak> cp orapwvmsdb1 $ORACLE_HOME/dbs/

d) 创建参数文件

oracle@linux155:/opt/orabak> cp VMSDB1_init.ora $ORACLE_HOME/dbs/initvmsdb1.ora

Oracle11g数据库启动时,Oracle实例会搜索$ORACLE_HOME/dbs路径,先加载spfile文件,如果不存在spfile文件,则加载pfile文件,pfile文件的命名规则是:init$ORACLE_SID.ora。

e) RMAN恢复

oracle@linux155:~> export ORACLE_SID=vmsdb1
oracle@linux155:~> echo $ORACLE_SID
vmsdb1
oracle@linux155:~> rman target/
Recovery Manager: Release 11.1.0.7.0 - Production on Thu May 3 19:54:18 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database (not started)
RMAN> set dbid=2886533464; //指定DBID,需要和源服务器的DBID一致,可以从源服务器中的v$database视图中查询得到
executing command: SET DBID
RMAN> startup nomount;
Oracle instance started
Total System Global Area 1603411968 bytes
Fixed Size 2160112 bytes
Variable Size 419432976 bytes
Database Buffers 1174405120 bytes
Redo Buffers 7413760 bytes
RMAN> restore controlfile from '/opt/orabak/ctlfile_backup.backup'; --恢复控制文件
Starting restore at 03-MAY-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=153 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/oradata/vmsdb1/control01.ctl
output file name=/opt/oracle/oradata/vmsdb1/control02.ctl
output file name=/opt/oracle/oradata/vmsdb1/control03.ctl
Finished restore at 03-MAY-12
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> restore database;
--还原数据库文件
Starting restore at 03-MAY-12
Starting implicit crosscheck backup at 03-MAY-12
……
Finished restore at 03-MAY-12
RMAN> recover database;
--恢复数据库文件,这里将报错,不需处理,继续根据本案例指导,进行后面的操作
Starting recover at 03-MAY-12
using channel ORA_DISK_1
starting media recovery
RMAN-08187: WARNING: media recovery until SCN 1553545 complete
Finished recover at 03-MAY-12
RMAN> shutdown immediate;
database dismounted
Oracle instance shut down

f) 打开数据库

linux155:~ # su - oracle
oracle@linux155:~>
export ORACLE_SID=vmsdb1
oracle@linux155:~>
echo $ORACLE_SID
vmsdb1
oracle@linux155:~>
sqlplus "/as sysdba"
SQL*Plus: Release 11.1.0.7.0 - Production on Thu May 3 08:29:00 2012
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup;
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2160112 bytes
Variable Size
385878544 bytes
Database Buffers
1207959552 bytes
Redo Buffers 7413760 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;
Database altered.
SQL> select status from v$instance;
STATUS
------------
OPEN

至此,数据库在目标单板上已成功恢复了。

2、 结论、解决方案及效果

本案例使用的典型场景如下:

a) 在一线搭建测试床,演练升级和调测业务。

b) 当现网数据库出现严重故障,需要较长时间修复时,可以快速地在冗余、空闲数据库单板上恢复数据库,业务指向暂时数据库,快速恢复业务。

c) 在研发实验室快速搭建现场数据库镜像环境,进行业务开发和测试,以及问题重现等。

3、 经验总结、预防措施和规范建议

如果打开数据库的过程中,出现下列错误:

SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
Process ID: 2946
Session ID: 170 Serial number: 5

-- alert日志报错
Thu May 03 08:29:15 2012
ALTER DATABASE OPEN
ORA-1589 signalled during: ALTER DATABASE OPEN...
Thu May 03 08:29:33 2012
alter database open resetlogs
……
ORA-00704: bootstrap process failure
ORA-39700: database must be opened with UPGRADE option
Error 704 happened during db open, shutting down database
USER (ospid: 2946): terminating the instance due to error 704
Instance terminated by USER, pid = 2946
ORA-1092 signalled during: alter database open resetlogs...
ORA-1092 : opiodr aborting process unknown ospid (2946_47245946265184)
Thu May 03 08:29:41 2012
ORA-1092 : opitsk aborting process

错误原因是:源数据库和目标数据库的版本不一致或Oracle补丁没有加载一致,所以请用下面的方法解决:

oracle@linux155:~>
export ORACLE_SID=vmsdb1
oracle@linux155:~>
echo $ORACLE_SID
vmsdb1
oracle@linux155:~>
sqlplus "/as sysdba"
SQL*Plus: Release 11.1.0.7.0 - Production on Thu May 3 08:32:23 2012
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to an idle instance.
SQL> STARTUP UPGRADE;
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2160112 bytes
Variable Size
385878544 bytes
Database Buffers
1207959552 bytes
Redo Buffers 7413760 bytes
Database mounted.
Database opened.
SQL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql

-- 上述命令执行完毕后,数据库已关闭,所以执行下列命令
SQL> quit
oracle@linux155:~>
sqlplus "/as sysdba"
SQL> startup;

-- 编译失效对象
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: