为了加深对RMAN的理解, 今天做了下对数据恢复的实验. 手上有两台RedHat虚拟环境. 目的是用rman把一台机器的数据库恢复到另外一台上. 以下记录了实验中的步骤:
1. 实验环境( 两台数据库环境一致 )
-- Database 10g Enterprise Edition Release 10.2.0.2.0 for Linux
-- Rman没有使用catalog
2. 备份源数据库环境
rman target / -- 记录DBID "connected to target database: HARRY (DBID=2188061810)"
RMAN> show all; -- 查看当前RMAN设置
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> sql 'alter system archive log current';
RMAN> backup database plus archivelog delete input;
RMAN> list backup;
-- 查看backupset信息, 获得以下内容
-- Piece Name: /storage/ora_recover/harry/HARRY/backupset/2009_07_28/o1_mf_nnndf_TAG20090728T201229_56yhwfyc_.bkp 包含数据文件
-- Piece Name: /storage/ora_recover/harry/HARRY/backupset/2009_07_28/o1_mf_annnn_TAG20090728T204927_56yl1s3x_.bkp 包含归档文件
-- Piece Name: /storage/ora_recover/harry/HARRY/autobackup/2009_07_28/o1_mf_s_693434970_56yl1v12_.bkp 包含自动备份的controlfile和spfile文件
3. 上传文件到目标数据库
scp o1_mf_nnndf_TAG20090728T201229_56yhwfyc_.bkp oracle@HOSTIP:/storage/ora_data/temp
..........
.........
4. 登录目标数据库, 恢复spfile
export ORACLE_SID=harry -- 和源数据库SID一致
rman target /
RMAN> set DBID 2188061810 --和源数据库一致( 因为在后面指定恢复文件, 这个参数也可以不设置 )
RMAN> startup nomount;
RMAN> run{
restore spfile to pfile '/storage/ora_data/temp/initharry.ora' from '/storage/ora_data/temp/o1_mf_s_693434970_56yl1v12_.bkp;
shutdown abort;
}
-- 打开initharry.ora, 修改相关参数, 比如controlfile, online log的路径等. 使其这些参数符合目标数据库环境
5. 登录目标数据库, 恢复controlfile
RMAN> startup force nomount pfile '/storage/ora_data/temp/initharry.ora';
RMAN> run{
restore controlfile from '/storage/ora_data/temp/o1_mf_s_693434970_56yl1v12_.bkp;
alter database mount;
}
6. 把备份信息加入目标数据库的RMAN中
RMAN> catalog backuppiece '/storage/ora_data/temp/o1_mf_nnndf_TAG20090728T201229_56yhwfyc_.bkp';
RMAN> catalog backuppiece '/storage/ora_data/temp/o1_mf_annnn_TAG20090728T204927_56yl1s3x_.bkp';
RMAN> list backup; -- 查看信息
7. 使用RMAN在目标环境中恢复数据库并打开
RMAN> restore database;
RMAN> recover database until sequence 4; --- sequence 设置参考archivelog在list backup的信息, 我的环境如下:
------------------------ Archived Log -------------------------------------
List of Archived Logs in backup set 36
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 1 726612 28-JUL-09 726957 28-JUL-09
1 2 726957 28-JUL-09 726963 28-JUL-09
1 3 726963 28-JUL-09 727024 28-JUL-09
1 4 727024 28-JUL-09 727034 28-JUL-09
------------------------ Archived Log -------------------------------------
RMAN> alter database open resetlogs;
-- Note: 因为online log不能备份, 是没有恢复online log的步骤的. 所以在目标数据库上online log文件是不存在的. 但, 在open时, 这些online log文件会被自动创建(设置了db_creaet_file_dest参数), 可以在alert log中查看到. 列举部分log信息如下:
------------------------------------- alert log information -------------------------------------------------
Errors in file /opt/app/oracle/admin/harry/udump/harry_ora_16910.trc:
ORA-00313: open failed for members of log group 4 of thread 1
ORA-00312: online log 4 thread 1: '/opt/app/oracle/oradata/HARRY/onlinelog/o1_mf_4_562fd6vl_.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-00312: online log 4 thread 1: '/storage/ora_data/HARRY/onlinelog/o1_mf_4_562fd5pr_.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Sat Aug 8 01:12:50 2009
Deleted Oracle managed file /storage/ora_data/HARRY/onlinelog/o1_mf_4_562fd5pr_.log
Deleted Oracle managed file /opt/app/oracle/oradata/HARRY/onlinelog/o1_mf_4_562fd6vl_.log
Sat Aug 8 01:13:01 2009
Setting recovery target incarnation to 4
Sat Aug 8 01:13:02 2009
Assigning activation ID 2189896278 (0x82872a56)
LGWR: STARTING ARCH PROCESSES
ARC0 started with pid=16, OS id=16935
Sat Aug 8 01:13:02 2009
ARC0: Archival started
ARC1: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC1 started with pid=20, OS id=16937
Sat Aug 8 01:13:04 2009
Thread 1 opened at log sequence 1
Current log# 3 seq# 1 mem# 0: /storage/ora_data/HARRY/onlinelog/o1_mf_3_57rr4gqv_.log
Current log# 3 seq# 1 mem# 1: /opt/app/oracle/oradata/HARRY/onlinelog/o1_mf_3_57rr4j2w_.log
Successful open of redo thread 1
------------------------------------- alert log information -------------------------------------------------
至此, 完成在目标数据库环境的恢复过程, 简单测试, 数据库运行正常. 相关步骤可以参考Backup and Recovery Advanced User's Guide.pdf charpter 7.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7319061/viewspace-1025050/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7319061/viewspace-1025050/