Heim >Datenbank >MySQL-Tutorial >Oracle数据库表空间级的异地不完全恢复

Oracle数据库表空间级的异地不完全恢复

WBOY
WBOYOriginal
2016-06-07 16:46:22982Durchsuche

Oracle 资料库做异地恢复时,全库的完全恢复需要很大的空间和很长的时间。 如果采用基于模式的恢复方式仅仅恢复某一模式下所有物

Oracle 资料库做异地恢复时,全库的完全恢复需要很大的空间和很长的时间。
如果采用基于模式的恢复方式仅仅恢复某一模式下所有物件,而不用去恢复所有的资料,这将节省大量的时间和空间。
这个在 Oracle 9i 版本中经常使用,在 10g 、 11g 中也可以使用一下。
下面案例是在 10g 的环境下将一个 ASM 上的 RAC 资料库的资料恢复到一个档案系统上单实例资料库中,并且是只恢复几个使用者下的资料。
操作步骤如下:
1 、将备份组拷贝到要恢复的机器上,如果空间够的话,可以将资料备份、控制档案备份和归档备份一起拷贝过来,如果不够的话,先拷贝控制档案备份和资料档案备份。
2 、关闭资料库,启动到 nomount 状态进行控制档的恢复
shutdown immediate;
startup nomount;
rman target /
restore controlfile from '/data/urpdb/urpdb_ctl_ikn3tot4_1_1.20120222';
3 、修改控制档
查询要恢复的使用者的表空间资讯
  select owner,tablespace_name,count(*) from dba_segments group by owner,tablespace_name;
查找这些表空间和系统表空间( 'SYSTEM','SYSAUX', 'UNDOTBS1','UNDOTBS2', 'UNDOTBS3', 'UNDOTBS4' )对应的资料档案
select *
  from dba_data_files
 where tablespace_name in
       ('TSP_URP', 'TSP_URP_INDEX', 'TSP_JC', 'TSP_JC_INDEX', 'TSP_GXSJ',
        'TSP_GXSJ_INDE', 'TSP_OWB', 'TSP_YJSSJCK', 'USERS', 'SYSTEM',
        'SYSAUX', 'UNDOTBS1','UNDOTBS2', 'UNDOTBS3', 'UNDOTBS4');
SQL> alter database backup controlfile to trace;
修改控制档并执行:
CREATE CONTROLFILE REUSE DATABASE "URPDB" RESETLOGS FORCE LOGGING ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 9088
LOGFILE
  GROUP 1 (
    '/opt/app/oracle/oradata/URPDB/group1_2.log',
    '/opt/app/oracle/oradata/URPDB/group1_1.log'
  ) SIZE 10M,
  GROUP 2 (
    '/opt/app/oracle/oradata/URPDB/group2_2.log',
    '/opt/app/oracle/oradata/URPDB/group2_1.log'
  ) SIZE 10M,
  GROUP 3 (
    '/opt/app/oracle/oradata/URPDB/group3_2.log',
    '/opt/app/oracle/oradata/URPDB/group3_1.log'
  ) SIZE 10M,
  GROUP 11 '/opt/app/oracle/oradata/URPDB/group11_1.log'  SIZE 100M,
  GROUP 12 '/opt/app/oracle/oradata/URPDB/group12_1.log'  SIZE 100M,
  GROUP 13 '/opt/app/oracle/oradata/URPDB/group13_1.log'  SIZE 100M,
  GROUP 14 '/opt/app/oracle/oradata/URPDB/group14_1.log'  SIZE 100M,
  GROUP 15 '/opt/app/oracle/oradata/URPDB/group15_1.log'  SIZE 100M
-- STANDBY LOGFILE
DATAFILE
  '/opt/app/oracle/oradata/URPDB/system01.dbf',
  '/opt/app/oracle/oradata/URPDB/undotbs1.dbf',
  '/opt/app/oracle/oradata/URPDB/sysaux.dbf',
  '/opt/app/oracle/oradata/URPDB/users.dbf',
  '/opt/app/oracle/oradata/URPDB/undotbs2.dbf',
  '/opt/app/oracle/oradata/URPDB/tsp_urp.dbf',
  '/opt/app/oracle/oradata/URPDB/tsp_urp_index.dbf',
  '/opt/app/oracle/oradata/URPDB/tsp_gxsj.dbf',
  '/opt/app/oracle/oradata/URPDB/tsp_urp.dbf_1.ora',
  '/opt/app/oracle/oradata/URPDB/tsp_owb.ora',
  '/opt/app/oracle/oradata/URPDB/tsp_jc.dbf',
  '/opt/app/oracle/oradata/URPDB/tsp_jc_index.dbf',
  '/opt/app/oracle/oradata/URPDB/tsp_yjssjck.dbf',
  '/opt/app/oracle/oradata/URPDB/undotbs03.dbf',
  '/opt/app/oracle/oradata/URPDB/undotbs04.dbf'
CHARACTER SET AL32UTF8
;
mount 资料库;
SQL> alter database mount;


select name from v$datafile;
--select 'alter database rename file '''||name||''' to '''|| replace(name,'+URPDBDG','/opt/app/oracle/oradata/URPDB')||''';' from  v$datafile;
3 、将备份资料档案拷贝到测试机
rman>catalog start with '/data/urpdb/';   执行一下,就是将这个目录下的资料档案的备份档案写入了 catalog 。
4 、 restore 资料库
select file#,name from v$datafile ; --- 看看控制档中资料档案存放的位置,,这里是 “ +URPDBDG/..." ,替换为目标资料库档存放的位置。
set linesize 300
column name format a200
set pagesize 100


select 'set newname for datafile '||file#||' to '''||replace(name,'+URPDBDG','/opt/app/oracle/oradata/urpdb')||''';' newname from v$datafile -- 如果一个目标目录不够,可以用多个目标目录
union all
select 'restore datafile '||file#||';' newname from v$datafile;


select *
  from dba_data_files
 where tablespace_name in
       ('TSP_URP', 'TSP_URP_INDEX', 'TSP_JC', 'TSP_JC_INDEX', 'TSP_GXSJ',
        'TSP_GXSJ_INDE', 'TSP_OWB', 'TSP_YJSSJCK', 'USERS', 'SYSTEM',
        'SYSAUX', 'UNDOTBS1','UNDOTBS2', 'UNDOTBS3', 'UNDOTBS4');


rman>
run
{
allocate channel ch01 type disk;
allocate channel ch02 type disk;
set until time "to_date('2012-02-23 10:00:00','yyyy-mm-dd hh24:mi:ss')";
set newname for datafile 1 to '/opt/app/oracle/oradata/URPDB/system01.dbf';
set newname for datafile 2 to '/opt/app/oracle/oradata/URPDB/undotbs1.dbf';
set newname for datafile 3 to '/opt/app/oracle/oradata/URPDB/sysaux.dbf';
set newname for datafile 4 to '/opt/app/oracle/oradata/URPDB/users.dbf';
set newname for datafile 6 to '/opt/app/oracle/oradata/URPDB/undotbs2.dbf';
set newname for datafile 9 to '/opt/app/oracle/oradata/URPDB/tsp_urp.dbf';
set newname for datafile 10 to '/opt/app/oracle/oradata/URPDB/tsp_urp_index.dbf';
set newname for datafile 14 to '/opt/app/oracle/oradata/URPDB/tsp_gxsj.dbf';
set newname for datafile 16 to '/opt/app/oracle/oradata/URPDB/tsp_urp.dbf_1.ora';
set newname for datafile 18 to '/opt/app/oracle/oradata/URPDB/tsp_owb.ora';
set newname for datafile 19 to '/opt/app/oracle/oradata/URPDB/tsp_jc.dbf';
set newname for datafile 20 to '/opt/app/oracle/oradata/URPDB/tsp_jc_index.dbf';
set newname for datafile 26 to '/opt/app/oracle/oradata/URPDB/tsp_yjssjck.dbf';
set newname for datafile 29 to '/opt/app/oracle/oradata/URPDB/undotbs03.dbf';
set newname for datafile 30 to '/opt/app/oracle/oradata/URPDB/undotbs04.dbf';
restore datafile 1;
restore datafile 2;
restore datafile 3;
restore datafile 4;
restore datafile 6;
restore datafile 9;
restore datafile 10;
restore datafile 14;
restore datafile 16;
restore datafile 18;
restore datafile 19;
restore datafile 20;
restore datafile 26;
restore datafile 29;
restore datafile 30;
switch datafile all;
release channel ch01;
release channel ch02;
}
5 、修改日志档和暂存档案的路径为目标资料库的路径(可与 restore 同时进行)
select member from v$logfile;


select name from v$tempfile;


select 'alter database rename file '''||member||''' to '''|| replace(member,'+URPDBDG','/opt/app/oracle/oradata/URPDB')||''';' from  v$logfile;


alter database rename file '+YWKDG/ywk/onlinelog/group15_1.log' to '/opt/app/oracle/oradata2/YWKDG/group15_1.log';
。。。。。


select 'alter database rename file '''||name||''' to '''|| replace(name,'+URPDBDG','/opt/app/oracle/oradata2/urpdb/')||''';' from  v$tempfile;


alter database rename file '+YWKDG/ywk/tempfile/tsp_zc_temp02.dbf' to  '/opt/app/oracle/oradata2/YWKDG/tsp_zc_temp02.dbf';

 


6 、将归档档拷到目标资料库伺服器,
rman>catalog start with '/data/urpdb/';   执行一下,就是将这个目录下的归档档的备份档案写入了 catalog 。
run
{
allocate channel ch01 type disk;
allocate channel ch02 type disk;
set until time "to_date('2012-02-23 10:00:00','yyyy-mm-dd hh24:mi:ss')";
recover database;
release channel ch01;
release channel ch02;
}
或则
SQL> select to_char(checkpoint_time,'yyyy-mm-dd hh24:mi:ss') from v$datafile;


S QL> select file#,checkpoint_change# from v$datafile order by checkpoint_change#;


     FILE# CHECKPOINT_CHANGE#
---------- ------------------
        14         2793109724
        20         2793109725
         6         2793232002
        19         2793232002
        18         2793258889
        26         2793258889
         9         2793281171
        30         2793281171
         1         2793283158
        16         2793301522
        29         2793301522
         2         2793304369
        10         2793304369
         4         2793333238
         3         2793333238


15 rows selected.


run
{
allocate channel ch01 type disk;
allocate channel ch02 type disk;
set until scn  2793333238;
recover database ;
release channel ch01;
release channel ch02;
}


如果 recover 资料库缺少档,可以到主库去查是哪个档,然后拷贝过来再 recover 一次。
RMAN> list backupset of archivelog logseq 7438 thread 4;


RMAN> crosscheck backupset;
delete expired backupset;


7 、 alter database open resetlogs;

更多Oracle相关信息见Oracle 专题页面 ?tid=12

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn