Oracle10g RMAN备份异机恢复过程

环境说明: 
操作系统版本: Oracle linux 5.4 64BIT
Oracle版本: 10.2.0.5 64位
Oracle_SID: orcl

源DB服务器: 192.168.187.183
目标服务器: 192.168.187.184,  只安装了oracle软件,没有dbca操作
rman备份异机恢复通常用于原服务器无法启动情况,数据无法拿出的情况。

Oracle 10g RAC RMAN备份异机单实例恢复 

一、源DB服务器
[oracle@dbtest scripts]$ ./rman_bak.sh 0
----------------------------start----------------------------
Sat Mar 10 20:31:37 CST 2012
RMAN> RMAN> RMAN> 2> 3> 4> 5> 6> 7> RMAN> RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> RMAN> -----------------------------end-----------------------------
Sat Mar 10 20:33:16 CST 2012
[oracle@dbtest scripts]$ sqlplus /nolog
SQL> conn admin/admin
Connected.
SQL> select * from t1;
         A
----------
         1
       100
      1000
        11
        12

SQL> insert into t1 values(13);
1 row created.

SQL> alter system switch logfile;
System altered.

SQL> commit;
Commit complete.

查看归档日志文件。
SQL> host ls /u01/app/archive;
1_28_777161447.dbf

SQL> insert into t1 values(14);
1 row created.
SQL> quit
注:这里没有提示,数据在redolog中。


1. 拷贝RMAN备份的数据
[root@dbtest /]# tar czvf data.tar.gz data
data/
data/lost+found/
data/redolog/
data/redolog/redo02.log
data/redolog/redo01.log
data/redolog/redo03.log
data/rman_bak/
data/rman_bak/c-1304942180-20120310-01
data/rman_bak/logs/
data/rman_bak/logs/level.orcl.0.20120307.log
data/rman_bak/logs/level.orcl.0.20120310.log
data/rman_bak/archlog.ORCL.level.0.777587502
data/rman_bak/c-1304942180-20120310-00
data/rman_bak/data.ORCL.level.0.777587507
data/rman_bak/data.ORCL.level.0.777587593
data/archive/
data/archive/1_28_777161447.dbf
data/controlfile/
data/controlfile/control04.ctl

2. 按备份目录打包上传到其它服务器上这里为184服务器上。

[root@dbtest /]# scp data.tar.gz 192.168.187.184:/
The authenticity of host '192.168.187.184 (192.168.187.184)' can't be established.
RSA key fingerprint is 9d:a6:56:6a:b8:b9:96:98:4e:24:34:5c:b8:7b:07:06.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.187.184' (RSA) to the list of known hosts.
[email protected]'s password: 
data.tar.gz                                                 100%  104MB   4.5MB/s   00:23
[root@dbtest /]#

3. 在184上解压备份
异机恢复最好与原来服务器上的配置目录与环境一致。
# tar zxvf data.tar.gz

4. 创建归档日志目录
# mkdir -p /u01/app/archive
# chown -R oracle:oinstall /u01/app/archive

5. 创建数据库基本目录
说明: 由于rman备份的信息都是记录在controlfile中,所以目录结构应该与原数据库的一致.
# su - oracle
$ mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,ddump,udump}  
$ mkdir -p /u01/app/oracle/oradata/orcl  
$ mkdir -p /u01/app/oracle/flash_recovery_area/ORCL

6. 先恢复redolog文件
说明: 由于在前期将redolog日志,规档日志,controlfile,rman备份都存放了一份到远程共享磁盘上。
在原服务器down机无法启动情况,远程的数据得以保存,用来实现数据完全恢复。

$ cp /data/redolog/redo*.log /u01/app/oracle/oradata/orcl/
$ cp /data/archive/* /u01/app/archive/
$ cp /data/controlfile/* /u01/app/oracle/oradata/orcl/
[oracle@db ~]$ cd /u01/app/oracle/oradata/orcl/
[oracle@db orcl]$ cp control04.ctl control01.ctl        
[oracle@db orcl]$ cp control04.ctl control02.ctl  
[oracle@db orcl]$ cp control04.ctl control03.ctl  
[oracle@db orcl]$ ll -h
total 178M
-rw-r----- 1 oracle oinstall 7.0M Mar 10 21:13 control01.ctl
-rw-r----- 1 oracle oinstall 7.0M Mar 10 21:14 control02.ctl
-rw-r----- 1 oracle oinstall 7.0M Mar 10 21:14 control03.ctl
-rw-r----- 1 oracle oinstall 7.0M Mar 10 21:12 control04.ctl
-rw-r----- 1 oracle oinstall  51M Mar 10 21:11 redo01.log
-rw-r----- 1 oracle oinstall  51M Mar 10 21:11 redo02.log
-rw-r----- 1 oracle oinstall  51M Mar 10 21:11 redo03.log
[oracle@db orcl]$


7. 在目标服务器上正试恢复数据

(1) 设置SID和DBID
$ echo 'db_name=orcl' > $ORACLE_HOME/dbs/initorcl.ora  
$ export ORACLE_SID=orcl 
$ rman target / 

(2) 恢复参数文件
RMAN> startup nomount; 
RMAN> restore spfile from '/data/rman_bak/c-1304942180-20120310-00';

(3) 恢复控制文件
RMAN> startup nomount force;

(4) 恢复数据文件
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open; 

说明: 由于在恢复的过程中保留了redolog日志,所以恢复出没有丢失数据。


8. 恢复过程如下

[oracle@db orcl]$ echo 'db_name=orcl' > $ORACLE_HOME/dbs/initorcl.ora  
[oracle@db orcl]$ export ORACLE_SID=orcl 
[oracle@db orcl]$ rman target / 

Recovery Manager: Release 10.2.0.5.0 - Production on ??y 3? 10 21:16:02 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount;

Oracle instance started

Total System Global Area     171966464 bytes

Fixed Size                     2094832 bytes
Variable Size                113248528 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6291456 bytes

RMAN> restore spfile from '/data/rman_bak/c-1304942180-20120310-00';

Starting restore at 10-3? -12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /data/rman_bak/c-1304942180-20120310-00
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 10-3? -12

RMAN> startup nomount force;

Oracle instance started

Total System Global Area     599785472 bytes

Fixed Size                     2098112 bytes
Variable Size                163580992 bytes
Database Buffers             427819008 bytes
Redo Buffers                   6287360 bytes

RMAN> alter database mount;

database mounted

RMAN> restore database;

Starting restore at 10-3? -12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/admin.dbf
channel ORA_DISK_1: reading from backup piece /data/rman_bak/data.ORCL.level.0.777587507
channel ORA_DISK_1: restored backup piece 1
piece handle=/data/rman_bak/data.ORCL.level.0.777587507 tag=TAG20120310T203147
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 10-3? -12

RMAN> recover database;

Starting recover at 10-3? -12
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:02

Finished recover at 10-3? -12

RMAN> alter database open;

database opened

RMAN>

[root@db ~]# su - oracle
sql[oracle@db ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on ??y 3? 10 21:19:40 2012

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn / as sysdba;
Connected.
SQL> conn admin/admin
Connected.
SQL> select * from t1;

         A
----------
         1
       100
      1000
        13
        14
        11
        12

7 rows selected.

SQL>

你可能感兴趣的:(oracle10g,RMAN备份异机恢复)