oracle rman 异机恢复pitr的具体步骤
rman 使用备份集进行异机还原、恢复。大家应该清楚还原和恢复的差异。
$ rman target /
/*
测试用,发现测试失败,如果需要还原spfile时就很有用
没有参数文件,在RMAN的命令下会生成一个DUMMY的实例
RMAN> set dbid=1234567890;
*/
启动数据库到nomunt状态
RMAN> startup nomount pfile='/ebsfs/EBSPROD2/db/tech_st/11.2.0/dbs/initEBSPROD.ora';
还原控制文件
RMAN> run {
ALLOCATE CHANNEL ch00 TYPE disk;
restore controlfile to '/ebsfs/EBSPROD2/db/apps_st/data/cntrl01.dbf' from '/ebstar/ebsclonetar2/CTL_c-xxxxxxxx-04';
restore controlfile to '/ebsfs/EBSPROD2/db/apps_st/data/cntrl02.dbf' from '/ebstar/ebsclonetar2/CTL_c-xxxxxxxx-04';
restore controlfile to '/ebsfs/EBSPROD2/db/apps_st/data/cntrl03.dbf' from '/ebstar/ebsclonetar2/CTL_c-xxxxxxxx-04';
RELEASE CHANNEL ch00;
}
修改数据库到mount状态
RMAN> alter database mount;
效验备份集
RMAN> crosscheck backupset;
删除备份集
RMAN> delete expired backup;
注册本地目录,一定要最后一个’/’
RMAN>catalog start with '/ebstar/ebsclonetar2/';
做还原的检查
RMAN> run{
ALLOCATE CHANNEL ch00 TYPE disk;
restore database preview summary;
RELEASE CHANNEL ch00;
}
Media recovery start SCN is xxxxxxxx
Recovery must be done beyond SCN xxxxxxxx to clear datafile fuzziness
Finished restore at xx-xxx-xx
released channel: ch00
新开一个shell会话,拼接还原SQL
$ Sqlplus /nolog
SQL> conn / as sysdba;
Connected.
SQL> set lines 500;
SQL> set pages 500;
SQL> select 'set newname for datafile '''||dd.name||''' to '''||replace(replace(dd.name,'/EBSPROD/','/EBSPROD2/'),'/ebsfs2/','/ebsfs/')||''';' as set_dbname
from v$datafile dd
where 1=1
order by dd.name
;
还原数据库,一般开4个channel是比较快了。如果io不错,可以开6个、8个channel试试。
把上面输出的语句粘贴到下面 ———- 处
RMAN> run{
ALLOCATE CHANNEL ch00 TYPE disk;
ALLOCATE CHANNEL ch01 TYPE disk;
ALLOCATE CHANNEL ch02 TYPE disk;
ALLOCATE CHANNEL ch03 TYPE disk;
----------
----------
restore database;
switch datafile all;
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
RELEASE CHANNEL ch02;
RELEASE CHANNEL ch03;
}
尽可能多的应用归档,切记不要贸然打开数据库
RMAN> run{
ALLOCATE CHANNEL ch00 TYPE disk;
recover database ;
RELEASE CHANNEL ch00;
}
或者指定一个时间点
RMAN> run{
ALLOCATE CHANNEL ch00 TYPE disk;
set until time "to_date('2006-12-01 15:00:00','yyyy-mm-dd hh24:mi:ss')";
recover database ;
RELEASE CHANNEL ch00;
}
结束后会报一个ora错误提示无法找到指定的归档文件
这时可以从源库拷贝生成的归档文件
再次注册本地目录,一定要最后一个’/’
RMAN> catalog start with '/ebstar/ebsclonetar2/';
RMAN> list backup summary;
RMAN> list backup ;
再次恢复数据库
RMAN> run{
ALLOCATE CHANNEL ch00 TYPE disk;
recover database ;
RELEASE CHANNEL ch00;
}
新开一个sqlplus会话,修改文件
sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Mon Feb 24 09:34:38 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn / as sysdba;
Connected.
SQL> select instance_name,status from v$instance;
SQL> set lines 500;
SQL> set pages 500;
SQL> select 'alter database rename file '''||dd.file_name||''' to '''||replace(replace(dd.file_name,'/EBSPROD/','/EBSPROD2/'),'/ebsfs2/','/ebsfs/') ||''';' as alter_tmpname
from (
select name as file_name from v$tempfile
union all
select member as file_name from v$logfile l
) dd
Order by dd.file_name
拷出来执行就行了
打开数据库
SQL> select instance_name,status from v$instance;
SQL> alter database open resetlogs;
调整TEMP 表空间
select 'alter database tempfile '''||dtf.file_name||''' autoextend on next 100m maxsize 30g; ', dtf.*
from dba_temp_files dtf
where 1=1
;
关闭数据库的归档模式
如果源数据库是RAC,目标恢复机是单实例的话还需要做如下操作
禁止thread
SQL> select thread#,status,enabled from v$thread;
SQL> alter database disable thread 2;
删除被禁止thread 的 logfile group
SQL> select group#,thread#,archived,status from v$log;
SQL> alter database clear unarchived logfile group 5;
SQL> alter database drop logfile group 5;
清除多余的undo
SQL> select name from v$tablespace where name like 'UNDO%';
SQL> show parameter undo_tablespace;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
SQL> drop tablespace undotbs2 including contents and datafiles;
Tablespace dropped.
再检查tnsnames.ora 及 listener.ora