oracle rman恢复数据库 方式恢复到异地数据库

时间:2022-10-08 08:41:22
目的:从某个环境中,获取相关文件,放到异地机器使用rman 恢复。
 
情况说明:XX系统使用的是oracle数据库,现已从服务器拉下来相关文件,依靠这些文件来早本地的测试机上恢复数据库,方便进行数据清洗、分析等工作。
xx环境使用的数据库版本为11.2.0.4,由于没有注意版本之前装了一个11.2.0.1的oracle,后发现和生产环境的版本不匹配,从新下载了一个同版本的。
 
从XX环境获取pfile
 
sql > create pfile='/xxxxx' from spfile;
 
获取到pfile文件后,放到目的服务上,需要修改文件内相关的目录名
 
然后把生成的文件放到目的服务器上
 
[oracle@abcd-xt-oracle-t-001 ~]$ sqlplus / as sysdba;
 
SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 23 16:36:07 2016
 
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
 
Connected to an idle instance.
 
ORACLE instance shut down.
SQL> startup pfile=/tmp/20160328/paydb.ora nomount
ORACLE instance started.
 
Total System Global Area 5.1310E+10 bytes
Fixed Size     2217632 bytes
Variable Size  4294969696 bytes
Database Buffers  4.6976E+10 bytes
Redo Buffers    36118528 bytes
 
[oracle@abcd-xt-oracle-t-001 paydb]$ rman target / 
RMAN>restore controlfile from '/tmp/20160330/Lv0_PAYDB_20160328_fbr1j0v7_1_1_primary_control.rbf';
 
 
 
 
==============================================================
RMAN> alter database mount;
 
database mounted
released channel: ORA_DISK_1
 
通过catalog start with 命令可以将最新的备份集以及归档日志文件列表导入到控制文中,然后就可以进行rman的恢复了.
RMAN> catalog start with '/tmp/20160330/';
 
Starting implicit crosscheck backup at 2016-03-30 14:47:26
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1136 device type=DISK
Crosschecked 608 objects
Finished implicit crosscheck backup at 2016-03-30 14:47:30
 
Starting implicit crosscheck copy at 2016-03-30 14:47:30
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2016-03-30 14:47:30
 
searching for all files in the recovery area
cataloging files...
no files cataloged
 
searching for all files that match the pattern /tmp/20160330/
 
List of Files Unknown to the Database
=====================================
File Name: /tmp/20160330/Lv0_PAYDB_20160328_fbr1j0v7_1_1_primary_control.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_1_1.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_fcr1j0va_1_1_primary_spfile.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_2_1.rbf
File Name: /tmp/20160330/Arc_PAYDB_20160328_far1j0qk_1_1.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_f9r1j0q1_1_1.rbf
 
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
 
List of Cataloged Files
=======================
File Name: /tmp/20160330/Lv0_PAYDB_20160328_fbr1j0v7_1_1_primary_control.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_1_1.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_fcr1j0va_1_1_primary_spfile.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_2_1.rbf
File Name: /tmp/20160330/Arc_PAYDB_20160328_far1j0qk_1_1.rbf
File Name: /tmp/20160330/Lv0_PAYDB_20160328_f9r1j0q1_1_1.rbf
 
RMAN> run  {
2> set newname for datafile '+DATA/paydb/datafile/system.259.893526117'  to '/dbdata/paydb/datafile/system.259.893526117';
3> 
4>  set newname for datafile '+DATA/paydb/datafile/sysaux.260.893526133' to '/dbdata/paydb/datafile/sysaux.260.893526133';
5> 
6>  set newname for datafile '+DATA/paydb/datafile/undotbs1.261.893526141' to '/dbdata/paydb/datafile/undotbs1.261.893526141'; 
7> 
8>  set newname for datafile '+DATA/paydb/datafile/undotbs2.263.893526155' to '/dbdata/paydb/datafile/undotbs2.263.893526155';
9> 
10>  set newname for datafile '+DATA/paydb/datafile/undotbs3.264.893526163' to '/dbdata/paydb/datafile/undotbs3.264.893526163';
11> 
12>  set newname for datafile '+DATA/paydb/datafile/users.265.893526169' to '/dbdata/paydb/datafile/users.265.893526169';
13> 
14>  set newname for datafile '+DATA/paydb/datafile/acs01.dbf' to '/dbdata/paydb/datafile/acs01.dbf';
15> 
16>  set newname for datafile '+DATA/paydb/datafile/activemq01.dbf' to '/dbdata/paydb/datafile/activemq01.dbf';
17> 
18>  set newname for datafile '+DATA/paydb/datafile/authorize01.dbf' to '/dbdata/paydb/datafile/authorize01.dbf';
19> 
20>  set newname for datafile '+DATA/paydb/datafile/basis01.dbf' to '/dbdata/paydb/datafile/basis01.dbf';
21> 
22>  set newname for datafile '+DATA/paydb/datafile/cashier01.dbf'  to '/dbdata/paydb/datafile/cashier01.dbf';
23> 
24>  set newname for datafile '+DATA/paydb/datafile/cert01.dbf' to '/dbdata/paydb/datafile/cert01.dbf';
25> 
26>  set newname for datafile '+DATA/paydb/datafile/cmf01.dbf' to '/dbdata/paydb/datafile/cmf01.dbf';
27> 
28>  set newname for datafile '+DATA/paydb/datafile/counter01.dbf' to '/dbdata/paydb/datafile/counter01.dbf';
29> 
30>  set newname for datafile '+DATA/paydb/datafile/csa01.dbf' to '/dbdata/paydb/datafile/csa01.dbf';
31> 
32>  set newname for datafile '+DATA/paydb/datafile/deposit01.dbf' to '/dbdata/paydb/datafile/deposit01.dbf';
33> 
34>  set newname for datafile '+DATA/paydb/datafile/dpm01.dbf' to '/dbdata/paydb/datafile/dpm01.dbf';
35> 
36>  set newname for datafile '+DATA/paydb/datafile/ffs01.dbf' to '/dbdata/paydb/datafile/ffs01.dbf';
37> 
38>  set newname for datafile '+DATA/paydb/datafile/fos01.dbf' to '/dbdata/paydb/datafile/fos01.dbf';
39> 
40>  set newname for datafile '+DATA/paydb/datafile/guardian01.dbf' to '/dbdata/paydb/datafile/guardian01.dbf';
41> 
42>  set newname for datafile '+DATA/paydb/datafile/lflt01.dbf' to '/dbdata/paydb/datafile/lflt01.dbf';
43> 
44>  set newname for datafile '+DATA/paydb/datafile/member01.dbf' to '/dbdata/paydb/datafile/member01.dbf';
45> 
46> set newname for datafile '+DATA/paydb/datafile/mns01.dbf' to '/dbdata/paydb/datafile/mns01.dbf';
47> 
48>  set newname for datafile '+DATA/paydb/datafile/oss01.dbf' to '/dbdata/paydb/datafile/oss01.dbf';
49> 
50>  set newname for datafile '+DATA/paydb/datafile/payment01.dbf' to '/dbdata/paydb/datafile/payment01.dbf';
51> 
52>  set newname for datafile '+DATA/paydb/datafile/pbsdb01.dbf' to '/dbdata/paydb/datafile/pbsdb01.dbf';
53> 
54>  set newname for datafile '+DATA/paydb/datafile/pfs01.dbf' to '/dbdata/paydb/datafile/pfs01.dbf';
55> 
56>  set newname for datafile '+DATA/paydb/datafile/pns01.dbf' to '/dbdata/paydb/datafile/pns01.dbf';
57> 
58>  set newname for datafile '+DATA/paydb/datafile/reader01.dbf' to '/dbdata/paydb/datafile/reader01.dbf';
59> 
60>  set newname for datafile '+DATA/paydb/datafile/rms01.dbf' to '/dbdata/paydb/datafile/rms01.dbf';
61> 
62>  set newname for datafile '+DATA/paydb/datafile/smsgateway01.dbf' to '/dbdata/paydb/datafile/smsgateway01.dbf';
63> 
64>  set newname for datafile '+DATA/paydb/datafile/tss01.dbf' to '/dbdata/paydb/datafile/tss01.dbf';
65> 
66>  set newname for datafile '+DATA/paydb/datafile/ues01.dbf' to '/dbdata/paydb/datafile/ues01.dbf';
67> 
68>  set newname for datafile '+DATA/paydb/datafile/voucher01.dbf' to '/dbdata/paydb/datafile/voucher01.dbf';
69> 
70>  set newname for datafile '+DATA/paydb/datafile/wallet01.dbf' to '/dbdata/paydb/datafile/wallet01.dbf';
71> 
72> restore database;
73>  switch datafile all;}
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
Starting restore at 2016-03-30 14:48:01
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 00001 to /dbdata/paydb/datafile/system.259.893526117
channel ORA_DISK_1: restoring datafile 00002 to /dbdata/paydb/datafile/sysaux.260.893526133
channel ORA_DISK_1: restoring datafile 00003 to /dbdata/paydb/datafile/undotbs1.261.893526141
channel ORA_DISK_1: restoring datafile 00004 to /dbdata/paydb/datafile/undotbs2.263.893526155
channel ORA_DISK_1: restoring datafile 00005 to /dbdata/paydb/datafile/undotbs3.264.893526163
channel ORA_DISK_1: restoring datafile 00006 to /dbdata/paydb/datafile/users.265.893526169
channel ORA_DISK_1: restoring datafile 00007 to /dbdata/paydb/datafile/acs01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /dbdata/paydb/datafile/activemq01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /dbdata/paydb/datafile/authorize01.dbf
channel ORA_DISK_1: restoring datafile 00010 to /dbdata/paydb/datafile/basis01.dbf
channel ORA_DISK_1: restoring datafile 00011 to /dbdata/paydb/datafile/cashier01.dbf
channel ORA_DISK_1: restoring datafile 00012 to /dbdata/paydb/datafile/cert01.dbf
channel ORA_DISK_1: restoring datafile 00013 to /dbdata/paydb/datafile/cmf01.dbf
channel ORA_DISK_1: restoring datafile 00014 to /dbdata/paydb/datafile/counter01.dbf
channel ORA_DISK_1: restoring datafile 00015 to /dbdata/paydb/datafile/csa01.dbf
channel ORA_DISK_1: restoring datafile 00016 to /dbdata/paydb/datafile/deposit01.dbf
channel ORA_DISK_1: restoring datafile 00017 to /dbdata/paydb/datafile/dpm01.dbf
channel ORA_DISK_1: restoring datafile 00018 to /dbdata/paydb/datafile/ffs01.dbf
channel ORA_DISK_1: restoring datafile 00019 to /dbdata/paydb/datafile/fos01.dbf
channel ORA_DISK_1: restoring datafile 00020 to /dbdata/paydb/datafile/guardian01.dbf
channel ORA_DISK_1: restoring datafile 00021 to /dbdata/paydb/datafile/lflt01.dbf
channel ORA_DISK_1: restoring datafile 00022 to /dbdata/paydb/datafile/member01.dbf
channel ORA_DISK_1: restoring datafile 00023 to /dbdata/paydb/datafile/mns01.dbf
channel ORA_DISK_1: restoring datafile 00024 to /dbdata/paydb/datafile/oss01.dbf
channel ORA_DISK_1: restoring datafile 00025 to /dbdata/paydb/datafile/payment01.dbf
channel ORA_DISK_1: restoring datafile 00026 to /dbdata/paydb/datafile/pbsdb01.dbf
channel ORA_DISK_1: restoring datafile 00027 to /dbdata/paydb/datafile/pfs01.dbf
channel ORA_DISK_1: restoring datafile 00028 to /dbdata/paydb/datafile/pns01.dbf
channel ORA_DISK_1: restoring datafile 00029 to /dbdata/paydb/datafile/reader01.dbf
channel ORA_DISK_1: restoring datafile 00030 to /dbdata/paydb/datafile/rms01.dbf
channel ORA_DISK_1: restoring datafile 00031 to /dbdata/paydb/datafile/smsgateway01.dbf
channel ORA_DISK_1: restoring datafile 00032 to /dbdata/paydb/datafile/tss01.dbf
channel ORA_DISK_1: restoring datafile 00033 to /dbdata/paydb/datafile/ues01.dbf
channel ORA_DISK_1: restoring datafile 00034 to /dbdata/paydb/datafile/voucher01.dbf
channel ORA_DISK_1: restoring datafile 00035 to /dbdata/paydb/datafile/wallet01.dbf
channel ORA_DISK_1: reading from backup piece /tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_1_1.rbf
channel ORA_DISK_1: piece handle=/tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_1_1.rbf tag=TAG20160328T024014
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: reading from backup piece /tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_2_1.rbf
channel ORA_DISK_1: piece handle=/tmp/20160330/Lv0_PAYDB_20160328_f8r1j0of_2_1.rbf tag=TAG20160328T024014
channel ORA_DISK_1: restored backup piece 2
channel ORA_DISK_1: restore complete, elapsed time: 00:01:50
Finished restore at 2016-03-30 14:49:52
 
datafile 1 switched to datafile copy
input datafile copy RECID=36 STAMP=907858193 file name=/dbdata/paydb/datafile/system.259.893526117
datafile 2 switched to datafile copy
input datafile copy RECID=37 STAMP=907858193 file name=/dbdata/paydb/datafile/sysaux.260.893526133
datafile 3 switched to datafile copy
input datafile copy RECID=38 STAMP=907858193 file name=/dbdata/paydb/datafile/undotbs1.261.893526141
datafile 4 switched to datafile copy
input datafile copy RECID=39 STAMP=907858193 file name=/dbdata/paydb/datafile/undotbs2.263.893526155
datafile 5 switched to datafile copy
input datafile copy RECID=40 STAMP=907858193 file name=/dbdata/paydb/datafile/undotbs3.264.893526163
datafile 6 switched to datafile copy
input datafile copy RECID=41 STAMP=907858193 file name=/dbdata/paydb/datafile/users.265.893526169
datafile 7 switched to datafile copy
input datafile copy RECID=42 STAMP=907858193 file name=/dbdata/paydb/datafile/acs01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=43 STAMP=907858193 file name=/dbdata/paydb/datafile/activemq01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=44 STAMP=907858193 file name=/dbdata/paydb/datafile/authorize01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=45 STAMP=907858193 file name=/dbdata/paydb/datafile/basis01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=46 STAMP=907858193 file name=/dbdata/paydb/datafile/cashier01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=47 STAMP=907858193 file name=/dbdata/paydb/datafile/cert01.dbf
datafile 13 switched to datafile copy
input datafile copy RECID=48 STAMP=907858193 file name=/dbdata/paydb/datafile/cmf01.dbf
datafile 14 switched to datafile copy
input datafile copy RECID=49 STAMP=907858193 file name=/dbdata/paydb/datafile/counter01.dbf
datafile 15 switched to datafile copy
input datafile copy RECID=50 STAMP=907858193 file name=/dbdata/paydb/datafile/csa01.dbf
datafile 16 switched to datafile copy
input datafile copy RECID=51 STAMP=907858193 file name=/dbdata/paydb/datafile/deposit01.dbf
datafile 17 switched to datafile copy
input datafile copy RECID=52 STAMP=907858193 file name=/dbdata/paydb/datafile/dpm01.dbf
datafile 18 switched to datafile copy
input datafile copy RECID=53 STAMP=907858193 file name=/dbdata/paydb/datafile/ffs01.dbf
datafile 19 switched to datafile copy
input datafile copy RECID=54 STAMP=907858193 file name=/dbdata/paydb/datafile/fos01.dbf
datafile 20 switched to datafile copy
input datafile copy RECID=55 STAMP=907858193 file name=/dbdata/paydb/datafile/guardian01.dbf
datafile 21 switched to datafile copy
input datafile copy RECID=56 STAMP=907858193 file name=/dbdata/paydb/datafile/lflt01.dbf
datafile 22 switched to datafile copy
input datafile copy RECID=57 STAMP=907858193 file name=/dbdata/paydb/datafile/member01.dbf
datafile 23 switched to datafile copy
input datafile copy RECID=58 STAMP=907858193 file name=/dbdata/paydb/datafile/mns01.dbf
datafile 24 switched to datafile copy
input datafile copy RECID=59 STAMP=907858193 file name=/dbdata/paydb/datafile/oss01.dbf
datafile 25 switched to datafile copy
input datafile copy RECID=60 STAMP=907858193 file name=/dbdata/paydb/datafile/payment01.dbf
datafile 26 switched to datafile copy
input datafile copy RECID=61 STAMP=907858193 file name=/dbdata/paydb/datafile/pbsdb01.dbf
datafile 27 switched to datafile copy
input datafile copy RECID=62 STAMP=907858193 file name=/dbdata/paydb/datafile/pfs01.dbf
datafile 28 switched to datafile copy
input datafile copy RECID=63 STAMP=907858193 file name=/dbdata/paydb/datafile/pns01.dbf
datafile 29 switched to datafile copy
input datafile copy RECID=64 STAMP=907858193 file name=/dbdata/paydb/datafile/reader01.dbf
datafile 30 switched to datafile copy
input datafile copy RECID=65 STAMP=907858193 file name=/dbdata/paydb/datafile/rms01.dbf
datafile 31 switched to datafile copy
input datafile copy RECID=66 STAMP=907858193 file name=/dbdata/paydb/datafile/smsgateway01.dbf
datafile 32 switched to datafile copy
input datafile copy RECID=67 STAMP=907858193 file name=/dbdata/paydb/datafile/tss01.dbf
datafile 33 switched to datafile copy
input datafile copy RECID=68 STAMP=907858193 file name=/dbdata/paydb/datafile/ues01.dbf
datafile 34 switched to datafile copy
input datafile copy RECID=69 STAMP=907858193 file name=/dbdata/paydb/datafile/voucher01.dbf
datafile 35 switched to datafile copy
input datafile copy RECID=70 STAMP=907858193 file name=/dbdata/paydb/datafile/wallet01.dbf
 
 
 
 
run  命令之后   在目录下会有以下.rbf文件
 
 
再次核对以下数据库文件信息,与上面的.rbf文件对应一致,即是正确的。
 
RMAN> recover database;
 
Starting recover at 2016-03-30 15:00:51
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=3 sequence=602
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=604
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=668
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=669
channel ORA_DISK_1: restoring archived log
archived log thread=3 sequence=603
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=605
channel ORA_DISK_1: reading from backup piece /tmp/20160330/Arc_PAYDB_20160328_far1j0qk_1_1.rbf
channel ORA_DISK_1: piece handle=/tmp/20160330/Arc_PAYDB_20160328_far1j0qk_1_1.rbf tag=TAG20160328T024123
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:35
archived log file name=/u01/archive/paydb/Arc_1_668_893526106.arc thread=1 sequence=668
archived log file name=/u01/archive/paydb/Arc_2_604_893526106.arc thread=2 sequence=604
archived log file name=/u01/archive/paydb/Arc_3_602_893526106.arc thread=3 sequence=602
archived log file name=/u01/archive/paydb/Arc_1_669_893526106.arc thread=1 sequence=669
archived log file name=/u01/archive/paydb/Arc_3_603_893526106.arc thread=3 sequence=603
archived log file name=/u01/archive/paydb/Arc_2_605_893526106.arc thread=2 sequence=605
unable to find archived log
archived log thread=1 sequence=670
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/30/2016 15:03:30
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 670 and starting SCN of 156142203
 
 
[oracle@abcd-xt-oracle-t-001 ~]$ rman target /
 
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Mar 30 16:14:21 2016
 
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: PAYDB (DBID=3409530074, not open)
 
RMAN> alter database open resetlogs;        //以open resetlogs的方式打开数据库,完成整个RMAN的恢复
 
using target database control file instead of recovery catalog
database opened
 
到此整个到异地单机的RMAN恢复任务已经完成。
注:这里只是简单的介绍一下恢复的过程,每个人遇到的情况可能都不是完全一样的,如果遇到问题,耐心的查找,一个一个解决,最终会成功的!