rman 异机恢复


1、源端:rman 备份

[oracle@node1 dbs]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jan 27 08:30:53 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: NODE1 (DBID=1752471044) --注意记住dbid

run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup  database format '/oradata/backup/full_%d_%T_%s_%p';
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup archivelog all format '/oradata/backup/arch_%d_%T_%s_%p';
backup current controlfile format '/oradata/backup/c_ctl_%d_%T_%s_%p';
}

2. 查看spfile所在备份的位置

RMAN> list backup of spfile;

List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
20      Full    80.00K     DISK        00:00:00     27-JAN-16      
        BP Key: 20   Status: AVAILABLE  Compressed: NO  Tag: TAG20160127T072041
        Piece Name: /oradata/backup/full_NODE1_20160127_22_1   --可以看到在这个文件里面
  SPFILE Included: Modification time: 25-JAN-16
  SPFILE db_unique_name: NODE1

3. scp rman备份到目标端
   
[oracle@node1 backup]$ scp * [email protected]:/oradata/backup

The authenticity of host '192.168.56.12 (192.168.56.12)' can't be established.
RSA key fingerprint is f4:26:86:52:23:76:4c:09:1b:b0:6d:32:a7:7a:0a:80.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.12' (RSA) to the list of known hosts.
[email protected]'s password: 
arch_NODE1_20160127_23_1                             100%   18MB  17.7MB/s   00:01    
arch_NODE1_20160127_24_1                             100%  168MB  28.1MB/s   00:06    
arch_NODE1_20160127_25_1                             100%  105MB  26.3MB/s   00:04    
c_ctl_NODE1_20160127_26_1                            100% 9664KB   9.4MB/s   00:00    
full_NODE1_20160127_19_1                             100%  198MB  13.2MB/s   00:15    
full_NODE1_20160127_20_1                             100%  112MB   7.5MB/s   00:15    
full_NODE1_20160127_21_1                             100% 9664KB   9.4MB/s   00:00    
full_NODE1_20160127_22_1                             100%   96KB  96.0KB/s   00:00    --spfile在这个文件里
[oracle@node1 backup]$ 


4. 创建各种dump目录

[oracle@node3 backup]$ export ORACLE_SID=node1
[oracle@node3 backup]$ env|grep SID
ORACLE_SID=node1


11g要创建这些目录

rm -rf $ORACLE_BASE/admin/$ORACLE_SID
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/dpdump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/pfile
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/scripts
chmod -R 750 $ORACLE_BASE/admin

rm -rf $ORACLE_BASE/diag/rdbms/$ORACLE_SID
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/alert 
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/cdump 
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/hm    
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/incident
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/incpkg
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/ir    
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/lck   
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/metadata
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/stage 
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/sweep 
mkdir -p $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace
chmod -R 750 $ORACLE_BASE/diag/rdbms/$ORACLE_SID 


5. 创建密码文件,直接copy过去也行

方法一:创建密码文件
cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ orapwd file=/u01/app/oracle/product/11.2.0.3/db_1/dbs/orapworcl password=oracle

方法二:copy密码文件
[oracle@node1 dbs]$ scp orapwnode1 [email protected]://u01/app/oracle/product/11.2.0/db_1/dbs
[email protected]'s password: 
orapwnode1                            100% 1536     1.5KB/s   00:00    
[oracle@node1 dbs]$ 

缺省情况下,win下口令文件的格式是pwdsid.ora,unix下的格式是orapwSID(大小写敏感)实例名区分大小写,库名不区分大小写


6. 恢复
[oracle@node3 dbs]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Feb 4 19:27:58 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database (not started)

RMAN> set DBID=1752471044  --设置dbid
executing command: SET DBID

RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initnode1.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                281019272 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5517312 bytes

注意:在rman下即使没有参数文件,默认也会启动一个DUMMY实例,以便能够恢复参数文件。

7.恢复参数文件

RMAN> restore spfile from '//oradata/backup/full_NODE1_20160127_22_1';

Starting restore at 04-FEB-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP //oradata/backup/full_NODE1_20160127_22_1
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 04-FEB-16

8.强制启动到nomount状态

RMAN> startup force nomount;
Oracle instance started

Total System Global Area     839282688 bytes

Fixed Size                     2257880 bytes
Variable Size                494930984 bytes
Database Buffers             339738624 bytes
Redo Buffers                   2355200 bytes


9.恢复控制文件


RMAN> restore  controlfile from '/oradata/backup/c_ctl_NODE1_20160127_26_1';
Starting restore at 04-FEB-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring control file
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 02/04/2016 19:50:38
ORA-19504: failed to create file "/u01/app/oracle/fast_recovery_area/node1/control02.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
ORA-19600: input file is control file  (/oradata/node1/control01.ctl)
ORA-19601: output file is control file  (/u01/app/oracle/fast_recovery_area/node1/control02.ctl)

这里没有那些目录,创建目录
mkdir -p /u01/app/oracle/fast_recovery_area/node1/
mkdir -p  /oradata/node1/

RMAN> restore  controlfile from '/oradata/backup/c_ctl_NODE1_20160127_26_1';

Starting restore at 04-FEB-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/oradata/node1/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/node1/control02.ctl
Finished restore at 04-FEB-16

10.启动到mount状态

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


[oracle@node3 node1]$ export ORACLE_SID=node1
[oracle@node3 node1]$ env|grep SID
ORACLE_SID=node1
[oracle@node3 node1]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Feb 4 19:58:20 2016

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

查看文件路径
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/node1/system01.dbf
/oradata/node1/sysaux01.dbf
/oradata/node1/undotbs01.dbf
/oradata/node1/users01.dbf
/oradata/node1/bbb.dbf


11.rman 恢复数据文件

 第一种目标端的路径跟源端路径不一样了需要set newname
run
{
set newname for datafile '/oradata/node1/system01.dbf' to '/oradata/node2/system01.dbf';
set newname for datafile '/oradata/node1/sysaexux01.dbf'to '/oradata/node2/sysaux01.dbf';
set newname for datafile '/oradata/node1/undotbs01.dbf' to '/oradata/node2/undotbs01.dbf';
set newname for datafile '/oradata/node1/users01.dbf'  to '/oradata/node2/users01.dbf';
restore database ;
switch datafile all;
}

run{
   allocate channel c1 type disk;
   recover database;
}

第二种:目标端路径和源端完全一样直接 restore database;

RMAN> restore database;

Starting restore at 04-FEB-16
Starting implicit crosscheck backup at 04-FEB-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 15 objects
Finished implicit crosscheck backup at 04-FEB-16

Starting implicit crosscheck copy at 04-FEB-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 04-FEB-16

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /oradata/node1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oradata/node1/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /oradata/backup/full_NODE1_20160127_20_1
channel ORA_DISK_1: piece handle=/oradata/backup/full_NODE1_20160127_20_1 tag=TAG20160127T072041
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oradata/node1/system01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oradata/node1/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /oradata/node1/bbb.dbf
channel ORA_DISK_1: reading from backup piece /oradata/backup/full_NODE1_20160127_19_1
channel ORA_DISK_1: piece handle=/oradata/backup/full_NODE1_20160127_19_1 tag=TAG20160127T072041
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 04-FEB-16

RMAN> recover database;
Starting recover at 04-FEB-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=46
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=47
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=48
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=49
channel ORA_DISK_1: reading from backup piece /oradata/backup/arch_NODE1_20160127_25_1
channel ORA_DISK_1: piece handle=/oradata/backup/arch_NODE1_20160127_25_1 tag=TAG20160127T072111
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
archived log file name=/oradata/arch1_46_901846980.dbf thread=1 sequence=46
archived log file name=/oradata/arch1_47_901846980.dbf thread=1 sequence=47
archived log file name=/oradata/arch1_48_901846980.dbf thread=1 sequence=48
archived log file name=/oradata/arch1_49_901846980.dbf thread=1 sequence=49
unable to find archived log
archived log thread=1 sequence=50
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2016 20:03:15
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 50 and starting SCN of 436825


12.源库查看
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;

    GROUP#  SEQUENCE# STATUS       FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- -------------------------------- ------------- ------------
 1   49 INACTIVE      436817   436825
 2   50 CURRENT      436825   2.8147E+14
 3   48 INACTIVE      436808   436817

可以看到sequence 50的是current日志

主库先备份归档:RMAN> backup archivelog all format '/oradata/backup/arch_%d_%T_%s_%p';
将归档备份集Scp到备库;
[root@node1 backup]# scp arch_NODE1_20160127_27_1 [email protected]:/oradata/backup
The authenticity of host '192.168.56.12 (192.168.56.12)' can't be established.
RSA key fingerprint is f4:26:86:52:23:76:4c:09:1b:b0:6d:32:a7:7a:0a:80.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.12' (RSA) to the list of known hosts.
[email protected]'s password: 
arch_NODE1_20160127_27_1                                                                                                                                     100%  293MB  29.3MB/s   00:10    
[root@node1 backup]# 


13.备库再注册归档备份集:
RMAN> catalog backuppiece '/oradata/backup/arch_NODE1_20160127_27_1';

cataloged backup piece
backup piece handle=/oradata/backup/arch_NODE1_20160127_27_1 RECID=25 STAMP=902952783

RMAN> recover database;

Starting recover at 04-FEB-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=50
channel ORA_DISK_1: reading from backup piece /oradata/backup/arch_NODE1_20160127_27_1
channel ORA_DISK_1: piece handle=/oradata/backup/arch_NODE1_20160127_27_1 tag=TAG20160127T081756
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/oradata/arch1_50_901846980.dbf thread=1 sequence=50
unable to find archived log
archived log thread=1 sequence=51
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2016 20:13:22
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 51 and starting SCN of 438344

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

    GROUP#    THREAD#  SEQUENCE# STATUS   FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------- -------------------------------- ------------- ------------
 1    1      49 INACTIVE 436817       436825
 2    1      50 ACTIVE  436825       438344
 3    1      51 CURRENT 438344   2.8147E+14
 
可以看到sequence 51 已经是最新的日志了

14. 打开数据库
SQL> alter database open resetlogs;

Database altered.

你可能感兴趣的:(rman迁移,Rman异机恢复)