Oracle利用RMAN做异地恢复实验

 

一:实验介绍

把一台机器上面的某个数据库恢复到另一台机器上(相当于,建个测试环境,以便进行相关操作)

二:实验环境

Oracle利用RMAN做异地恢复实验_第1张图片

三:实验准备

在目标恢复机器上建好相关目录:

3.1 创建同源库相同的数据库全备所在目录

[oracle@rac2 dbs]$ mkdir -p /home/oracle/dandan/rmanbk

3.2 创建相同的控制文件备份目录

[oracle@rac2 flash_recovery_area]$ mkdir -p /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2014_10_21

3.3 建数据存放目录

[oracle@rac2 ~]$ mkdir -p /u01/app/oracle/oradata/orcl/

3.4 建bdump,cdump等几个目录

[oracle@rac2 dbs]$ mkdir -p /u01/app/oracle/admin/orcl/bdump

[oracle@rac2 dbs]$ mkdir -p /u01/app/oracle/admin/orcl/cdump

[oracle@rac2 dbs]$ mkdir -p /u01/app/oracle/admin/orcl/udump

[oracle@rac2 dbs]$ mkdir -p /u01/app/oracle/admin/orcl/adump

四:实验步骤

4.1 测试数据

--查看源机器下scott.t表现有数据,以便于实验完成后验证是否恢复成功

SQL> conn scott/tiger;

Connected.

SQL> select *

  2  from t;

 

ID

----------

 1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

 

ID

----------

12

13

 

13 rows selected.


 

4.2 源机器做下数据库全备

RMAN> backup database format '/home/oracle/dandan/rmanbk/%d_%s_%T.bak';

 

Starting backup at 21-OCT-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=145 devtype=DISK

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile fno=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile fno=00009 name=/u01/app/oracle/oradata/orcl/ogg01.dbf

input datafile fno=00002 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

input datafile fno=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile fno=00006 name=/u01/app/oracle/oradata/orcl/test01.dbf

input datafile fno=00007 name=/u01/app/oracle/oradata/orcl/undo_test01.dbf

input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 21-OCT-14

channel ORA_DISK_1: finished piece 1 at 21-OCT-14

piece handle=/home/oracle/dandan/rmanbk/ORCL_17_20141021.bak tag=TAG20141021T045035 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26

Finished backup at 21-OCT-14

 

Starting Control File and SPFILE Autobackup at 21-OCT-14

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2014_10_21/o1_mf_s_861511861_b4d7mobl_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 21-OCT-14


 

4.3 拷贝相关文件

4.3.1 拷贝初始化参数文件

[oracle@source_pc dbs]$ cd $ORACLE_HOME/dbs

[oracle@source_pc dbs]$ ls -l

total 7300

-rw-rw---- 1 oracle oinstall    1544 Jun 28 03:17 hc_jiao.dat

-rw-r----- 1 oracle oinstall    1544 Jun 22 01:22 hc_orcl.dat

-rw-rw---- 1 oracle oinstall    1544 Jun 22 11:43 hc_ORCL.dat

-rw-r----- 1 oracle oinstall   12920 May  3  2001 initdw.ora

-rw-r----- 1 oracle oinstall    8385 Sep 11  1998 init.ora

-rw-r----- 1 oracle oinstall    2472 Jun 22 11:40 initORCL.ora

-rw-rw---- 1 oracle oinstall      24 Jun 28 03:18 lkJIAO

-rw-r----- 1 oracle oinstall      24 Jun 22 01:24 lkORCL

-rw-r----- 1 oracle oinstall    1536 Jun 28 03:20 orapwjiao

-rw-r----- 1 oracle oinstall    1536 Jun 22 01:30 orapworcl

-rw-r----- 1 oracle oinstall 7389184 Oct 21 03:03 snapcf_ORCL.f

-rw-r----- 1 oracle oinstall    3584 Jun 28 03:20 spfilejiao.ora

-rw-r----- 1 oracle oinstall    2560 Jun 22 02:54 spfileorcl.ora

-rw-r----- 1 oracle oinstall    3584 Oct 21 01:58 spfileORCL.ora

[oracle@source_pc dbs]$ scp initORCL.ora 192.168.8.221:$ORACLE_HOME/dbs/

The authenticity of host '192.168.8.221 (192.168.8.221)' can't be established.

RSA key fingerprint is 1c:b2:66:d8:fc:a9:29:45:73:dd:ca:92:ca:b8:0a:20.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.8.221' (RSA) to the list of known hosts.

 

 

[email protected]'s password: 

initORCL.ora                                                                                                                                                 100% 2472     2.4KB/s   00:00    

4.3.2 拷贝数据库全备文件

[oracle@source_pc dbs]$ scp /home/oracle/dandan/rmanbk/ORCL_17_20141021.bak  192.168.8.221:/home/oracle/dandan/rmanbk/

[email protected]'s password: 

ORCL_17_20141021.bak                                                                                                                                         100%  715MB  13.3MB/s   00:54    

4.3.3 拷贝控制文件备份

[oracle@source_pc rmanbk]# scp /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2014_10_21/o1_mf_s_861511861_b4d7mobl_.bkp 192.168.8.221:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2014_10_21/

The authenticity of host '192.168.8.221 (192.168.8.221)' can't be established.

RSA key fingerprint is 1c:b2:66:d8:fc:a9:29:45:73:dd:ca:92:ca:b8:0a:20.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.8.221' (RSA) to the list of known hosts.

[email protected]'s password: 

o1_mf_s_861505385_b4d199pq_.bkp                                                                                                                              100% 7296KB   7.1MB/s   00:01 

4.4 恢复

4.4.1 启动到nomount状态

[oracle@rac2 dbs]$ sqlplus / as sysdba

 

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Oct 21 07:25:27 2014

 

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

 

Connected to an idle instance.

 

SQL> startup nomount;

ORACLE instance started.

 

Total System Global Area  285212672 bytes

Fixed Size     1218992 bytes

Variable Size    92276304 bytes

Database Buffers   188743680 bytes

Redo Buffers     2973696 bytes


 

4.4.2 恢复控制文件

--在源库查询dbid

 

SQL> select dbid

  2  from v$database;

 

      DBID

----------

1378653027

 

[oracle@rac2 dbs]$ rman target /

 

Recovery Manager: Release 10.2.0.1.0 - Production on Tue Oct 21 07:38:27 2014

 

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

 

connected to target database: orcl (not mounted)

 

RMAN> set dbid 1378653027;

 

executing command: SET DBID

 

--对于不同数据库来说,DBID应当不同,而db_name则可能是相同的。避免在同机的时候有数据库名相同的情况下,无法识别。

RMAN> restore controlfile from '/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2014_10_21/o1_mf_s_861511861_b4d7mobl_.bkp';

 

Starting restore at 21-OCT-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=152 devtype=DISK

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

output filename=/u01/app/oracle/oradata/orcl/control01.ctl

output filename=/u01/app/oracle/oradata/orcl/control02.ctl

output filename=/u01/app/oracle/oradata/orcl/control03.ctl

Finished restore at 21-OCT-14


 

4.4.3 启动数据库到mount状态

RMAN> alter database mount;

 

database mounted

released channel: ORA_DISK_1


 

4.4.4 恢复数据库

 

RMAN> restore database;

Starting restore at 21-OCT-14

Starting implicit crosscheck backup at 21-OCT-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=152 devtype=DISK

Crosschecked 16 objects

Finished implicit crosscheck backup at 21-OCT-14

 

Starting implicit crosscheck copy at 21-OCT-14

using channel ORA_DISK_1

Finished implicit crosscheck copy at 21-OCT-14

 

searching for all files in the recovery area

cataloging files...

cataloging done

 

List of Cataloged Files

=======================

File Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2014_10_21/o1_mf_s_861511861_b4d7mobl_.bkp

 

using channel ORA_DISK_1

 

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/example01.dbf

restoring datafile 00006 to /u01/app/oracle/oradata/orcl/test01.dbf

restoring datafile 00007 to /u01/app/oracle/oradata/orcl/undo_test01.dbf

restoring datafile 00009 to /u01/app/oracle/oradata/orcl/ogg01.dbf

channel ORA_DISK_1: reading from backup piece /home/oracle/dandan/rmanbk/ORCL_17_20141021.bak

channel ORA_DISK_1: restored backup piece 1

piece handle=/home/oracle/dandan/rmanbk/ORCL_17_20141021.bak tag=TAG20141021T045035

channel ORA_DISK_1: restore complete, elapsed time: 00:00:16

Finished restore at 21-OCT-14

 

RMAN> recover database;

 

Starting recover at 21-OCT-14

using channel ORA_DISK_1

 

starting media recovery

 

unable to find archive log

archive log thread=1 sequence=5

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 10/21/2014 09:01:21

RMAN-06054: media recovery requesting unknown log: thread 1 seq 5 lowscn 1317773

--可以忽略这个错误


4.4.5 以resetlogs方式打开库

RMAN> alter database open resetlogs;

 

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of alter db command at 10/21/2014 09:01:49

ORA-00344: unable to re-create online log '/disk/redofile/redo01.log'

ORA-27040: file create error, unable to create file

Linux Error: 2: No such file or directory

--倘若出现上面这个ORA-00344: unable to re-create online log '/disk/redofile/redo01.log'错误,这样解决:

--查询日志文件路径

SQL> select member

  2  from v$logfile;

 

MEMBER

--------------------------------------------------------------------------------

/disk/redofile/redo03.log

/disk/redofile/redo02.log

/disk/redofile/redo01.log

/disk/redofile/redo01b.log

/disk/redofile/redo02b.log

/disk/redofile/redo03b.log

 

6 rows selected.

 

--重命名日志文件,命名后的日志文件路径可以自定义

SQL> alter database rename file '/disk/redofile/redo03.log' to '/u01/app/oracle/oradata/orcl/redo03.log';

 

Database altered.

 

SQL> alter database rename file '/disk/redofile/redo02.log' to '/u01/app/oracle/oradata/orcl/redo02.log';

 

Database altered.

 

SQL> alter database rename file '/disk/redofile/redo01.log' to '/u01/app/oracle/oradata/orcl/redo01.log';

 

Database altered.

 

SQL> alter database rename file '/disk/redofile/redo01b.log' to '/u01/app/oracle/oradata/orcl/redo01b.log';

 

Database altered.

 

SQL> alter database rename file '/disk/redofile/redo02b.log' to '/u01/app/oracle/oradata/orcl/redo02b.log';

 

Database altered.

 

SQL>  alter database rename file '/disk/redofile/redo03b.log' to '/u01/app/oracle/oradata/orcl/redo03b.log';

 

Database altered.

 

SQL> select member

  2  from v$logfile;

 

MEMBER

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/orcl/redo03.log

/u01/app/oracle/oradata/orcl/redo02.log

/u01/app/oracle/oradata/orcl/redo01.log

/u01/app/oracle/oradata/orcl/redo01b.log

/u01/app/oracle/oradata/orcl/redo02b.log

/u01/app/oracle/oradata/orcl/redo03b.log

 

6 rows selected.

 

SQL> 

 

RMAN> alter database open resetlogs;

 

database opened

 


 

4.5 验证是否恢复成功

SQL> select *

  2  from scott.t;

 

ID

----------

 1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

 

ID

----------

12

13

 

13 rows selected.

--和备库一样,都有13条数据,说明恢复成功了。

--记得在目标库上做个全备……


 

你可能感兴趣的:(Oracle利用RMAN做异地恢复实验)