ITPub博客

首页 > 数据库 > Oracle > 使用RMAN进行同名数据库异地环境搭建实验

使用RMAN进行同名数据库异地环境搭建实验

原创 Oracle 作者:realkid4 时间:2014-03-04 17:09:23 0 删除 编辑

 

随着版本不断地提升,RMAN作为标准备份工具的作用地位是不断的被增强的。从过去传统的备份还原工具,到现在新环境迁移、DG搭建,我们都可以看到RMAN工具增强的身影。

本篇就以RMAN为工具,利用RMAN备份在新主机上搭建服务名相同的数据库。由于环境所限,笔者采用的方法是:先进行备份获取,之后删除掉原数据库,最后使用备份重新搭建(包括参数、控制文件和数据文件恢复)。

 

1、环境介绍

 

我们选择Linux环境下的10.2.0.1进行实验。

 

SQL> select * from v$version;

BANNER

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

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

PL/SQL Release 10.2.0.1.0 - Production

CORE    10.2.0.1.0      Production

TNS for Linux: Version 10.2.0.1.0 - Production

NLSRTL Version 10.2.0.1.0 - Production

 

当前处在归档模式下。

 

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     2

Next log sequence to archive   4

Current log sequence           4

 

2、备份获取

 

RMAN支持onlineoffline两种备份模式。如果选择online备份模式,Oracle就不需要因为备份操作停机,但是恢复过程需要配合redo logapply过程。如果选择offline备份模式,Oracle需要在备份过程中停机,但是理论上是不需要archive redo log进行支持的。

如果Oracle运行在archived模式下,RMAN可以进行onlineoffline模式。如果是noarchived模式,RMAN就只能在offline模式备份了。

当前环境变量:

 

[oracle@SimpleLinuxUp ~]$ env | grep ORA

ORACLE_SID=oratest

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

 

笔者对onlineoffline备份,都进行保留。首先创建驻留目录:

 

[root@SimpleLinuxUp ~]# cd /

[root@SimpleLinuxUp /]# mkdir onlinebk

[root@SimpleLinuxUp /]# mkdir oflinebk

[root@SimpleLinuxUp /]# chown oracle:oinstall onlinebk/

[root@SimpleLinuxUp /]# chown oracle:oinstall oflinebk/

[root@SimpleLinuxUp /]# ls -l | grep linebk

drwxr-xr-x   2 oracle oinstall  4096 Mar  3 16:46 oflinebk

drwxr-xr-x   2 oracle oinstall  4096 Mar  3 16:46 onlinebk

 

如果进行online备份,数据库不需要关闭。备份范围为:参数文件、数据文件、控制文件。

 

online backup

RMAN> connect target /

 

connected to target database: ORATEST (DBID=3370560176)

using target database control file instead of recovery catalog

 

RMAN> backup database format '/onlinebk/%U'; --数据库

Starting backup at 03-MAR-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

(篇幅原因,有省略……)

piece handle=/onlinebk/04p28ubo_1_1 tag=TAG20140303T165227 comment=NONE

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

Finished backup at 03-MAR-14

 

RMAN> backup archivelog all format '/onlinebk/%U'; --已经归档日志

 

Starting backup at 03-MAR-14

current log archived

using channel ORA_DISK_1

(篇幅原因,有省略……)

piece handle=/onlinebk/05p28uds_1_1 tag=TAG20140303T165420 comment=NONE

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

Finished backup at 03-MAR-14

 

 

RMAN> backup current controlfile format '/onlinebk/control.bks';

 

Starting backup at 03-MAR-14

using channel ORA_DISK_1

(篇幅原因,有省略……)

piece handle=/onlinebk/control.bks tag=TAG20140303T165457 comment=NONE

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

Finished backup at 03-MAR-14

 

RMAN> backup spfile format '/onlinebk/spfile.bks';

 

Starting backup at 03-MAR-14

using channel ORA_DISK_1

(篇幅原因,有省略……)

piece handle=/onlinebk/spfile.bks tag=TAG20140303T165518 comment=NONE

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

Finished backup at 03-MAR-14

 

如果进行offline备份,则需要将数据库完整关闭(非abort关闭)。也不需要进行归档文件备份。

 

RMAN> shutdown immediate;

database closed

database dismounted

Oracle instance shut down

 

RMAN> startup mount;

 

connected to target database (not started)

Oracle instance started

database mounted

 

进行备份。

 

 

RMAN> backup database format '/oflinebk/%U';

 

Starting backup at 03-MAR-14

allocated channel: ORA_DISK_1

(篇幅原因,有省略……

piece handle=/oflinebk/09p28ukd_1_1 tag=TAG20140303T165713 comment=NONE

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

Finished backup at 03-MAR-14

 

 

RMAN> backup current controlfile format '/oflinebk/control.bks';

 

Starting backup at 03-MAR-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

(篇幅原因,有省略……

piece handle=/oflinebk/control.bks tag=TAG20140303T165824 comment=NONE

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

Finished backup at 03-MAR-14

 

RMAN> backup spfile format '/oflinebk/spfile.bks';

 

Starting backup at 03-MAR-14

using channel ORA_DISK_1

(篇幅原因,有省略……

piece handle=/oflinebk/spfile.bks tag=TAG20140303T165841 comment=NONE

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

Finished backup at 03-MAR-14

 

必要的备份元素已经具备。注意:如果从完善的角度,对TNS网络参数三文件:tnsnames.oralistener.orasqlnet.ora最好也进行备份。

 

 

3、数据库删除

 

配置XWindows工具调用dbca将原数据库删除。

 

[oracle@SimpleLinuxUp oflinebk]$ export DISPLAY=192.168.0.1:0.0

[oracle@SimpleLinuxUp oflinebk]$ xclock

Warning: Missing charsets in String to FontSet conversion

 

调用dbca删除数据库。

 


删除数据库确认。

 

SQL> conn / as sysdba 

Connected to an idle instance.

SQL> startup

ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initoratest.ora'

 

注意:使用dbca删除数据库后,根据OFA原则创建的数据库目录大都被删除。相关文件也被删除。

下面就可以进行恢复过程。

 

4、参数文件恢复

 

参数文件是确保数据库进行nomount状态、实例创建、控制文件获取的重要文件。由于RMAN是工作在mount状态以上,所以需要先进行spfile的恢复。如果使用RMAN,是可以在没有参数文件的情况下,进入一个dummy数据库的。

 

RMAN> connect target /

connected to target database (not started)

MAN> startup nomount force;

 

startup failed: ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initoratest.ora'

starting Oracle instance without parameter file for retrival of spfile

Oracle instance started

 

Total System Global Area     159383552 bytes

 

Fixed Size                     1218268 bytes

Variable Size                 54528292 bytes

Database Buffers             100663296 bytes

Redo Buffers                   2973696 bytes

 

恢复参数文件,使用restore spfile from ‘<目录>’方法。

 

RMAN> restore spfile from '/onlinebk/spfile.bks';

Starting restore at 03-MAR-14

using channel ORA_DISK_1

 

channel ORA_DISK_1: autobackup found: /onlinebk/spfile.bks

channel ORA_DISK_1: SPFILE restore from autobackup complete

Finished restore at 03-MAR-14

 

注意:这个时候还不能启动到nomount

 

SQL> conn / as sysdba

Connected.

SQL> shutdown immediate

ORA-01507: database not mounted

 

ORACLE instance shut down.

SQL> startup nomount

ORA-09925: Unable to create audit trail file

Linux Error: 2: No such file or directory

Additional information: 9925

 

这个问题的原因在于:我们删除数据库之后,原有的很多与ORATEST相关的目录都被删除。解决的方法是利用文本格式的pfile确定目录,之后手工创建出来。

 

SQL> create pfile from spfile;

File created.

 

[oracle@SimpleLinuxUp ~]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs/

[oracle@SimpleLinuxUp dbs]$ ls

hc_oratest.dat  initdw.ora  init.ora  initoratest.ora  snapcf_oratest.f  spfileoratest.ora

 

参数文件initoratest.ora中,定义了很多目录结构,如control_filesrecovery_file_dest等。内容较多,就不一一列举。手工使用mkdir进行创建。

 

[root@SimpleLinuxUp u01]# cd /

 [root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/admin/oratest/adump

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/admin/oratest/bdump

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/oradata/ORATEST/controlfile/

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/flash_recovery_area/ORATEST/controlfile

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/flash_recovery_area/ORATEST/controlfile

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/admin/oratest/cdump

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/oradata

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/flash_recovery_area

[root@SimpleLinuxUp /]# mkdir -p /u01/app/oracle/admin/oratest/udump

[root@SimpleLinuxUp /]# chown -R oracle:oinstall /u01

[root@SimpleLinuxUp /]#

 

再尝试启动到nomount,成功。

 

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup nomount

ORACLE instance started.

 

Total System Global Area  247463936 bytes

Fixed Size                  1218772 bytes

Variable Size              83887916 bytes

Database Buffers          159383552 bytes

Redo Buffers                2973696 bytes

 

5、控制文件恢复

 

使用restore controlfile from的方法进行控制文件恢复。

 

RMAN> restore controlfile from '/onlinebk/control.bks';

 

Starting restore at 03-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=431 devtype=DISK

 

channel ORA_DISK_1: restoring control file

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

output filename=/u01/app/oracle/oradata/ORATEST/controlfile/o1_mf_9k8lh412_.ctl

output filename=/u01/app/oracle/flash_recovery_area/ORATEST/controlfile/o1_mf_9k8lh45x_.ctl

Finished restore at 03-MAR-14

 

加载入control file之后,作为备份信息就可以读取到。

 

RMAN> report schema;

 

Starting implicit crosscheck backup at 03-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=431 devtype=DISK

Crosschecked 3 objects

Finished implicit crosscheck backup at 03-MAR-14

 

Starting implicit crosscheck copy at 03-MAR-14

using channel ORA_DISK_1

Finished implicit crosscheck copy at 03-MAR-14

 

searching for all files in the recovery area

cataloging files...

no files cataloged

 

RMAN-06139: WARNING: control file is not current for REPORT SCHEMA

Report of database schema

 

List of Permanent Datafiles

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

File Size(MB) Tablespace           RB segs Datafile Name

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

(篇幅原因,有省略……

List of Temporary Files

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

File Size(MB) Tablespace           Maxsize(MB) Tempfile Name

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

1    0        TEMP                 32767       /u01/app/oracle/oradata/ORATEST/datafile/o1_mf_temp_9cq625jt_.tmp

 

下面要讲/onlinebk目录中的备份加载进去,使用rmancatalog命令就可以实现这个功能。

 

 

RMAN> catalog start with '/onlinebk/';

 

searching for all files that match the pattern /onlinebk/

 

List of Files Unknown to the Database

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

File Name: /onlinebk/spfile.bks

File Name: /onlinebk/control.bks

File Name: /onlinebk/02p28u13_1_1

 

Do you really want to catalog the above files (enter YES or NO)? yes

cataloging files...

cataloging done

 

List of Cataloged Files

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

File Name: /onlinebk/spfile.bks

File Name: /onlinebk/control.bks

File Name: /onlinebk/02p28u13_1_1

 

6、恢复数据文件

 

我们使用备份数据文件、归档文件和参数文件,在online状态下,是不能进行完全恢复的。因为运行状态下,当前active的日志信息是拿不到的。所以是需要进行until scn

使用restore database preview可以查看当前可以做到什么程度。

 

RMAN> restore database preview ;

 

Starting restore at 03-MAR-14

using channel ORA_DISK_1

 

List of Backup Sets

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

(篇幅原因,有省略……)

Key     Thrd Seq     S Low Time  Name

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

2       1    5       A 03-MAR-14 /u01/app/oracle/flash_recovery_area/ORATEST/archivelog/2014_03_03/o1_mf_1_5_9k8jsw0m_.arc

Media recovery start SCN is 556011

Recovery must be done beyond SCN 556011 to clear data files fuzziness

Finished restore at 03-MAR-14

 

进行数据库restore过程。

 

 

RMAN> restore database;

 

Starting restore at 03-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=434 devtype=DISK

 

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

(篇幅原因,有省略……)

 

channel ORA_DISK_1: restored backup piece 1

piece handle=/onlinebk/03p28uab_1_1 tag=TAG20140303T165227

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

Finished restore at 03-MAR-14

 

尝试完全恢复。

 

RMAN> recover database;

Starting recover at 03-MAR-14

using channel ORA_DISK_1

 

starting media recovery

 

archive log thread 1 sequence 5 is already on disk as file /u01/app/oracle/flash_recovery_area/ORATEST/archivelog/2014_03_03/o1_mf_1_5_9k8jsw0m_.arc

archive log filename=/u01/app/oracle/flash_recovery_area/ORATEST/archivelog/2014_03_03/o1_mf_1_5_9k8jsw0m_.arc thread=1 sequence=5

unable to find archive log

archive log thread=1 sequence=6

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

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

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

RMAN-03002: failure of recover command at 03/03/2014 17:34:43

RMAN-06054: media recovery requesting unknown log: thread 1 seq 6 lowscn 556089

 

恢复失败,只能选择恢复到有日志的SCN点。

 

 

RMAN> recover database until scn 556011;

Starting recover at 03-MAR-14

using channel ORA_DISK_1

 

starting media recovery

 

archive log thread 1 sequence 5 is already on disk as file /u01/app/oracle/flash_recovery_area/ORATEST/archivelog/2014_03_03/o1_mf_1_5_9k8jsw0m_.arc

archive log filename=/u01/app/oracle/flash_recovery_area/ORATEST/archivelog/2014_03_03/o1_mf_1_5_9k8jsw0m_.arc thread=1 sequence=5

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

Finished recover at 03-MAR-14

 

启动数据库,由于online redo log的缺失和指定SCN恢复,所以必须要进行resetlogs操作open数据库。

 

SQL> alter database open resetlogs;

Database altered.

 

[oracle@SimpleLinuxUp ~]$ ps -ef | grep pmon

oracle    3512     1  0 17:21 ?        00:00:00 ora_pmon_oratest

oracle    3639  3481  0 17:44 pts/0    00:00:00 grep pmon

 

7、结论和拓展

 

同名数据库同结构恢复是比较容易的。如果需要进行数据库名称修改,或者文件目录的修改,则需要进行额外的操作和步骤。但是无论是手工进行,还是虚拟搭建RMAN auxiliary数据库,这都是可以实现的。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17203031/viewspace-1100957/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
求道~

注册时间:2010-11-30

  • 博文量
    545
  • 访问量
    7691777