目标 

主要测试如何使用RMAN将single数据库恢复到rac数据库

HCMPRD RAC测试环境:

HCMPRD数据库恢复HCMPRD RAC数据库_第1张图片

生产环境:HCMPRD

HCMPRD数据库恢复HCMPRD RAC数据库_第2张图片

测试目的:

测试恢复数据库

41和42 RAC只安装了grid和Oracle数据库软件。

实施步骤

1.         分配共享磁盘

存放恢复后的HCMPRD数据库数据文件和备份文件。

2.         安装oracle实例

对照HCMPRD生产库,在测试主机上安装对应版本的oracle软件 (11.2.0.3.0);

3.         修改初始化参数

将HCMPRD生产库初始化文件拷贝至测试主机上,并对参数做如下修改(部分参数进行调整).

在生产库HCMPRD备份数据库(包括当前控制文件和归档日志):

run {

  backup full filesperset 20 tag 'dbfull'format '/mnt/RMAN_DIR2/DATA/full_%d__%T_%u_%s_%p' database include currentcontrolfile;

  sql 'alter system archive log current';

  backup filesperset 20  maxsetsize 10G format '/mnt/RMAN_DIR2/DATA/arch_%Y%M%D_%u_%s_%p'skip inaccessible archivelog all;

}

然后备份完,让IP10.200.130.41中oracle用户能够访问;修改必要的权限,否则在restore controlfile时会读取不到控制文件;

Chown –R oracle:oinstalldata/

目标端10.200.130.41  注意一下undo表空间是哪个文件以及其他

(1)在$ORACLE_HOEM/dbs目录下创建initHCMPRD1.ora

修改之后的pfile文件如下:

HCMPRD.__oracle_base='/u01/app/oracle'#ORACLE_BASEset from environment

*.audit_file_dest='/u01/app/oracle/admin/HCMPRD/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='+RACDB_DATA /HCMPRD/controlfile/current.256.787766785','+ GRIDCRS /HCMPRD/controlfile/current.256.787766785'

*.db_create_file_dest='+RACDB_DATA'

*.db_recovery_file_dest='+GRIDCRS'

*.db_block_size=8192

*.db_domain=''

*.db_name='HCMPRD'

*.dispatchers='(PROTOCOL=TCP)(SERVICE=HCMPRDXDB)'

*.nls_language='SIMPLIFIEDCHINESE'

*.nls_territory='CHINA'

*.open_cursors=300

*.diagnostic_dest='/u01/app/oracle/diag'

*.log_archive_dest_1='LOCATION=+GRIDCRS'/HCMPRD/archivelog/'

*.log_archive_format='%t_%s_%r.arc'

*.processes=150

*.db_recovery_file_dest_size=42950000000

*.remote_login_passwordfile='exclusive'

*.memory_target=1210612736

*.undo_tablespace=PSUNDOTS

*.db_file_name_convert=('/u02/oradata/HCMPRD/datafile','+RACDB_DATA/HCMPRD/datafile')

*.db_file_name_convert=('/u02/oradata/HCMPRD//tempfile','+RACDB_DATA/HCMPRD/tempfile')

 

注意最后两行,因为RAC的目录结构不一样,所以这里需要进行转换一下。这里面要根据自己的情况来决定。

{

两个节点都创建:

/u01/app/oracle/admin

mkdir -p admin/HCMPRD/adump

 

**以下是存放在ASM共享存储 只在一个节点创建即可

--对于源数据库存放的控制文件、数据文件、临时数据文件、onlinelog目录进行操作

 

--存放数据文件和临时文件

ASMCMD> pwd

+GDATA

ASMCMD> mkdir HCMPRD

ASMCMD> cd HCMPRD

ASMCMD> mkdir datafile

ASMCMD> mkdir tempfile

ASMCMD> mkdircontrolfile --存放控制文件

ASMCMD> pwd

+GCRS/HCMPRD

ASMCMD> mkdircontrolfile

--创建归档目录

+GCRS/HCMPRD/archivelog/

ASMCMD> mkdirarchivelog

--存放onlinelog

+GCRS/HCMPRD

ASMCMD> mkdir onlinelog

ASMCMD> pwd

+GCRS/HCMPRD/onlinelog

 

+GDATA/HCMPRD

ASMCMD> mkdir onlinelog

ASMCMD> pwd

+GDATA/HCMPRD/onlinelog

}

(2)创建目标库HCMPRD的口令文件:两个节点都执行

$orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SIDpassword=Tony870612 entries=4 force=y

(注意文件名:应该为orapw$ORACLE_SID,可能无法识别。)

目标端10.200.130.41:

使用pfile(参数文件)启动到nomount状态:

[oracle@RAC01 ~]$ export ORACLE_SID=HCMPRD1

[oracle@RAC01 ~]$ ss

SQL*Plus: Release 11.2.0.3.0 Production on Thu Nov 1509:48:38 2012

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

Connected to an idle instance.

SQL> startup nomountpfile='/u01/app/oracle/product/11.2.3/db_1/dbs/initHCMPRD1.ora';

ORACLE instance started.

 

Total System Global Area 1219260416 bytes

Fixed Size                  2227864 bytes

Variable Size            738197864 bytes

Database Buffers    469762048 bytes

Redo Buffers             9072640 bytes

设置dbid(是从生产库得到的select dbid fromv$database),恢复控制文件,修改rman的默认配置,并且set newname然后restore,在recover。

SQL> select dbid from v$database;  --在生产库上查询

      DBID

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

     460426404

 

[oracle@RAC01 ~]$ rman target /

RMAN> set dbid=460426404;

RMAN> restore controlfile from '/data/hcmprd_1/bak/full_HCMPRD__20130207_2oo1c50d_88_1';

Starting restore at 07-FEB-2013 11:38:43

using channel ORA_DISK_1

 

channel ORA_DISK_1: restoring control file

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

output filename=+RACDB_DATA/hcmprd/controlfile/current.256.806758725

output filename=+GRIDCRS/hcmprd/controlfile/current.256.806758725

Finished restore at 07-FEB-2013 11:38:46

 

RMAN> alter database mount;

database mounted

released channel: ORA_DISK_1

 

--向控制文件中加载备份集

RMAN> catalog start with'/data/hcmprd_1/bak';

RMAN> report schema;

RMAN>recover database;

Starting recover at07-FEB-2013 13:33:33

using channel ORA_DISK_1

 

starting media recovery

 

channel ORA_DISK_1:starting archived log restore to default destination

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1192

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1193

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1194

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1195

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1196

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1197

channel ORA_DISK_1:restoring archived log

archived log thread=1sequence=1198

channel ORA_DISK_1:reading from backup piece /data/hcmprd_1/bak/arch_20130207_3no1c9gf_119_1

channel ORA_DISK_1: piecehandle=/data/hcmprd_1/bak/arch_20130207_3no1c9gf_119_1 tag=TAG20130207T100819

channel ORA_DISK_1:restored backup piece 1

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

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1192_802614672.arc thread=1 sequence=1192

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1193_802614672.arc thread=1 sequence=1193

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1194_802614672.arc thread=1 sequence=1194

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1195_802614672.arc thread=1 sequence=1195

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1196_802614672.arc thread=1 sequence=1196

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1197_802614672.arc thread=1 sequence=1197

archived log filename=+GRIDCRS/hcmprd/archivelog/1_1198_802614672.arc thread=1 sequence=1198

unable to find archivedlog

archived log thread=1sequence=1199

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

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

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

RMAN-03002: failure ofrecover command at 02/07/2013 13:37:44

RMAN-06054: media recoveryrequesting unknown archived log for thread 1 with sequence 1199 and startingSCN of 74609878

这里由于部分archive log日志没有此备份归档日志,出现错误。

在recover 完成后;做alterdatabase rename file 看是否能不重建控制文件,而直接打开数据库并且rsetlogs;

 

在生产库上查询日志存放位置 然后进行renamefile:

SQL> col member for a65

SQL> selectmember from v$logfile;

MEMBER

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

/u02/oradata/HCMPRD/redo06.log

/u02/oradata/HCMPRD/redo05.log

/u02/oradata/HCMPRD/redo04.log

/u02/oradata/HCMPRD/redo03.log

/u02/oradata/HCMPRD/redo02.log

/u02/oradata/HCMPRD/redo01.log

 

在测试库上进行操作

alter databaserename file'/u02/oradata/HCMPRD/redo01.log' to'+racdb_data/hcmprd/onlinelog/redo01.log';

alter database renamefile'/u02/oradata/HCMPRD/redo02.log' to '+racdb_data/hcmprd/onlinelog/redo02.log';

alter database renamefile'/u02/oradata/HCMPRD/redo03.log' to'+racdb_data/hcmprd/onlinelog/redo03.log';

alter database renamefile'/u02/oradata/HCMPRD/redo04.log' to'+racdb_data/hcmprd/onlinelog/redo04.log';

alter database renamefile'/u02/oradata/HCMPRD/redo05.log' to'+racdb_data/hcmprd/onlinelog/redo05.log';

alter database renamefile'/u02/oradata/HCMPRD/redo06.log' to'+racdb_data/hcmprd/onlinelog/redo06.log';

在测试库上进行操作:

SQL> ALTER DATABASE OPENRESETLOGS;

Database altered.

查找缺失的archive log:

SQL> selectl.RECID,l.SEQUENCE#,d.CHECKPOINT_CHANGE#,l.FIRST_CHANGE#,l.NEXT_CHANGE#,l.NAME

   from v$databased,v$archived_log l where d.RESETLOGS_CHANGE# = l.RESETLOGS_CHANGE# andl.SEQUENCE#=4418;

     RECID SEQUENCE# NAME -----------------------------------------------------------------------------

      7024    4418 +FAR/HCMPRD/archivelog/2012_11_15/thread_1_seq_4418.4373.799424917

 

ASMCMD> cpthread_1_seq_4418.4373.799424917 /home/grid/

copying +FAR/HCMPRD/archivelog/2012_08_22/thread_1_seq_3068.3628.792022053-> /home/grid//thread_1_seq_3068.3628.792022053

ASMCMD> pwd

+FAR/HCMPRD/archivelog/2012_11_15

Set pagesize 999 linesize777

Col member for a65

SQL> select l.group#,l.thread#, bytes/1024.1024, a.member from v$log l, v$logfile a wherel.group#=a.group#;

GROUP#    THREAD# BYTES/1024.1024 MEMBER

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

        1        1       51194.8805 /data/app/oracle/oradata/redo01.log

        1        1       51194.8805 /data/app/oracle/oradata/redo01a.log

        2        1       51194.8805 /data/app/oracle/oradata/redo02.log

        2        1       51194.8805 /data/app/oracle/oradata/redo02a.log

        3        2        51194.8805/data/app/oracle/oradata/redo03.log

        3        2       51194.8805 /data/app/oracle/oradata/redo03a.log

        4        2       51194.8805 /data/app/oracle/oradata/redo04.log

        4        2       51194.8805 /data/app/oracle/oradata/redo04a.log

恢复成功后的后续处理

setpagesize 999 linesize 777

 col member for a76

select l.group#,thread#,l.status, member,bytes/1024/1024 from v$log l, v$logfile f wherel.group#=f.group# order by group#;

{

删除redo log组  如果删不掉 switch

SQL> alterdatabase drop logfile group 5;

SQL> alterdatabase drop logfile group 6;

添加logfile组  使用OMF方式管理的

ALTER DATABASEADD LOGFILE THREAD 2 GROUP 7 size 500M;

ALTER DATABASEADD LOGFILE THREAD 2 GROUP 8 size 500M

 

ALTER DATABASEADD LOGFILE THREAD 2 GROUP 5 size 500M;

ALTER DATABASEADD LOGFILE THREAD 2 GROUP 6 size 500M

}

重点 重点  重点  重点  重点

关闭节点1数据库

SQL>shutdown immediate

Databaseclosed.

Databasedismounted.

ORACLEinstance shut down.

在节点1上修改initHCMPRD1.ora文件;位置在$ORACLE_HOME/dbs其最后内容为:

HCMPRD1.__oracle_base='/u01/app/oracle'#ORACLE_BASEset from environment

HCMPRD2.__oracle_base='/u01/app/oracle'#ORACLE_BASEset from environment

*.audit_file_dest='/u01/app/oracle/admin/HCMPRD/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='+RACDB_DATA/HCMPRD/controlfile/current.256.806770117','+GRIDCRS/HCMPRD/controlfile/current.256.806770117'

*.db_create_file_dest='+RACDB_DATA'

*.db_recovery_file_dest='+GRIDCRS'

*.db_block_size=8192

*.db_domain=''

*.db_name='HCMPRD'

*.dispatchers='(PROTOCOL=TCP)(SERVICE=HCMPRDXDB)'

*.nls_language='SIMPLIFIEDCHINESE'

*.nls_territory='CHINA'

*.open_cursors=300

*.diagnostic_dest='/u01/app/oracle/diag'

*.log_archive_dest_1='LOCATION=+GRIDCRS/HCMPRD/archivelog/'

*.log_archive_format='%t_%s_%r.arc'

*.processes=150

*.db_recovery_file_dest_size=42950000000

*.remote_login_passwordfile='exclusive'

*.memory_target=1210612736

HCMPRD2.thread=2

HCMPRD1.thread=1

HCMPRD2.undo_tablespace='UNDOTBS2'

HCMPRD1.undo_tablespace='PSUNDOTS'

remote_listener='rac-scan.tony.cn:1521'

HCMPRD1.instance_number=1

HCMPRD2.instance_number=2

*.cluster_database=TRUE

*.db_file_name_convert=('/u02/oradata/HCMPRD/datafile','+RACDB_DATA/HCMPRD/datafile')

*.db_file_name_convert=('/u02/oradata/HCMPRD//tempfile','+RACDB_DATA/HCMPRD/tempfile')

 

在节点2上创建initHCMPRD2.ora文件

 

使用initHCMPRD1.ora启动节点1数据库,使用initHCMPRD2.ora启动节点2数据库

SQL> startupmount pfile='/u01/app/oracle/product/11.2.3/db_1/dbs/initHCMPRD11.ora';

SQL> startupmount pfile='/u01/app/oracle/product/11.2.3/db_1/dbs/initHCMPRD21.ora';

然后怎么样让两个节点公用一个spfile文件?创建到ASM共享存储上:操作如下:

[oracle@rac01~]$ cd $ORACLE_HOME/dbs

[oracle@rac01dbs]$ pwd

/u01/app/oracle/product/11.2.3/db_1/dbs

**一个节点执行 即可

使用initHCMPRD1.ora文件

SQL> createspfile='+RACDB_DATA/HCMPRD/spfileHCMPRD.ora' from pfile='/u01/app/oracle/product/11.2.3/db_1/dbs/initHCMPRD1.ora';

然后编辑vi  initHCMPRD1.ora其内容为:

SPFILE='+RACDB_DATA/HCMPRD/spfileHCMPRD.ora'

其节点2 initHCMPRD2.ora内容一样;

在两个节点上启动数据库:

SQL>startup mount pfile='/u01/app/oracle/product/11.2.3/db_1/dbs/initHCMPRD1.ora';

SQL>startup mount pfile='/u01/app/oracle/product/11.2.3/db_1/dbs/initHCMPRD2.ora';

然后打开两个数据库。

 

监听:

[oracle@RAC01 admin]$ morelistener.ora

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST =IP)(PORT = 1521))

      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))

    )

  )

 

数据库总大小

SQL> select round(sum(space)) all_space_m

      from (select sum(bytes) / 1024 / 1024 space

               from dba_data_files

            union all

            select nvl(sum(bytes) / 1024 / 1024, 0) space

               from dba_temp_files

            union all

             select sum(bytes) / 1024 / 1024space

      from v$log);

表空间检查;

set pagesize 888 linesize 666

col tablespace_name format a35

SELECT UPPER(F.TABLESPACE_NAME)"tablespace_name",

      D.TOT_GROOTTE_MB "sum_space(M)",

      D.TOT_GROOTTE_MB-F.TOTAL_BYTES "use_space(M)",

TO_CHAR(ROUND((D.TOT_GROOTTE_MB-F.TOTAL_BYTES)/D.TOT_GROOTTE_MB*100,2),'990.99')"use rate%",

      F.TOTAL_BYTES "free_space(M)"

FROM (SELECT TABLESPACE_NAME,

            ROUND(SUM(BYTES)/1024/1024) TOTAL_BYTES,

            ROUND(MAX(BYTES)/(1024*1024),2) MAX_BYTES

     FROM SYS.DBA_FREE_SPACE

     GROUP BY TABLESPACE_NAME) F,

    (SELECT DD.TABLESPACE_NAME,

            ROUND(SUM(BYTES)/1024/1024) TOT_GROOTTE_MB

     FROM SYS.DBA_DATA_FILES DD

     GROUP BY DD.TABLESPACE_NAME) D

WHERE D.TABLESPACE_NAME=F.TABLESPACE_NAME

ORDER BY 2 DESC;