首页 > 代码库 > RMAN异机恢复实验---转载
RMAN异机恢复实验---转载
一、RMAN异机恢复实验
2011年3月23日00:44
1、环境介绍:
主机1:
操作系统 | REDHAT5.5 | IP地址 | 172.16.1.120 |
主机名 | sigle | 数据库版本 | 10.2.0.4 |
数据库名 | orcl | DBID | 1305151947 |
catalog | win_yjr | catalog用户 | sigle/sigle |
主机2:
操作系统 | REDHAT5.5 | IP地址 | 172.16.1.121 |
主机名 | clone_sigle | 数据库版本 | 10.2.0.4 |
|
|
|
|
2、本次恢复实验目的:
主机崩溃恢复后(重装了操作系统及数据库软件),在没有任何控制文件、数据文件、参数文件的情况下,依靠catalog知识库进行控制文件、数据文件、参数文件等的恢复(或异机恢复)。
3、实际操作过程:
注意:在这类使用catalog库进行恢复操作中,DBID是尤为重要的信息,如没有DBID则这类型的恢复工作将无法进行。
1)、创建测试表,并备份数据库。
创建表并启动到mount状态,由于数据库处于非归档模式,因此全库备份只能在mount状态下执行。
SQL> create table test_rman(t1 number,t2 date);
Table created.
SQL> insert into test_rman values(1,sysdate);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test_rman;
T1 T2 ---------- -------------- 1 23-3月 -12
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started.
Total System Global Area 486539264 bytes Fixed Size 1268196 bytes Variable Size 171968028 bytes Database Buffers 306184192 bytes Redo Buffers 7118848 bytes Database mounted. SQL> |
备份数据库:
[oracle@sigle dbs]$ rman target / catalog sigle/sigle@catalog [uniread] Loaded history (87 lines)
Recovery Manager: Release 10.2.0.4.0 - Production on 星期五 3月 23 00:16:14 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1305151947, not open) connected to recovery catalog database
RMAN> run { 2> 3> configure controlfile autobackup on; 4> allocate channel disk1 device type disk format=‘/oracle/backup/backup_%d_%T_%s_%t_1.bak‘; allocate channel disk2 device type disk format=‘/oracle/backup/backup_%d_%T_%s_%t_2.bak‘; 5> allocate channel disk3 device type disk format=‘/oracle/backup/backup_%d_%T_%s_%t_3.bak‘; 6> backup database tag=‘FULLL_DB_20120322‘; } 7> 8> old RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP ON; new RMAN configuration parameters are successfully stored starting full resync of recovery catalog full resync complete
allocated channel: disk1 channel disk1: sid=1640 devtype=DISK
allocated channel: disk2 channel disk2: sid=1639 devtype=DISK
allocated channel: disk3 channel disk3: sid=1638 devtype=DISK
Starting backup at 23-3月 -12 channel disk1: starting full datafile backupset channel disk1: specifying datafile(s) in backupset input datafile fno=00002 name=/dev/raw/raw3 input datafile fno=00003 name=/dev/raw/raw2 channel disk1: starting piece 1 at 23-3月 -12 channel disk2: starting full datafile backupset channel disk2: specifying datafile(s) in backupset input datafile fno=00001 name=/dev/raw/raw1 input datafile fno=00004 name=/dev/raw/raw4 channel disk2: starting piece 1 at 23-3月 -12 channel disk2: finished piece 1 at 23-3月 -12 piece handle=/oracle/backup/backup_ORCL_20120323_10_778637780_2.bak tag=FULLL_DB_20120322 comment=NONE channel disk2: backup set complete, elapsed time: 00:00:46 channel disk1: finished piece 1 at 23-3月 -12 piece handle=/oracle/backup/backup_ORCL_20120323_9_778637780_1.bak tag=FULLL_DB_20120322 comment=NONE channel disk1: backup set complete, elapsed time: 00:00:46 Finished backup at 23-3月 -12
Starting Control File and SPFILE Autobackup at 23-3月 -12 piece handle=/oracle/db10g/dbs/c-1305151947-20120323-00 comment=NONE Finished Control File and SPFILE Autobackup at 23-3月 -12 released channel: disk1 released channel: disk2 released channel: disk3
RMAN> |
2)、使用RMAN连接数据库及CATALOG库
在主机崩溃恢复后(包括操作系统及数据库版本都要与原系统一致,本次试验采用克隆主机系统后删除数据库来实现),使用oracle用户启动RMAN工具,并连接到catalog数据库(配置tnsnames.ora)
[oracle@clone_sigle ~]$ hostname [oracle@clone_sigle ~]$ rman target / catalog sigle/sigle@catalog [uniread] Loaded history (1 lines)
Recovery Manager: Release 10.2.0.4.0 - Production on 星期四 3月 22 23:06:52 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database (not started) connected to recovery catalog database
RMAN> |
3)、设置DBID
RMAN> set DBID=1305151947
executing command: SET DBID database name is "ORCL" and DBID is 1305151947
RMAN> |
4)、启动实例到nomount状态
虽然缺失spfile、pfile、init等参数文件,但是oracle会按默认设置启动实例。
RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file ‘/oracle/db10g/dbs/initorcl.ora‘
starting Oracle instance without parameter file for retrival of spfile Oracle instance started
Total System Global Area 159383552 bytes
Fixed Size 1266320 bytes Variable Size 58723696 bytes Database Buffers 92274688 bytes Redo Buffers 7118848 bytes
RMAN> |
5)、查看备份集
RMAN> list backupset;
List of Backup Sets ===================
BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 62 Full 540.16M DISK 00:00:36 22-3月 -12 BP Key: 64 Status: AVAILABLE Compressed: NO Tag: FULLL_DB_20120322 Piece Name: /oracle/backup/backup_ORCL_20120322_4_778630144_1.bak List of Datafiles in backup set 62 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ---- 2 Full 489158 22-3月 -12 /dev/raw/raw3 3 Full 489158 22-3月 -12 /dev/raw/raw2
BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 63 Full 357.91M DISK 00:00:39 22-3月 -12 BP Key: 65 Status: AVAILABLE Compressed: NO Tag: FULLL_DB_20120322 Piece Name: /oracle/backup/backup_ORCL_20120322_5_778630144_2.bak List of Datafiles in backup set 63 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ---- 1 Full 489158 22-3月 -12 /dev/raw/raw1 4 Full 489158 22-3月 -12 /dev/raw/raw4
BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 75 Full 13.70M DISK 00:00:02 22-3月 -12 BP Key: 78 Status: AVAILABLE Compressed: NO Tag: TAG20120322T220950 Piece Name: /oracle/db10g/dbs/c-1305151947-20120322-01 Control File Included: Ckp SCN: 489158 Ckp time: 22-3月 -12 SPFILE Included: Modification time: 22-3月 -12
RMAN> |
6)、执行spfile文件恢复
这里要注意,如果备份集是存放在磁带库上的,需要先配置数据库到磁带库的路径,并保证路径可用。如果是在磁盘上,需要拷贝备份文件到该主机的相同目录,本次试验采用NFS方式实现。即在目标主机上挂在和源主机相同的目录并配置成NFS文件系统。
关于Linux NFS配置,参考链接:http://blog.csdn.net/snowfox326043/article/details/7463002
RMAN> restore spfile from ‘/oracle/db10g/dbs/c-1305151947-20120322-01‘;
Starting restore at 22-3月 -12 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=36 devtype=DISK
channel ORA_DISK_1: autobackup found: /oracle/db10g/dbs/c-1305151947-20120322-01 channel ORA_DISK_1: SPFILE restore from autobackup complete Finished restore at 22-3月 -12
RMAN> |
7)、执行控制文件恢复
在执行控制文件恢复前,先恢复spfile参数文件,并且一定要重启数据库,以使数据库使用还原后的spfile参数文件来启动数据库,这样才能将控制文件还原到正确位置
RMAN> restore controlfile from ‘/oracle/db10g/dbs/c-1305151947-20120322-01‘;
Starting restore at 22-3月 -12 using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 output filename=/oracle/db10g/dbs/cntrlorcl.dbf Finished restore at 22-3月 -12
RMAN> |
8)、重启数据库到mount状态
注意在重启到mount状态前,需要先创建好dump文件夹目录
包括adump/bdump/cdump/dpdump/udump/pfile等
RMAN> shutdown immediate;
Oracle instance shut down
RMAN>
[oracle@clone_sigle ~]$ sq [uniread] Loaded history (43 lines)
SQL*Plus: Release 10.2.0.4.0 - Production on 星期四 3月 22 23:38:48 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
SQL> conn /as sysdba Connected. SQL> startup nomount; ORACLE instance started.
Total System Global Area 486539264 bytes Fixed Size 1268196 bytes Variable Size 167773724 bytes Database Buffers 310378496 bytes Redo Buffers 7118848 bytes SQL> alter database mount;
Database altered.
SQL> |
9)、执行数据文件还原
RMAN> restore database from tag=‘FULLL_DB_20120322‘;
Starting restore at 22-3月 -12 using channel ORA_DISK_1
skipping datafile 2; already restored to file /dev/raw/raw3 skipping datafile 3; already restored to file /dev/raw/raw2 channel ORA_DISK_1: starting datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set restoring datafile 00001 to /dev/raw/raw1 restoring datafile 00004 to /dev/raw/raw4 channel ORA_DISK_1: reading from backup piece /oracle/backup/backup_ORCL_20120322_5_778630144_2.bak channel ORA_DISK_1: restored backup piece 1 piece handle=/oracle/backup/backup_ORCL_20120322_5_778630144_2.bak tag=FULLL_DB_20120322 channel ORA_DISK_1: restore complete, elapsed time: 00:00:45 Finished restore at 22-3月 -12
RMAN> |
10)、执行数据文件恢复
RMAN> recover database;
Starting recover at 22-3月 -12 using channel ORA_DISK_1
starting media recovery media recovery complete, elapsed time: 00:00:00
Finished recover at 22-3月 -12
RMAN> |
11)、打开数据库
由于本次试验的数据为非归档模式,所以没有重设redolog的操作,如果数据库处于归档模式,这里执行了不完全恢复,在打开的时候需要加参数resetlogs
RMAN> alter database open;
database opened
RMAN> |
12)、验证数据恢复
[oracle@clone_sigle ~]$ sq [uniread] Loaded history (102 lines)
SQL*Plus: Release 10.2.0.4.0 - Production on 星期五 3月 23 00:41:01 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
SQL> conn /as sysdba Connected. SQL> !hostname clone_sigle
SQL> select * from test_rman;
T1 T2 ---------- -------------- 1 23-3月 -12
SQL> |
可以看到在原数据库备份前的数据已经恢复到在现在的主机上。至此数据库rman异机恢复实验成功完成。
RMAN异机恢复实验---转载