RAC数据恢复至单机环境
一、概括
随着越来越多的RAC环境,将RAC数据迁移至单机环境下的需求也随之增加,怎样才能更有效的迁移呢,方法有许多逻辑迁移(exp/expdp)、RMAN、DG、goldengate等,我们可根据自身环境及需求选择相应的迁移方式,下面简单介绍一下使用RMAN将RAC数据迁移至单机环境中的步骤。
二、
模拟环境:整套RAC环境无故宕机,暂无法恢复,我们将之前备份的数据进行恢复
将最近一次全备份文件上传至目标环境,并查看文件信息
|
[oracle@oradb1 backup]$ pwd /oracle/backup [oracle@oradb1 backup]$ ls -lrt 总计 264312 -rw-r-----
1 oracle
oinstall -rw-r-----
1 oracle
oinstall -rw-r-----
1 oracle oinstall -rw-r----- 1 oracle oinstall 269107200 02-17 13:24 full_0jp0ro50_1_ |
通过上述我们可以看到,归档文件有两个,由于是测试环境,数据量及备份信息较简单,数据文件也是两个,由此得知文件full_0kp0ro7v_1_1存放参数文件和控制文件。
设置环境变量
|
[oracle@oradb1 ~]$ vi ~/.bash_profile 修改参数为:export ORACLE_SID=racdb1 |
恢复spfile文件
|
[oracle@oradb1 backup]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon Feb 17 11:37:45 2014 Copyright (c) 1982, 2011, Oracle and/or its
affiliates. connected to target database (not started) RMAN> startup force nomount; startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/oracle/db_1/dbs/initracdb1.ora' starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global
Area Fixed
Size Variable
Size Database
Buffers Redo
Buffers RMAN> restore spfile from '/oracle/backup/full_0kp0ro7v_1_1'; Starting restore at 17-FEB-14 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK channel ORA_DISK_1: restoring spfile from AUTOBACKUP /oracle/backup/full_0kp0ro7v_1_1 channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 17-FEB-14 RMAN> restore spfile from '/oracle/backup/full_0kp0ro7v_1_1'; Starting restore at 17-FEB-14 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK channel ORA_DISK_1: restoring spfile from AUTOBACKUP /oracle/backup/full_0kp0ro7v_1_1 channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 17-FEB-14 |
登录到数据库,生成pfile文件,并编辑,删除与集群即节点2相关参数,修改控制文件及其他目录路径,并根据需求创建相应目录(如闪回区、oracle基础目录)
|
idle> create pfile from spfile; File created. |
创建spfile,并重启实例
|
idle> create spfile from pfile; File created. idle> show parameter pfile NAME ------------------------------------ ----------- ------------------------------ spfile idle> show parameter spfile NAME ------------------------------------ ----------- ------------------------------ spfile idle> shutdown abort ORACLE instance shut down. idle> startup nomount ORACLE instance started. Total System Global Area Fixed
Size Variable
Size Database
Buffers Redo
Buffers idle> show parameter pfile NAME ------------------------------------ ----------- ------------------------------ spfile |
恢复控制文件,并启动数据库到mount模式
|
[oracle@oradb1 oracle]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon Feb 17 12:45:58 2014 Copyright (c) 1982, 2011, Oracle and/or its
affiliates. connected to target database: RACDB (not mounted) RMAN> restore controlfile from '/oracle/backup/full_0bp0rlcu_1_1'; Starting restore at 17-FEB-14 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:15 output file name=/oracle/oradata/racdb/current.273.839446247 output file name=/oracle/oradata/racdb/current.274.839446249 Finished restore at 17-FEB-14 RMAN> sql 'alter database mount'; sql statement: alter database mount released channel: ORA_DISK_1 |
查看备份集信息
|
RMAN> list backup; List of Backup Sets =================== BS
Key ------- ---------- ----------- ------------ --------------- 18 BS
Key ------- ---- -- ---------- ----------- ------------ --------------- 19 |
根据备份信息,恢复数据文件及数据库
|
RMAN> run{ 2> set newname for datafile 1 to '/oracle/oradata/racdb/system01.dbf'; 3> set newname for datafile 3 to '/oracle/oradata/racdb/undotbs01.dbf'; 4> set newname for datafile 2 to '/oracle/oradata/racdb/sysaux01.dbf'; 5> set newname for datafile 5 to
'/oracle/oradata/racdb/users01.dbf'; 6> set newname for datafile 4 to '/oracle/oradata/racdb/undotbs02.dbf'; 7> restore database; 8> switch datafile all; 9> } executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting restore at 17-FEB-14 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /oracle/oradata/racdb/system01.dbf channel ORA_DISK_1: restoring datafile 00002 to /oracle/oradata/racdb/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00003 to /oracle/oradata/racdb/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00004 to /oracle/oradata/racdb/undotbs02.dbf channel ORA_DISK_1: restoring datafile 00005 to /oracle/oradata/racdb/users01.dbf channel ORA_DISK_1: reading from backup piece /oracle/backup/full_0jp0ro50_1_1 channel ORA_DISK_1: piece handle=/oracle/backup/full_0jp0ro50_1_1 tag=TAG20140217T133111 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:01:55 Finished restore at 17-FEB-14 datafile 1 switched to datafile copy input datafile copy RECID=6 STAMP=839771072 file name=/oracle/oradata/racdb/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=7 STAMP=839771072 file name=/oracle/oradata/racdb/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=8 STAMP=839771072 file name=/oracle/oradata/racdb/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=9 STAMP=839771072 file name=/oracle/oradata/racdb/undotbs02.dbf datafile 5 switched to datafile copy input datafile copy RECID=10 STAMP=839771072 file name=/oracle/oradata/racdb/users01.dbf RMAN> run{ 2> set until scn 1482715; --scn 号根据备份集信息得出 recover database; }3> 4> executing command: SET until clause Starting recover at 17-FEB-14 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 17-FEB-14 |
打开数据库
|
RMAN> sql 'alter database open resetlogs'; sql statement: alter database open resetlogs |
查看redo log
信息,并删除无效日志组(节点2日志)
|
sys@RACDB> select THREAD#, STATUS, ENABLED from v$thread; ---------- ------ -------- sys@RACDB> ---------- |
删除日志组3、4
|
sys@RACDB> alter database disable thread 2;
Database altered. Database altered. sys@RACDB> alter database drop logfile group 3; Database altered. |
查看undo表空间,并删除节点2(在此不使用)的undo表空间
|
sys@RACDB> show parameter undo NAME ------------------------------------ ----------- ------------------------------ undo_management undo_retention undo_tablespace sys@RACDB> select tablespace_name from dba_tablespaces where contents='UNDO'; TABLESPACE_NAME ------------------------------ UNDOTBS1 UNDOTBS2 sys@RACDB> drop tablespace UNDOTBS2 including contents and datafiles; |
修改临时表空间
|
sys@RACDB> select name from v$tempfile; NAME ---------------------------------------------------------------------------------------------------- /oracle/admin/racdb/RACDB/datafile/o1_mf_temp_9j38pmmk_.tmp sys@RACDB> select tablespace_name from dba_tablespaces where contents='TEMPORARY'; TABLESPACE_NAME ------------------------------ TEMP sys@RACDB> Tablespace created. sys@RACDB> alter database default temporary tablespace TEMP1; Database altered. sys@RACDB> drop tablespace TEMP including contents and datafiles; Tablespace dropped. |
查看监听状态并配置,编辑tnsname.ora文件。通过以下命令创建密码文件,注意密码文件的位置
|
[oracle@oradb1 dbs]$ orapwd file=orapwracdb1 password=oracle entries=30 |
附:
设置备份片
|
RMAN> catalog backuppiece '/oracle/backup/arch2_08p0rhm1'; cataloged backup piece backup piece handle=/oracle/backup/arch2_08p0rhm1 RECID=4 STAMP=839766295 |
三、总结
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9469065/viewspace-1115964/ ,如需转载,请注明出处,否则将追究法律责任。