全库恢复(异机)
全库恢复到另外一台测试库,属于异机恢复
Ø 测试库创建PFILE参数文件INITSHESTATE.ORA
*.aq_tm_processes=0 *.compatible='9.2.0.0.0' *.db_block_size=8192 *.db_cache_size=268435456 *.db_name=shestate *.db_file_multiblock_read_count=16 *.job_queue_processes=10 *.open_cursors=300 *.pga_aggregate_target=254803968 *.processes=150 *.session_max_open_files=20 #*.sga_target=767557632 *.sga_max_size=536870912 *.large_pool_size=33554432 *.shared_pool_size=262144000 *.sort_area_size=524288 *.undo_management='AUTO' *.undo_retention=900 *.undo_tablespace='UNDOTBS1' *.audit_file_dest='/u01/oracle/admin/shestate/adump' *.user_dump_dest='/u01/oracle/admin/shestate/udump' *.background_dump_dest='/u01/oracle/admin/shestate/bdump' *.core_dump_dest='/u01/oracle/admin/shestate/cdump' *.control_files='/u01/oradata/aux/control01.ctl' *.db_file_name_convert=('/dev','/u01/oradata/shestate') *.log_file_name_convert=('/dev','/u01/oradata/shestate') #*.log_archive_dest_1='/u01/oradata/archivelog' #*.log_archive_dest='/u01/oradata/archivelog'
|
Ø 测试库创建PASSWORD文件ORAPWSHESTATE
orapwd=$ORACLE_HOME/dbs/orapwshestate password=xxxxxxx(与目标数据库SYS密码相同) entries=2;
|
Ø 测试库创建LISTENER监听器、TNS网络配置文件.
配置监听器:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.40.203)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = /u01/oracle/product/9.2.0)
(SID_NAME = shestate)
)
)
TNS配置:
RMAN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.41.128)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = rman)
)
)
shestate =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =172.16.40.203)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAMAE = shestate)
(SID = shestate)
)
)
Ø RESTORE数据库
$ export ORACLE_SID=shestate
$ rman target / nocatalog
Recovery Manager: Release 9.2.0.5.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database (not started)
RMAN> set dbid=3563853082
executing command: SET DBID
RMAN> startup nomount;
Oracle instance started
Total System Global Area 1411877936 bytes
Fixed Size 744496 bytes
Variable Size 1358954496 bytes
Database Buffers 50331648 bytes
Redo Buffers 1847296 bytes
RMAN> alter database mount;
database mounted
RMAN> run
2> {
3> allocate channel t1 type 'SBT_TAPE';
4> restore database;
5> release channel t1;
6> }
allocated channel: t1
channel t1: sid=11 devtype=SBT_TAPE
channel t1: Data Protection for Oracle: version 5.4.1.0
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.40.203)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = /u01/oracle/product/9.2.0)
(SID_NAME = shestate)
)
)
RMAN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.41.128)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = rman)
)
)
shestate =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =172.16.40.203)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAMAE = shestate)
(SID = shestate)
)
)
$ export ORACLE_SID=shestate
$ rman target / nocatalog
Recovery Manager: Release 9.2.0.5.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database (not started)
RMAN> set dbid=3563853082
executing command: SET DBID
RMAN> startup nomount;
Oracle instance started
Total System Global Area 1411877936 bytes
Fixed Size 744496 bytes
Variable Size 1358954496 bytes
Database Buffers 50331648 bytes
Redo Buffers 1847296 bytes
RMAN> alter database mount;
database mounted
RMAN> run
2> {
3> allocate channel t1 type 'SBT_TAPE';
4> restore database;
5> release channel t1;
6> }
allocated channel: t1
channel t1: sid=11 devtype=SBT_TAPE
channel t1: Data Protection for Oracle: version 5.4.1.0
restore数据库成功完成,需要注意的是,上述的restore数据库到异机(测试库),测试库数据文件路径与目标数据库的数据文件是一致的,如果restore数据库到异机(测试库),而且测试库数据库文件的路径与目标数据库数据文件的路径是不一致,则需要set newname for 指定还原到不同的路径,例如:目标库数据文件源路径是/dev/rsh_data_01,异机(测试库)的数据文件路径为/u01/oradata/shestate,那么在rman run块里指定{ set newname for datafile ‘/dev/rsh_data_01’to ‘/u01/oradata/shestate/rsh_data_01’;} 。另外,因为restore数据库,只能在Mount状态下进行,如果连接到rman catalog数据库,那么,catalog数据库会认为是在连接目标库,目标库是open状态,会报错;所有,在测试库不需要连接rman catalog数据库,只需使用默认的nocatalog mode即可.
Ø 不完全恢复测试数据库
目前备份的控制文件以及数据库文件已经restore到测试库,使用rman备份集中restore出来的数据文件的头部信息SCN与控制文件的头部信息SCN是不一致的,但是可以使用所有的归档日志、联机重做日志完全恢复数据库,使数据库到达一致状态,从而OPEN打开数据库。但是在我们的测试库中只能做不完全恢复数据库,因为rman不备份联机重做日志文件.
还原部分归档日志文件,使数据库以OPEN RESETLOGS打开数据库。
$ rman target / catalog rman/rman@rman
Recovery Manager: Release 9.2.0.5.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database (not started)
connected to recovery catalog database
RMAN> set dbid=3563853082
executing command: SET DBID
RMAN> startup nomount;
Oracle instance started
Total System Global Area 1411877936 bytes
Fixed Size 744496 bytes
Variable Size 1358954496 bytes
Database Buffers 50331648 bytes
Redo Buffers 1847296 bytes
RMAN> alter database mount;
database mounted
RMAN> run
{
allocate channel t1 type 'SBT_TAPE';
set archivelog destination to '/archivelog';
restore archivelog from sequence 150017 until sequence 150022 thread 1;
restore archivelog from sequence 108607 until sequence 108612 thread 2;
release channel t1;
}
2> 3> 4> 5> 6> 7> 8>
allocated channel: t1
channel t1: sid=11 devtype=SBT_TAPE
channel t1: Data Protection for Oracle: version 5.4.1.0
executing command: SET ARCHIVELOG DESTINATION
Starting restore at 25-NOV-12
channel t1: starting archive log restore to user-specified destination
archive log destination=/archivelog
channel t1: restoring archive log
archive log thread=1 sequence=150017
channel t1: restoring archive log
archive log thread=1 sequence=150018
channel t1: restoring archive log
archive log thread=1 sequence=150019
channel t1: restoring archive log
archive log thread=1 sequence=150020
channel t1: restoring archive log
archive log thread=1 sequence=150021
不完全恢复数据库:
$ sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.5.0 - Production on Sun Nov 25 21:20:39 2012
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 30534322860 generated at 11/17/2012 02:16:24 needed for
thread 2
ORA-00289: suggestion : /archivelog/2_108619.dbf
ORA-00280: change 30534322860 for thread 2 is in sequence #108619
ORA-00279: change 30536463151 generated at 11/17/2012 13:43:32 needed for
thread 2
ORA-00289: suggestion : /archivelog/2_108630.dbf
ORA-00280: change 30536463151 for thread 2 is in sequence #108630
ORA-00278: log file '/archivelog/2_108629.dbf' no longer needed for this
recovery
ORA-00279: change 30536514214 generated at 11/17/2012 14:14:03 needed for
thread 1
ORA-00289: suggestion : /archivelog/1_150033.dbf
ORA-00280: change 30536514214 for thread 1 is in sequence #150033
ORA-00278: log file '/archivelog/1_150032.dbf' no longer needed for this
recovery
ORA-00279: change 30536560917 generated at 11/17/2012 14:44:07 needed for
thread 1
ORA-00289: suggestion : /archivelog/1_150034.dbf
ORA-00280: change 30536560917 for thread 1 is in sequence #150034
ORA-00278: log file '/archivelog/1_150033.dbf' no longer needed for this
recovery
ORA-00308: cannot open archived log '/archivelog/1_150034.dbf'
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3
SQL> SQL>
Ø 以 resetlogs打开测试数据库
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00344: unable to re-create online log '/dev/rsh_redo1_01'
$ rman target / catalog rman/rman@rman
Recovery Manager: Release 9.2.0.5.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database (not started)
connected to recovery catalog database
RMAN> set dbid=3563853082
executing command: SET DBID
RMAN> startup nomount;
Oracle instance started
Total System Global Area 1411877936 bytes
Fixed Size 744496 bytes
Variable Size 1358954496 bytes
Database Buffers 50331648 bytes
Redo Buffers 1847296 bytes
RMAN> alter database mount;
database mounted
RMAN> run
{
allocate channel t1 type 'SBT_TAPE';
set archivelog destination to '/archivelog';
restore archivelog from sequence 150017 until sequence 150022 thread 1;
restore archivelog from sequence 108607 until sequence 108612 thread 2;
release channel t1;
}
2> 3> 4> 5> 6> 7> 8>
allocated channel: t1
channel t1: sid=11 devtype=SBT_TAPE
channel t1: Data Protection for Oracle: version 5.4.1.0
executing command: SET ARCHIVELOG DESTINATION
Starting restore at 25-NOV-12
channel t1: starting archive log restore to user-specified destination
archive log destination=/archivelog
channel t1: restoring archive log
archive log thread=1 sequence=150017
channel t1: restoring archive log
archive log thread=1 sequence=150018
channel t1: restoring archive log
archive log thread=1 sequence=150019
channel t1: restoring archive log
archive log thread=1 sequence=150020
channel t1: restoring archive log
archive log thread=1 sequence=150021
$ sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.5.0 - Production on Sun Nov 25 21:20:39 2012
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 30534322860 generated at 11/17/2012 02:16:24 needed for
thread 2
ORA-00289: suggestion : /archivelog/2_108619.dbf
ORA-00280: change 30534322860 for thread 2 is in sequence #108619
ORA-00279: change 30536463151 generated at 11/17/2012 13:43:32 needed for
thread 2
ORA-00289: suggestion : /archivelog/2_108630.dbf
ORA-00280: change 30536463151 for thread 2 is in sequence #108630
ORA-00278: log file '/archivelog/2_108629.dbf' no longer needed for this
recovery
ORA-00279: change 30536514214 generated at 11/17/2012 14:14:03 needed for
thread 1
ORA-00289: suggestion : /archivelog/1_150033.dbf
ORA-00280: change 30536514214 for thread 1 is in sequence #150033
ORA-00278: log file '/archivelog/1_150032.dbf' no longer needed for this
recovery
ORA-00279: change 30536560917 generated at 11/17/2012 14:44:07 needed for
thread 1
ORA-00289: suggestion : /archivelog/1_150034.dbf
ORA-00280: change 30536560917 for thread 1 is in sequence #150034
ORA-00278: log file '/archivelog/1_150033.dbf' no longer needed for this
recovery
ORA-00308: cannot open archived log '/archivelog/1_150034.dbf'
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3
SQL> SQL>
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00344: unable to re-create online log '/dev/rsh_redo1_01'
报错的原因是,测试库联机重做日志逻辑卷LV没有建立,建立联机重做日志逻辑卷LV,数据库在open的时候将自动创建联机重做日志文件,注册到控制文件。
如果测试库日志文件是文件系统,则需要进行rename file,修改控制文件的注册信息:
SQL>alter database rename file '/dev/rwsw_redo1_21' to '/u01/oradata/retc/rwsw_redo1_21';
SQL>alter database rename file '/dev/rwsw_redo1_22' to '/u01/oradata/retc/rwsw_redo1_22';
然后打开数据库:
SQL> alter database open resetlogs;
Database altered.