Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1205957
  • 博文数量: 350
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 5668
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-23 17:53
文章分类

全部博文(350)

文章存档

2013年(350)

分类: Oracle

2013-04-27 17:07:47

 

5、单实例集恢复到

  要将单实例恢复到RAC数据库,要做的工作更多。目标库的软硬件准备工作就不提了,还有不明白的可以参考三思系列笔记:

  先描述下大致步骤如下:

  • 源端创建备份集;
  • 目标端数据库和集群件,并配置好共享存储;
  • 复制源端备份集到目标端;
  • 目录端任意节点执行正常恢复,恢复时注意要将spfile,controlfile,datafile,redofile等路径改到共享存储上,恢复完后这会儿仍然是个单实例数据库;
  • 修改初始化参数、增加UNDO表空间、增加REDOLOG线程组,重建密钥文件,目标端任意节点执行;
  • 目标端各个节点配置监听及网络服务名;
  • 将新建的数据库配置到crs,目标端任意节点执行即可。

  这回目标库选择192.168.10.11(12),该组已安装好CRS,并且还跑着一个名为jssdb的数据库,实际上咱们现在操作的这台单实例就是从那套RAC库中恢复过来的,现在好,再恢复回去,哈哈。

5.1  数据库更名

  考虑到目标数据库已经存在名为jssdb的数据库,为了简化在目标端的工作,这里先在源端给数据库改个名儿吧,改名推荐一个好工具,dbnewid,只需一行命令,即可轻松搞定,操作如下(注意nid执行时数据库必须处于mount状态):

    [oracle@jssnode1 data1]$ nid target=/ dbname=repdb

    DBNEWID: Release 10.2.0.4.0 - Production on Thu Mar 25 10:46:26 2010

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

    Connected to database JSSDB (DBID=953576437)

    Connected to server version 10.2.0

    Control Files in database:

        /data1/jssdb/control01.ctl

        /data1/jssdb/control02.ctl

        /data1/jssdb/control03.ctl

    Change database ID and database name JSSDB to REPDB? (Y/[N]) => y

    Proceeding with operation

    Changing database ID from 953576437 to 822106115

    Changing database name from JSSDB to REPDB

        Control File /data1/jssdb/control01.ctl - modified

        Control File /data1/jssdb/control02.ctl - modified

        Control File /data1/jssdb/control03.ctl - modified

        Datafile /data1/jssdb/system01.dbf - dbid changed, wrote new name

        Datafile /data1/jssdb/undoa01.dbf - dbid changed, wrote new name

        Datafile /data1/jssdb/sysaux01.dbf - dbid changed, wrote new name

        Datafile /data1/jssdb/users01.dbf - dbid changed, wrote new name

        Datafile /data1/jssdb/jsstbs01.dbf - dbid changed, wrote new name

        Datafile /data1/jssdb/temp01.dbf - dbid changed, wrote new name

        Control File /data1/jssdb/control01.ctl - dbid changed, wrote new name

        Control File /data1/jssdb/control02.ctl - dbid changed, wrote new name

        Control File /data1/jssdb/control03.ctl - dbid changed, wrote new name

        Instance shut down

    Database name changed to REPDB.

    Modify parameter file and generate a new password file before restarting.

    Database ID for database REPDB changed to 822106115.

    All previous backups and archived redo logs for this database are unusable.

    Database has been shutdown, open database with RESETLOGS option.

    Succesfully changed database name and ID.

    DBNEWID - Completed succesfully.

  数据库被自动关闭,重启数据库到nomount模式,修改初始化参数db_name

    [oracle@jssnode1 data1]$ sqlplus / as sysdba

    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Mar 25 10:54:03 2010

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

    Connected to an idle instance.

    SQL> startup nomount

    ORACLE instance started.

    Total System Global Area  285212672 bytes

    Fixed Size                  2083368 bytes

    Variable Size             125830616 bytes

    Database Buffers          150994944 bytes

    Redo Buffers                6303744 bytes

    SQL> alter system set db_name=¨repdb¨ scope=spfile;

    System altered.

    SQL> alter system set instance_name=¨repdb¨ scope=spfile;

    System altered.

    SQL> shutdown immediate

    ORA-01507: database not mounted

    ORACLE instance shut down.

    SQL> exit

    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production

    With the Partitioning, OLAP, Data Mining and Real Application Testing options

    [oracle@jssnode1 data1]$ mv /data/ora10g/product/10.2.0/db_1/dbs/spfilejssdb.ora /data/ora10g/product/10.2.0/db_1/dbs/spfilerepdb.ora

  重启数据库到mount模式,并以open resetlogs方式打开数据库:

    [oracle@jssnode1 data1]$ export ORACLE_SID=repdb

    [oracle@jssnode1 data1]$ sqlplus / as sysdba

    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Mar 25 10:59:58 2010

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

    Connected to an idle instance.

    SQL> startup mount

    ORACLE instance started.

    Total System Global Area  285212672 bytes

    Fixed Size                  2083368 bytes

    Variable Size              88081880 bytes

    Database Buffers          188743680 bytes

    Redo Buffers                6303744 bytes

    Database mounted.

    SQL> alter database open resetlogs;

    Database altered.

  验证一下吧:

    SQL> select dbid, name from v$database;

          DBID NAME

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

     822106115 REPDB

    SQL> select global_name from global_name;

    GLOBAL_NAME

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

    REPDB

  搞定。

5.2 恢复成单实例数据库

  先要恢复出初始化参数文件,操作步骤繁琐一点点,其实很简单,操作如下:

    [oracle@jssdbn2 ~]$ export ORACLE_SID=repdb

    [oracle@jssdbn2 ~]$ rman target /

    Recovery Manager: Release 10.2.0.4.0 - Production on Thu Mar 25 11:25:03 2010

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

    connected to target database (not started)

    RMAN> set dbid=822106115

    executing command: SET DBID

    RMAN> startup nomount

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

    LRM-00109: could not open parameter file ¨/data/ora10g/product/10.2.0/db_1/dbs/initrepdb.ora¨

    starting Oracle instance without parameter file for retrival of spfile

    Oracle instance started

    Total System Global Area     159383552 bytes

    Fixed Size                     2082400 bytes

    Variable Size                 71305632 bytes

    Database Buffers              79691776 bytes

    Redo Buffers                   6303744 bytes

    RMAN> restore spfile to  pfile  ¨/data/ora10g/admin/repdb/pfile/initrepdb.ora¨  from ¨/data/backup/09l9esg4_1_1¨;

    Starting restore at 25-MAR-10

    using channel ORA_DISK_1

    channel ORA_DISK_1: autobackup found: /data/backup/09l9esg4_1_1

    channel ORA_DISK_1: PFILE restore from autobackup complete

    Finished restore at 25-MAR-10

  打开 initrepdb.ora 文件,对一些文件路径相关的参数进行修改,本例中需要修改的参数有:audit_file_dest,background_dump_dest,control_files,core_dump_dest,log_archive_dest_1,user_dump_dest等。按实例情况进行修改并保存,而后再通过该pfile创建spfile,注意哟,创建的spfile可是要放到共享存储上去的:

    SQL> create spfile=¨+ASMDISK2/repdb/spfile/spfilerepdb.ora¨ from pfile=¨/data/ora10g/admin/repdb/pfile/initrepdb.ora¨;

    File created.
    提示:上述修改尤其要注意control_files指定的路径,务必放在共享存储上,这里是修改到ASM中。另外如果情况允许,log_archive_dest_n相关路径也建议放在共享存储上。

  修改客户端初始化参数文件,内容指向到asm共享盘中的SPFILE,命令如下:

    [oracle@jssdbn2 oradata]$ echo "SPFILE=¨+ASMDISK2/repdb/spfile/spfilerepdb.ora¨" > /data/ora10g/product/10.2.0/db_1/dbs/initrepdb.ora

  重新启动数据库到nomount状态:

    SQL> startup nomount

    ORACLE instance started.

    Total System Global Area  285212672 bytes

    Fixed Size                  2083368 bytes

    Variable Size              88081880 bytes

    Database Buffers          188743680 bytes

    Redo Buffers                6303744 bytes

    SQL> show parameter spfile

    NAME                                 TYPE        VALUE

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

    spfile                               string      +ASMDISK2/repdb/spfile/spfiler

                                                     epdb.ora

   执行对控制文件的恢复:

    RMAN> connect target /

    connected to target database:  (not mounted)

    using target database control file instead of recovery catalog

    RMAN> set dbid = 822106115

    executing command: SET DBID

    RMAN> restore controlfile from ¨/data/backup/09l9esg4_1_1¨;

    Starting restore at 25-MAR-10

    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:16

    output filename=+ASMDISK2/repdb/control01.ctl

    output filename=+ASMDISK2/repdb/control02.ctl

    output filename=+ASMDISK2/repdb/control03.ctl

    Finished restore at 25-MAR-10

  然后就可以将数据库启动到MOUNT状态了:

    RMAN> alter database mount;

    database mounted

    released channel: ORA_DISK_1

  将复制过来的数据文件备份集注册到备份资料库中,操作如下:

    RMAN> catalog backuppiece ¨/data/backup/08l9esfa_1_1¨;

    cataloged backuppiece

    backup piece handle=/data/backup/08l9esfa_1_1 recid=6 stamp=714575911

    RMAN> list backup;

    List of Backup Sets

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

    BS Key  Type LV Size

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

    5       Full    710.99M

      List of Datafiles in backup set 5

      File LV Type Ckp SCN    Ckp Time  Name

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

      1       Full 16365338   25-MAR-10 /data1/jssdb/system01.dbf

      2       Full 16365338   25-MAR-10 /data1/jssdb/undoa01.dbf

      3       Full 16365338   25-MAR-10 /data1/jssdb/sysaux01.dbf

      5       Full 16365338   25-MAR-10 /data1/jssdb/users01.dbf

      6       Full 16365338   25-MAR-10 /data1/jssdb/jsstbs01.dbf

      Backup Set Copy #1 of backup set 5

      Device Type Elapsed Time Completion Time Compressed Tag

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

      DISK        00:00:22     25-MAR-10       NO         TAG20100325T110930

        List of Backup Pieces for backup set 5 Copy #1

        BP Key  Pc# Status      Piece Name

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

        5       1   AVAILABLE   /data1/backup/08l9esfa_1_1

      Backup Set Copy #2 of backup set 5

      Device Type Elapsed Time Completion Time Compressed Tag

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

      DISK        00:00:22     25-MAR-10       NO         TAG20100325T110930

        List of Backup Pieces for backup set 5 Copy #2

        BP Key  Pc# Status      Piece Name

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

        6       1   AVAILABLE   /data/backup/08l9esfa_1_1

  接下来要恢复数据文件,直接执行RESTORE命令显然是不行的,因为原文件路径并没被放在共享存储,因此我们还需要在恢复前,对相关文件的路径进行重定义,操作如下:

    RMAN> RUN {

    2> SET NEWNAME FOR DATAFILE 1 to ¨+ASMDISK2/repdb/datafile/system01.dbf¨;

    3> SET NEWNAME FOR DATAFILE 2 to ¨+ASMDISK2/repdb/datafile/undoa01.dbf¨;

    4> SET NEWNAME FOR DATAFILE 3 to ¨+ASMDISK2/repdb/datafile/sysaux01.dbf¨;

    5> SET NEWNAME FOR DATAFILE 5 to ¨+ASMDISK2/repdb/datafile/users01.dbf¨;

    6> SET NEWNAME FOR DATAFILE 6 to ¨+ASMDISK2/repdb/datafile/jsstbs01.dbf¨;

    7> SET NEWNAME FOR TEMPFILE 1 to ¨+ASMDISK2/repdb/datafile/temp01.dbf¨;

    8> RESTORE DATABASE;

    9> SWITCH DATAFILE ALL;

    10> SWITCH TEMPFILE ALL;

    11> }

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    Starting restore at 25-MAR-10

    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 +ASMDISK2/repdb/datafile/system01.dbf

    restoring datafile 00002 to +ASMDISK2/repdb/datafile/undoa01.dbf

    restoring datafile 00003 to +ASMDISK2/repdb/datafile/sysaux01.dbf

    restoring datafile 00005 to +ASMDISK2/repdb/datafile/users01.dbf

    restoring datafile 00006 to +ASMDISK2/repdb/datafile/jsstbs01.dbf

    channel ORA_DISK_1: reading from backup piece /data1/backup/08l9esfa_1_1

    channel ORA_DISK_1: restored backup piece 1

    failover to piece handle=/data/backup/08l9esfa_1_1 tag=TAG20100325T110930

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

    Finished restore at 25-MAR-10

    datafile 1 switched to datafile copy

    input datafile copy recid=6 stamp=714576020 filename=+ASMDISK2/repdb/datafile/system01.dbf

    datafile 2 switched to datafile copy

    input datafile copy recid=7 stamp=714576021 filename=+ASMDISK2/repdb/datafile/undoa01.dbf

    datafile 3 switched to datafile copy

    input datafile copy recid=8 stamp=714576021 filename=+ASMDISK2/repdb/datafile/sysaux01.dbf

    datafile 5 switched to datafile copy

    input datafile copy recid=9 stamp=714576021 filename=+ASMDISK2/repdb/datafile/users01.dbf

    datafile 6 switched to datafile copy

    input datafile copy recid=10 stamp=714576021 filename=+ASMDISK2/repdb/datafile/jsstbs01.dbf

    renamed temporary file 1 to +ASMDISK2/repdb/datafile/temp01.dbf in control file

  恢复工作基本竣工。你是否想说还没recover呢,这里呢并不需要,因为之前创建备份集时数据库处理mount状态,也就是一致性状态,因此并不需要进行recover,下面再对redo文件的路径进行重定义,将其也移至共享存储,操作如下:

    SQL> select * from v$Logfile;

        GROUP# STATUS  TYPE    MEMBER                         IS_

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

             2         ONLINE  /data1/jssdb/redo02.dbf        NO

             1         ONLINE  /data1/jssdb/redo01.dbf        NO

    SQL> alter database rename file ¨/data1/jssdb/redo01.dbf¨ to ¨+ASMDISK2/repdb/redofile/redoa01.dbf¨;

    Database altered.

    SQL> alter database rename file ¨/data1/jssdb/redo02.dbf¨ to ¨+ASMDISK2/repdb/redofile/redob01.dbf¨;

    Database altered.

  然后直接open resetlogs即可:

    RMAN> alter database open resetlogs;

    database opened
待续~~~
阅读(2012) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~