RMAN备份恢复系列1: Oracle 10g rac asm数据库恢复到10g单实例数据库



Oracle 10grac asm数据库恢复到10g单实例数据库

环境:

数据库版本:10201

1.源端数据库:oracle 10g RAC ASM datbase

2.目标数据库:oracle 10g single Filesystem  datbase

 

1参数文件的恢复

按日志sequence号备份部分归档日志

BACKUP ARCHIVELOGFROM SEQUENCE 20035UNTILSEQUENCE 20035 thread1 format '/oradata/rman/log_%U';


1.1.恢复参数文件
[oracle@ora10g ~]$rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Mar 11 00:17:30 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database (not started)

RMAN> startup nomount;

RMAN> restore spfile to pfile "/u01/oracle/yd.ora"from "/u01/rmanbak/c-2562551067-20130310-00";


 

1.2.创建相关目录
[oracle@ora10g admin]$ mkdir -p /u01/oracle/admin/oradb/udump
[oracle@ora10g admin]$ mkdir -p /u01/oracle/admin/oradb/cdump
[oracle@ora10g admin]$ mkdir -p /u01/oracle/admin/oradb/bdump
[oracle@ora10g admin]$ mkdir -p /u01/oracle/admin/oradb/adump
[oracle@ora10g admin]$ mkdir -p /u01/oracle/admin/oradb/pfile
[oracle@ora10g admin]$ mkdir -p /u01/oracle/oradb

 

 

1.3.修改备库参数文件

-----这里修改的参数要根据1.2中创建的目录来修改
more yd.ora

*.audit_file_dest
='/u01/oracle/admin/oradb/adump'
*.background_dump_dest='/u01/oracle/admin/oradb/bdump'

*.core_dump_dest='/u01/oracle/admin/oradb/cdump'

*.user_dump_dest='/u01/oracle/admin/oradb/udump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/oracle/oradata/oradb/control01.ctl','/u01/oracle/oradata/oradb/control02.ctl','/u01/oracle/o
radata/oradb/control03.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='oradb'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=54371840
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=185212672
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'




1.4.
创建备库spfile文件
[oracle@ora10g oracle]$ sqlplus "/as sysdba"

SQL> create spfile from pfile='/u01/oracle/yd.ora';
File created.

SQL> create pfile from spfile;
File created.

 

 


2.恢复控制文件
2.1.从备份集中恢复controlfile

$export ORACLE_SID=XXXX --------------XXXX为要恢复数据库的实例名


[oracle@ora10g oracle]$ sqlplus "/as sysdba"



SQL> startup nomount;


oracle@ora10g ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Mar 11 00:26:36 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: oradb (not mounted)

RMAN> set dbid=2562551067
executing command: SET DBID

RMAN> restore controlfile from'/u01/rmanbak/c-2562551067-20130310-00';---
控制文件的路径有init.ora参数文件来决定

RMAN> restore controlfile from '/u01/rmanbak/c-2562551067-20130310-00';



RMAN>
alter database mount;
database mounted
released channel: ORA_DISK_1


2.2.注册rman备份集到控制文件

catalog start with '/u01/rmanbak';

RMAN>
catalog start with '/u01/rmanbak';


3.查看控制文件内容

set line 100   
col NAME for a80
col MEMBER for a80
select file#,status,name from v$datafile
  union all
  select group#,status,member from v$logfile
  union all
  select file#,status,name from v$tempfile;


SQL> set line 100   
SQL> col NAME for a80
SQL> col MEMBER for a80
SQL> select file#,status,name from v$datafile
      union all
     select group#,status,member from v$logfile
      union all
   select file#,status,name from v$tempfile;

      


4.数据库恢复

4.1.restore数据文件和临时数据文件

-----------这里需要将数据文件,temp文件的位置,路径按照在备库上预先规划的路径进行修改
run{
set newname for datafile 1 to '/u01/oracle/oradata/oradb/system01.dbf';
set newname for datafile 2 to'/u01/oracle/oradata/oradb/undotbs1.dbf';
set newname for datafile 3 to '/u01/oracle/oradata/oradb/sysaux01.dbf';
set newname for datafile 4 to '/u01/oracle/oradata/oradb/users01.dbf';
set newname for datafile 5 to '/u01/oracle/oradata/oradb/undotbs02.dbf';
set newname for datafile 6 to '/u01/oracle/oradata/oradb/ts1.dbf';
set newname for datafile 7 to '/u01/oracle/oradata/oradb/yd.dbf';
set newname for tempfile 1 to'/u01/oracle/oradata/oradb/temp01.dbf';
   
restore database;
    switch datafile all;
    switch tempfile all;

 }


RMAN>


--------
验证控制文件中数据文件,temp文件的位置,路径信息是否正确
SQL> select name from v$datafile;

SQL> select name from v$tempfile;


4.2.修改redo file的文件名

SQL> select GROUP#,MEMBER from v$logfile;
    GROUP# MEMBER
------------------------------------------------------------------------------------------
         2+ASMDG/oradb/onlinelog/group_2.262.809286305
         1+ASMDG/oradb/onlinelog/group_1.261.809286303
         3 +ASMDG/oradb/onlinelog/group_3.265.809286383
         4 +ASMDG/oradb/onlinelog/group_4.266.809286385


SQL>alter database rename file'+ASMDG/oradb/onlinelog/group_1.261.809286303'to '/u01/oracle/oradata/oradb/redo01.log';

Database altered.

SQL> alter database rename file'+ASMDG/oradb/onlinelog/group_2.262.809286305'to
'/u01/oracle/oradata/oradb/redo02.log';

Database altered.

SQL> alter database rename file '+ASMDG/oradb/onlinelog/group_3.265.809286383'to
'/u01/oracle/oradata/oradb/redo03.log';

Database altered.

SQL> alter database rename file '+ASMDG/oradb/onlinelog/group_4.266.809286385'to
'/u01/oracle/oradata/oradb/redo04.log';        

Database altered.

4.3. recover数据库
    
到这一步,datafiletempfileredolog都已经根据实际情况在controlfile中更新了。可以使用redolog,归档日志进行数据库的完全/不完全恢复


RMAN> recover database;

Starting recover at 11-MAR-13
using channel ORA_DISK_1
starting media recovery

channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=10
channel ORA_DISK_1: reading from backup piece/oracle/rmanbak/arch_07o46e51_ORADB_20130310
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/u01/rmanbak/arch_07o46e51_ORADB_20130310tag=TAG20130310T155616
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/oracle/product/10.2/dbs/arch1_10_809286303.dbfthread=1 sequence=10
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=2 sequence=9
channel ORA_DISK_1: reading from backup piece/oracle/rmanbak/arch_08o46e50_ORADB_20130310
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/u01/rmanbak/arch_08o46e50_ORADB_20130310tag=TAG20130310T155616
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/oracle/product/10.2/dbs/arch2_9_809286303.dbfthread=2 sequence=9
unable to find archive log
archive log thread=1 sequence=11
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/11/2013 00:39:45
RMAN-06054: media recovery requesting unknown log:thread 1 seq 11 lowscn 509191

RMAN>



SQL> set line 1000
SQL> select group#,thread#,sequence#,archived,status from v$log;
    GROUP#    THREAD#  SEQUENCE#  ARC  STATUS
----------     ----------     ----------   --- ----------------
        1         1               10      YES  INACTIVE
        2         1               11      NO   CURRENT
        3         2                9        YES  INACTIVE
        4         2               10      NO   CURRENT


4.4.使用resetlogs打开数据库

RMAN> alter database open resetlogs;

database opened

RMAN>

5.修正temp文件

SQL> col PROPERTY_NAME for a30
SQL> col DESCRIPTION for a50
SQL> col PROPERTY_VALUE for a20
SQL> select * from database_properties where property_value='TEMP';
PROPERTY_NAME                 PROPERTY_VALUE       DESCRIPTION
------------------------------ ----------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE       TEMP                Name of default temporary tablespace

 

SQL> select * from database_propertieswhere property_value='USERS';
PROPERTY_NAME                 PROPERTY_VALUE       DESCRIPTION
------------------------------ ----------------------------------------------------------------------
DEFAULT_PERMANENT_TABLESPACE  USERS               Name of default permanent tablespace


col FILE_NAME for a40
select tablespace_name,file_name,bytes/1024/1024 sizeM,AUTOEXTENSIBLE fromdba_temp_files;


SQL> select tablespace_name,file_name,bytes/1024/1024 sizeM,AUTOEXTENSIBLEfrom dba_temp_files;
TABLESPACE_NAME               FILE_NAME                                     SIZEM AUT
------------------------------ ----------------------------------------        -------------
TEMP                          /u01/oracle/oradata/oradb/temp01.dbf            20 YES


6.修正redo日志
SQL>  select THREAD#, STATUS, ENABLED from v$thread;

   THREAD# STATUS ENABLED
----------    ------ --------
         1   OPEN   PUBLIC
         2   CLOSED PUBLIC

SQL>
SQL>
SQL> alter database disable thread 2;

Database altered.

SQL>
SQL>  select THREAD#, STATUS, ENABLED from v$thread;

   THREAD# STATUS ENABLED
---------- ------ --------
         1 OPEN   PUBLIC
         2 CLOSED DISABLED


SQL> select group#,thread#,sequence#,archived,status from v$log;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------------
        1         1          0 YES UNUSED
        2         1          1 NO  CURRENT
        3         2          0 YES UNUSED
         4         2          1 NO  INACTIVE

SQL> -----
清理thread 2redolog group file
SQL> alter database drop logfile group 3;
Database altered.

SQL> alter database drop logfile group 4;
alter database drop logfile group 4
*
ERROR at line 1:
ORA-00350: log 4 of instance oradb2 (thread 2) needs to be archived
ORA-00312: online log 4 thread 2: '/u01/oracle/oradata/oradb/redo04.log'


SQL> alter database clear unarchived logfile group 4;
Database altered.

SQL> alter database drop logfile group 4;
Database altered.

----可以添加一组新的日志组
SQL> alter database add logfile group 3  '/u01/oracle/oradata/oradb/redo03.log'size 50m;
Database altered.

SQL> set linesize 300
SQL> l
   SELECT v$logfile.member,v$logfile.group#, v$log.status,v$log.ARCHIVED, v$log.bytes/1024/1024 ,v$log.thread#
   FROM v$log, v$logfile
    WHERE v$log.group# = v$logfile.group#
 ORDER BY v$log.thread#,v$logfile.group#
/

MEMBER                                      GROUP# STATUS           ARCV$LOG.BYTES/1024/1024    THREAD#
---------------------------------------- ---------- ---------------- ------------------------ ----------
/u01/oracle/oradata/oradb/redo01.log             1 UNUSED          YES                   50          1
/u01/oracle/oradata/oradb/redo02.log             2 CURRENT          NO                    50          1
/u01/oracle/oradata/oradb/redo03.log             3 UNUSED         NO                    50          1


SQL> archive log list;        
Database logmode             Archive Mode
Automaticarchival            Enabled
Archivedestination           /u01/oracle/product/10.2/dbs/arch
Oldest online log sequence     0
Next log sequence to archive   1
Current logsequence           1
SQL>
SQL>
SQL> alter system set log_archive_dest_1='location=/u01/oracle/archivelog';

System altered.

切换归档验证redo日志文件的可用性。


7.修正undo
SQL>
SQL>  select tablespace_name from dba_tablespaces wherecontents='UNDO';

TABLESPACE_NAME
------------------------------
UNDOTBS1
UNDOTBS2

SQL>
SQL> show parameter undo;

NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                     string      AUTO
undo_retention                      integer     900
undo_tablespace                     string      UNDOTBS1
SQL>
SQL>
SQL> drop tablespace UNDOTBS2 including contents and datafiles;

Tablespace dropped.

SQL> select tablespace_name from dba_tablespaces where contents='UNDO';

TABLESPACE_NAME
------------------------------
UNDOTBS1

8.验证
SQL> col name format a50
SQL>
select file#,status,fuzzy,checkpoint_change#,name fromv$datafile_header

     FILE# STATUS  FUZ CHECKPOINT_CHANGE# NAME
---------- ------- --- --------------------------------------------------------------------
         1 ONLINE  YES            509682 /u01/oracle/oradata/oradb/system01.dbf
         2 ONLINE YES            509682 /u01/oracle/oradata/oradb/undotbs1.dbf
         3 ONLINE YES            509682 /u01/oracle/oradata/oradb/sysaux01.dbf
         4 ONLINE YES             509682/u01/oracle/oradata/oradb/users01.dbf
         6 ONLINE YES            509682 /u01/oracle/oradata/oradb/ts1.dbf
         7 ONLINE YES            509682 /u01/oracle/oradata/oradb/yd.dbf

6 rows selected.


SQL>
select file#,status,checkpoint_change#,last_change#,namefrom v$datafile;

     FILE# STATUS  CHECKPOINT_CHANGE# LAST_CHANGE#NAME
---------- ------- ------------------ --------------------------------------------------------------
         1SYSTEM             509682             /u01/oracle/oradata/oradb/system01.dbf
         2ONLINE             509682             /u01/oracle/oradata/oradb/undotbs1.dbf
         3ONLINE             509682             /u01/oracle/oradata/oradb/sysaux01.dbf
         4 ONLINE             509682             /u01/oracle/oradata/oradb/users01.dbf
         6ONLINE             509682             /u01/oracle/oradata/oradb/ts1.dbf
         7ONLINE             509682             /u01/oracle/oradata/oradb/yd.dbf

6 rows selected.


SQL> conn test/test
Connected.
SQL>
SQL>  select count(*) from test;

  COUNT(*)
----------
     49781

SQL> conn yd/yd
Connected.
SQL> select count(*) from t1;

  COUNT(*)
----------

       14

=========================================================================
-- The End --

 

你可能感兴趣的:(RMAN备份恢复系列1: Oracle 10g rac asm数据库恢复到10g单实例数据库)