ITPub博客

首页 > 数据库 > Oracle > 同平台下利用RMAN做Oracle数据迁移

同平台下利用RMAN做Oracle数据迁移

Oracle 作者:StevenBeijing 时间:2015-12-25 09:53:50 1 删除 编辑
整体流程:对A机的数据库来一个热备,并且是一个全备,然后通过scp命令把备份传到B机,然后把A库停掉(注意关库不会触发归档),之后再把归档日志和redo日志传给B机,最后再在B库上 restore 和recover
数据文件,控制文件,参数文件  的恢复过程:根据数据库的启动流程,可以知道最先读取数据文件,所以应该先还原参数文件,然后会读控制文件,所以你要再修复控制文件,最后再修复数据文件,
具体操作流程:
一:对A库做一个热全备,
RMAN> backup as backupset database include current controlfile plus archivelog format '/u01/app/oracle/arch_%U.rmn' delete all input;
省列。。。。
Finished backup at 14-AUG-14
二:把所做的备份用scp传给B机。 如红色命令会把A机的ENMOEDU接到B机的Oracle/下,,即Oracle/ENMOEDU
[oracle@ENMOEDU ENMOEDU]$ scp -r /u01/app/oracle/fast_recovery_area/ENMOEDU     oracle@192.168.80.11:/u01/app/oracle/ 
The authenticity of host '192.168.80.11 (192.168.80.11)' can't be established. 
RSA key fingerprint is 54:78:71:4c:93:51:01:f4:e3:83:b5:35:8f:9f:d5:b1. 
Are you sure you want to continue connecting (yes/no)? y 
Please type 'yes' or 'no': yes 
Warning: Permanently added '192.168.80.11' (RSA) to the list of known hosts. 
oracle@192.168.80.11's password: 
o1_mf_nnndf_SECTION_DF1_9srh9o7k_.bkp 100% 148MB 36.9MB/s 00:04 
o1_mf_ncnnf_SECTION_DF1_9srh9ws3_.bkp 100% 9568KB 9.3MB/s 00:01 
o1_mf_nnndf_SECTION_DF1_9srh9n9o_.bkp 100% 97MB 24.2MB/s 00:04 
o1_mf_nnsnf_SECTION_DF1_9srh9nml_.bkp 100% 96KB 96.0KB/s 00:00 
o1_mf_nnndf_SECTION_DF1_9srh9o26_.bkp 100% 140MB 28.0MB/s 00:05 
o1_mf_nnndf_SECTION_DF1_9srh9v71_.bkp 100% 145MB 29.0MB/s 00:05 
o1_mf_nnndf_SECTION_DF1_9srhb0dh_.bkp 100% 81MB 27.0MB/s 00:03 
o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp 100% 9600KB 4.7MB/s 00:02 
o1_mf_nnndf_TAG20140814T203309_9ysc46go_.bkp 100% 1140MB 24.3MB/s 00:47 
control02.ctl                                                            100% 9520KB 9.3MB/s 00:01 
三:把A库数据库关闭,把归档和redo传给B机,(因为你备份的时候没有关闭数据库,难免会再产生新的归档和redo,为保证一致性,还有必要进行这步)
1.SYS@ENMOEDU> select * from v$log;                      #显示第三组  正在被使用,所以只传它就行(因为别的已经被归档,)

GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC 
---------- ---------- ---------- ---------- ---------- ---------- --- 
STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME 
---------------- ------------- --------- ------------ --------- 
1 1 100 52428800 512 1 YES 
INACTIVE 1365811 14-AUG-14 1365876 14-AUG-14 

2 1 101 52428800 512 1 YES 
INACTIVE 1365876 14-AUG-14 1365981 14-AUG-14 

3 1 102 52428800 512 1 NO 
CURRENT 1365981 14-AUG-14 2.8147E+14 


2.SYS@ENMOEDU> select * from v$logfile;     #查看日志的具体位置

GROUP# STATUS TYPE 
---------- ------- ------- 
MEMBER 
-------------------------------------------------------------------------------- 
IS_ 
--- 
1 ONLINE 
/u01/app/oracle/oradata/ENMOEDU/redo01.log 
NO 

2 ONLINE 
/u01/app/oracle/oradata/ENMOEDU/redo02.log 
NO 

GROUP# STATUS TYPE 
---------- ------- ------- 
MEMBER 
-------------------------------------------------------------------------------- 
IS_ 
--- 

3 ONLINE 
/u01/app/oracle/oradata/ENMOEDU/redo03.log 
NO
[oracle@ENMOEDU ENMOEDU]$ scp /u01/app/oracle/oradata/ENMOEDU/redo03.log oracle@192.168.80.11:/u01/app/oracle 
oracle@192.168.80.11's password: 
redo03.log 100% 50MB 50.0MB/s 00:01   
至于归档嘛  我在测试的时候没有切换日志,也不存在日志组写满的情况,所以没有产生归档,又因为我在备份的时候加上了delete all input 所以会把已经备份的归档删掉,所以你不会看到新的归档  也就不用传了  呵呵
四:在B机操作
1,开启伪实例,注意可不要把B机的数据库实例给打开了  因为我的测试B机也有数据库。
[oracle@ENMOEDU ~]$ set DBID=87396644               #设成A机的数据库编号
RMAN> startup                #启动伪实例   

[oracle@ENMOEDU ENMOEDU]$ rman target / 
RMAN> restore spfile from '/u01/app/oracle/ENMOEDU/backupset/2014_08_14/o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp'; 

Starting restore at 15-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/ENMOEDU/backupset/2014_08_14/o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 15-AUG-14
[oracle@ENMOEDU dbs]$ ls                  #恢复的参数文件在$ORACLE_HOME/dbs  下
hc_ENMOEDU2.dat    lkDUMMY   orapwENMOEDU    spfileENMOEDU2.ora
RMAN> shutdown immediate                           #关伪实例

Oracle instance shut down
2.然后再起真正的实例,恢复控制文件(要注意,他原来就有,你这样起,把B机的所有文件包括  数据文件 ,控制文件,参数文件,日志文件都删掉
SQL> startup
ORACLE instance started.

Total System Global Area 422670336 bytes
Fixed Size 1345380 bytes
Variable Size 260049052 bytes
Database Buffers 155189248 bytes
Redo Buffers 6086656 bytes
ORA-00205: error in identifying control file, check alert log for more info
RMAN> restore controlfile from '/u01/app/oracle/ENMOEDU/backupset/2014_08_14/o1_mf_ncsnf_TAG20140814T203309_9ysc8x14_.bkp';

Starting restore at 15-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/ENMOEDU/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/ENMOEDU/control02.ctl
Finished restore at 15-AUG-14
3.把数据库开到mount状态,以便修复数据文件。
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1
RMAN> restore database;                    #恢复数据文件   发现报错,很可能是备份已经过期已经,

Starting restore at 15-AUG-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK

creating datafile file number=1 name=/u01/app/oracle/oradata/ENMOEDU/system01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/15/2014 23:21:00
ORA-01180: can not create datafile 1
ORA-01110: data file 1: '/u01/app/oracle/oradata/ENMOEDU/system01.dbf'
RMAN> list backup;          #查看备份信息    发现确实过期
10 13.85M DISK 00:00:02 14-AUG-14
        BP Key: 14 Status: EXPIRED Compressed: NO Tag: TAG20140814T203306
        Piece Name: /u01/app/oracle/arch_50pfv1g2_1_1.rmn
然后再去A机  再来一个整体备份  再传给B机  不在赘述,再恢复控制文件,然后再恢复数据文件,  
再启动到open即可。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30135314/viewspace-1960973/,如需转载,请注明出处,否则将追究法律责任。

下一篇: 逻辑DG重启步骤
请登录后发表评论 登录
全部评论

注册时间:2015-02-10

  • 博文量
    197
  • 访问量
    189260