5、单实例备份集恢复到RAC
要将单实例数据库恢复到RAC数据库,要做的工作更多。目标库的软硬件准备工作就不提了,还有不明白的可以参考三思系列笔记:手把手教你用vmware安装ORACLE10g 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 执行对控制文件的恢复:
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> 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即可:
5.3、启用集群特性:
查看集群相关初始化参数:
SQL> select * from v$option where parameter = ¨Real Application Clusters¨;
PARAMETER VALUE
---------------------------------------- --------------------
Real Application Clusters TRUE
SQL> show parameter cluster
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean FALSE
cluster_database_instances integer 1
cluster_interconnects string
由上述返回结果可知,RAC特性是支持的,不过尚未启用集群数据库,因此接下来首先要改的,就是enable CLUSTER DATABASE,操作如下:
SQL> alter system set cluster_database=true scope=spfile;
System altered.
SQL> alter system set cluster_database_instances=2 scope=spfile;
System altered.
SQL> alter system set instance_number=1 scope=spfile sid=¨repdb1¨;
System altered.
SQL> alter system set instance_number=2 scope=spfile sid=¨repdb2¨;
System altered.
SQL> alter system set thread=1 scope=spfile sid=¨repdb1¨;
System altered.
SQL> alter system set thread=2 scope=spfile sid=¨repdb2¨;
System altered.
新建一组UNDO表空间和线程2使用的两组REDO文件:
SQL> create undo tablespace undotbs2 datafile ¨+ASMDISK2/repdb/datafile/undob01.dbf¨ size 256m;
Tablespace created.
SQL> alter system set undo_tablespace=¨undotbs1¨ scope=spfile sid=¨repdb1¨;
System altered.
SQL> alter system set undo_tablespace=¨undotbs2¨ scope=spfile sid=¨repdb2¨;
System altered.
SQL> create undo tablespace undotbs2 datafile ¨+ASMDISK2/repdb/datafile/undob01.dbf¨ size 256m;
Tablespace created.
SQL> alter database add logfile thread 2 group 3 ¨+ASMDISK2/repdb/redofile/redoc01.dbf¨ size 50m;
Database altered.
SQL> alter database add logfile thread 2 group 4 ¨+ASMDISK2/repdb/redofile/redod01.dbf¨ size 50m;
Database altered.
SQL> alter database enable thread 2;
Database altered.
酌情对log_archive_dest_n,* _file_dest 等参数进行设置,由于RAC数据库的各个实例分别在不同节点上运行,一定要确保上述参数的路径对所有节点均有效,同时各个节点的目录也应满足上述参数的需要,避免由目录不存在导致的数据库错误。
关闭数据库,并退出sqlplus命令行环境,修改ORACLE_SID以适应多实例环境,先在节一个节点中进行操作:
[oracle@jssdbn2 oradata]$ export ORACLE_SID=repdb2
[oracle@jssdbn2 oradata]$ echo "SPFILE=¨+ASMDISK2/repdb/spfile/spfilerepdb.ora¨" > /data/ora10g/product/10.2.0/db_1/dbs/initrepdb2.ora
[oracle@jssdbn2 oradata]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Mar 25 14:22:54 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> startup
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.
Database opened.
SQL> show parameter cluster;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
cluster_interconnects string
SQL> set line 150 pages 1000
SQL> select instance_number,instance_name,host_name from v$instance;
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
--------------- ---------------- ----------------------------------------------------------------
2 repdb2 jssdbn2
然后再到另一个节点中执行,注意更改ORACLE_SID:
[oracle@jssdbn1 ~]$ export ORACLE_SID=repdb1
[oracle@jssdbn1 ~]$ echo "SPFILE=¨+ASMDISK2/repdb/spfile/spfilerepdb.ora¨" > /data/ora10g/product/10.2.0/db_1/dbs/initrepdb1.ora
[oracle@jssdbn1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Mar 25 14:23:45 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> startup
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.
Database opened.
SQL> set line 150 pages 1000
SQL> show parameter cluster;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
cluster_interconnects string
SQL> select instance_number,instance_name,host_name from v$instance;
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
--------------- ---------------- ----------------------------------------------------------------
1 repdb1 jssdbn1
查询gv$视图看看:
SQL> select instance_number,instance_name,host_name from gv$instance;
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME
--------------- ---------------- ----------------------------------------------------------------
1 repdb1 jssdbn1
2 repdb2 jssdbn2
OK ,现在已经是集群的数据库了,整个恢复工作基本完成。剩下的比如修改监听、配置网络服务名,创建密钥文件等操作相信大家已经熟悉的不能再熟悉,这里不再演示相关操作了(注意密钥文件也是建议创建到共享存储端,否则的话就得在各个节点分别创建一份)。
不过这时候通过crs_stat -t查看的时候,还看不到新创建的repdb数据库信息:
[oracle@jssdbn2 ~]$ /data/ora10g/product/10.2.0/crs_1/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.jssdb.db application OFFLINE OFFLINE
ora....n1.inst application OFFLINE OFFLINE
ora....n2.inst application OFFLINE OFFLINE
ora....SM1.asm application ONLINE ONLINE jssdbn1
ora....N1.lsnr application ONLINE ONLINE jssdbn1
ora....bn1.gsd application ONLINE ONLINE jssdbn1
ora....bn1.ons application ONLINE ONLINE jssdbn1
ora....bn1.vip application ONLINE ONLINE jssdbn1
ora....SM2.asm application ONLINE ONLINE jssdbn2
ora....N2.lsnr application ONLINE ONLINE jssdbn2
ora....bn2.gsd application ONLINE ONLINE jssdbn2
ora....bn2.ons application ONLINE ONLINE jssdbn2
ora....bn2.vip application ONLINE ONLINE jssdbn2
这是正常的,因为手动恢复数据库,其配置信息并没有维护到crs中,需要手动处理,操作如下:
[oracle@jssdbn2 ~]$ srvctl add database -d repdb -o $ORACLE_HOME -n repdb -p +ASMDISK2/repdb/spfile/spfilerepdb.ora
[oracle@jssdbn2 ~]$ srvctl add instance -d repdb -i repdb1 -n jssdbn1
[oracle@jssdbn2 ~]$ srvctl add instance -d repdb -i repdb2 -n jssdbn2
上述3条命令分别配置了数据库和两个实例,此时3项服务刚刚配置完成,crs中尚未同步其状态,因此需要执行一下srvctl start database,然后再通过crs_stat即可查看正确的状态了:
[oracle@jssdbn2 ~]$ srvctl start database -d repdb
[oracle@jssdbn2 ~]$ /data/ora10g/product/10.2.0/crs_1/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.jssdb.db application OFFLINE OFFLINE
ora....n1.inst application OFFLINE OFFLINE
ora....n2.inst application OFFLINE OFFLINE
ora....SM1.asm application ONLINE ONLINE jssdbn1
ora....N1.lsnr application ONLINE ONLINE jssdbn1
ora....bn1.gsd application ONLINE ONLINE jssdbn1
ora....bn1.ons application ONLINE ONLINE jssdbn1
ora....bn1.vip application ONLINE ONLINE jssdbn1
ora....SM2.asm application ONLINE ONLINE jssdbn2
ora....N2.lsnr application ONLINE ONLINE jssdbn2
ora....bn2.gsd application ONLINE ONLINE jssdbn2
ora....bn2.ons application ONLINE ONLINE jssdbn2
ora....bn2.vip application ONLINE ONLINE jssdbn2
ora.repdb.db application ONLINE ONLINE jssdbn1
ora....b1.inst application ONLINE ONLINE jssdbn1
ora....b2.inst application ONLINE ONLINE jssdbn2
恢复操作至此基本完成。
关于RAC与其它ORACLE特性的应用,请继续关注下一个系列文章:ORACLE RAC数据库与DATA GUARD。
全文完,下载pdf版本请至:http://www.5ienet.com/mydesign/article.asp?/html/rid/119.html |