1.从源库生成spfile文件,并拷贝到目标库
sqlplus '/as sysdba'
create pfile='/oracle/tmp/pfile_dbname1_20130319.ora' from spfile;
2.目标库使用源库的pfile文件,去掉相关参数,打开数据库到nomount状态
export ORACLE_SID=dbname1
sqlplus '/as sysdba'
startup nomount pfile='/oradata/dbname/pfile_dbname1_20130319.ora'
3.查看备份集,确定控制文件
bplist -t 4 -C db1 -l -R / |more
/c-3869497698-20130317-01
4.还原控制文件
rman target /
set dbid=3869497698
run {
allocate channel ch1 device type sbt parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db1)';
restore controlfile from '/c-3869497698-20130317-01';
}
sql ' alter database mount'
5.检查恢复的表所在的表空间
SELECT * FROM dba_segments C WHERE C.segment_name='T_WFE_TEMPLATE';
TBS_dbname_WF_DAT
6.设置还原后的文件路径,使用脚本还原数据库(核心表空间和必需的业务空间)
select 'set newname for datafile ''' || d.file_name || ''' to ''/oradata/dbname/' || replace(file_name, '/dev/', '') || ''';',
d.tablespace_name
from dba_data_files d
where d.tablespace_name in
('SYSTEM', 'UNDOTBS1', 'UNDOTBS2', 'TBS_dbname_WF_DAT')
order by 2;
$ vi rman_dbname1_restore.sh
export ORACLE_SID=dbname1
CMD_STR_SYS="
rman target / log=/oradata/dbname/rman_dbname1_restore.log << eof
run {
allocate channel ch1 type 'sbt' parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db1)';
allocate channel ch2 type 'sbt' parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db2)';
set newname for datafile '/dev/rvg01_system_2g' to '/oradata/dbname/rvg01_system_2g';
set newname for datafile '/dev/rvg01_4g_01' to '/oradata/dbname/rvg01_4g_01';
set newname for datafile '/dev/rvg01_4g_02' to '/oradata/dbname/rvg01_4g_02';
set newname for datafile '/dev/rvg01_4g_03' to '/oradata/dbname/rvg01_4g_03';
set newname for datafile '/dev/rvg01_4g_04' to '/oradata/dbname/rvg01_4g_04';
set newname for datafile '/dev/rvg01_4g_05' to '/oradata/dbname/rvg01_4g_05';
set newname for datafile '/dev/rvg01_4g_06' to '/oradata/dbname/rvg01_4g_06';
set newname for datafile '/dev/rlv_db04_4g_003' to '/oradata/dbname/rlv_db04_4g_003';
set newname for datafile '/dev/rvg03_4g_30' to '/oradata/dbname/rvg03_4g_30';
set newname for datafile '/dev/rlv_db05_4g_027' to '/oradata/dbname/rlv_db05_4g_027';
set newname for datafile '/dev/rlv_db05_4g_013' to '/oradata/dbname/rlv_db05_4g_013';
set newname for datafile '/dev/rlv_db05_4g_016' to '/oradata/dbname/rlv_db05_4g_016';
set newname for datafile '/dev/rlv_db05_4g_023' to '/oradata/dbname/rlv_db05_4g_023';
set newname for datafile '/dev/rlv_db05_10g_007' to '/oradata/dbname/rlv_db05_10g_007';
set newname for datafile '/dev/rlv_db06_10g_006' to '/oradata/dbname/rlv_db06_10g_006';
set newname for datafile '/dev/rlv_db06_10g_009' to '/oradata/dbname/rlv_db06_10g_009';
set newname for datafile '/dev/rlv_db06_4g_031' to '/oradata/dbname/rlv_db06_4g_031';
set newname for datafile '/dev/rlv_db06_10g_023' to '/oradata/dbname/rlv_db06_10g_023';
set newname for datafile '/dev/rlv_db06_4g_039' to '/oradata/dbname/rlv_db06_4g_039';
set newname for datafile '/dev/rlv_db06_4g_040' to '/oradata/dbname/rlv_db06_4g_040';
set newname for datafile '/dev/rlv_db06_4g_041' to '/oradata/dbname/rlv_db06_4g_041';
set newname for datafile '/dev/rlv_db07_10g_07' to '/oradata/dbname/rlv_db07_10g_07';
set newname for datafile '/dev/rlv_db07_10g_23' to '/oradata/dbname/rlv_db07_10g_23';
set newname for datafile '/dev/rvg02_undo_30g_1' to '/oradata/dbname/rvg02_undo_30g_1';
set newname for datafile '/dev/rvg02_undo_30g_2' to '/oradata/dbname/rvg02_undo_30g_2';
restore tablespace system,UNDOTBS1,UNDOTBS2,TBS_dbname_WF_DAT;
switch datafile all;
}
exit
eof
"
sh -c "$CMD_STR_SYS" >> /oradata/dbname/rman_dbname1_restore.log &
$ nohup sh rman_dbname1_restore.sh &
$ tail -50f rman_dbname1_restore.out
7.设置redo的路径
select 'alter database rename file ''' || d.MEMBER || ''' to ''/oradata/dbname/' || replace(d.MEMBER, '/dev/', '') || ''';' sSQL
from v$logfile d
sqlplus '/as sysdba'
alter database rename file '/dev/rvg01_redo11_512' to '/oradata/dbname/rvg01_redo11_512';
alter database rename file '/dev/rvg02_redo21_512' to '/oradata/dbname/rvg02_redo21_512';
alter database rename file '/dev/rvg01_redo12_512' to '/oradata/dbname/rvg01_redo12_512';
alter database rename file '/dev/rvg02_redo22_512' to '/oradata/dbname/rvg02_redo22_512';
alter database rename file '/dev/rvg01_redo13_512' to '/oradata/dbname/rvg01_redo13_512';
alter database rename file '/dev/rvg02_redo23_512' to '/oradata/dbname/rvg02_redo23_512';
alter database rename file '/dev/rvg01_redo14_512' to '/oradata/dbname/rvg01_redo14_512';
alter database rename file '/dev/rvg02_redo24_512' to '/oradata/dbname/rvg02_redo24_512';
8.恢复数据库到制定的时间点,并skip掉不需要的表空间
$ vi rman_dbname1_recover.sh
CMD_STR_RECOVER="
rman target / log=/oradata/dbname/rman_dbname1_recover.log << eof
run {
allocate channel ch1 type 'sbt' parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db1)';
allocate channel ch2 type 'sbt' parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db2)';
set until time \"TO_DATE('2013-03-15 03:00:00','YYYY-MM-DD HH24:MI:SS')\";
recover database skip forever tablespace 'PERFSTAT','PRECISE_OR_TAB','TBS_dbname_BS_DAT','TBS_dbname_BS_HISDAT','TBS_dbname_BS_HISIDX','TBS_dbname_BS_IDX','TBS_dbname_BS_TEMP','TBS_dbname_ESALES_DAT','TBS_dbname_ESALES_HISDAT','TBS_dbname_ESALES_IDX','TBS_dbname_ESALES_LOGDAT','TBS_dbname_ESALES_LOGIDX','TBS_dbname_MKT_DAT','TBS_dbname_MKT_HISDAT','TBS_dbname_MKT_HISIDX','TBS_dbname_MKT_IDX','TBS_dbname_RPT_DAT','TBS_dbname_RPT_IDX','TBS_dbname_WF_HISDAT','TBS_dbname_WF_HISIDX','TBS_dbname_WF_IDX','TBS_dbname_WF_TEMP','TS_IDX_KFMAIN_dbname_01','TS_TAB_KFMAIN_dbname_01','TS_TAB_VERITAS_DATA','USERS';
RELEASE CHANNEL ch1;
RELEASE CHANNEL ch2;
}
exit
eof
"
sh -c "$CMD_STR_RECOVER" >> /oradata/dbname/rman_dbname1_recover.log
9.根据还原的时间点和恢复的截止时间点,查看需要多少归档文件
select * from v$log_history d where d.FIRST_TIME> Date'2013-03-14'+23/24 and d.FIRST_TIME< Date'2013-3-16'
10.打开数据库,并查询需要恢复的标的数据
sqlplus '/as sysdba'
alter database open resetlogs
select count(*) from icdwf.t_wfe_template;
11.生成logminer的相关包和视图
@?/rdbms/admin/dbmslm.sql
@?/rdbms/admin/dbmslmd.sql
12.还原logminer需要的归档文件(此处需要使用open之前的控制文件来mount数据库,需要做好备份)
startup mount pfile='/oracle/dbname/archlog01/pfile_dbname1_20130319_arc.ora';
--恢复归档
run {
allocate channel ch1 type 'sbt' parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db1)';
restore archivelog from logseq 48041 until logseq 48045 thread 1;
}
run {
allocate channel ch1 type 'sbt' parms='ENV=(NB_ORA_SERV=bakserver,NB_ORA_CLIENT=db2)';
restore archivelog from logseq 64951 until logseq 64960 thread 2;
}
--添加数据字典文件
alter system set utl_file_dir='/oradata/dbname/logminer' scope=spifle;
begin
sys.dbms_logmnr_d.build(dictionary_filename=>'dictionary.ora', dictionary_location =>'/oradata/dbname/logminer');
end;
--添加日志文件
begin
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname1_s0000048041.arc',options=>sys.dbms_logmnr.new);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname1_s0000048042.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname1_s0000048043.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname1_s0000048044.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname1_s0000048045.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064951.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064952.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064953.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064954.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064955.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064956.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064957.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064958.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064959.arc',options=>sys.dbms_logmnr.addfile);
sys.dbms_logmnr.add_logfile(logfilename=>'/oradata/dbname/archlog01/kfdbname2_s0000064960.arc',options=>sys.dbms_logmnr.addfile);
end;
select db_name, thread_sqn,filename from v$logmnr_logs;
--开始挖掘
begin
sys.dbms_logmnr.start_logmnr(dictfilename => '/oradata/dbname/logminer/dictionary.ora');
end;
//exec dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);
--查询挖掘表的相关信息
create table TRANS_OBJECT_T_WFE_TEMPLATE tablespace TBS_dbname_WF_DAT as
select /*+parallel(t,20)*/* from v$logmnr_contents t
where t.SEG_NAME like '%T_WFE_TEMPLATE%'
--结束挖掘
EXECUTE DBMS_LOGMNR.END_LOGMNR