linux 6.4平台利用rman迁移oracle 11g r2数据库

时间:2023-03-08 23:59:02
linux 6.4平台利用rman迁移oracle 11g r2数据库
测试环境分别在虚拟机安装A,B主机
系统:linux 6.4,
数据库:oracle 11g r2
A主机:安装oracle 11g r2数据库
B主机:只安装oracle 11g r2软件

第一步,运行下面rman命令备份数据库
run{
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/dbback/config_%F';
allocate channel c1 type disk format '/u01/app/dbback/full_%U';
backup database tag 'full_gpodb_data' FILESPERSET 10 PLUS ARCHIVELOG FILESPERSET 20 DELETE ALL INPUT;
release channel c1;
 }

[root@bogon ~]# su - oracle
[oracle@bogon ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Sat Oct 26 05:16:55 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DB (DBID=1587060738) ------------记住这个DBID恢复数据库会用到
RMAN> run{
2> CONFIGURE CONTROLFILE AUTOBACKUP ON;
3> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/dbback/config_%F';
4> allocate channel c1 type disk format '/u01/app/dbback/full_%U';
5> backup database tag 'full_gpodb_data' FILESPERSET 10 PLUS ARCHIVELOG FILESPERSET 20 DELETE ALL INPUT;
6> release channel c1;
7>  }

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/dbback/gpofullbak/%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/dbback/config_%F';
new RMAN configuration parameters are successfully stored

allocated channel: c1
channel c1: SID=47 device type=DISK

Starting backup at 26-OCT-13
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=21 RECID=12 STAMP=829805117
channel c1: starting piece 1 at 26-OCT-13
channel c1: finished piece 1 at 26-OCT-13
piece handle=/u01/app/dbback/full_08onbkhu_1_1 tag=TAG20131026T052518 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: deleting archived log(s)
archived log file name=/u01/app/archiv/1_21_823244933.dbf RECID=12 STAMP=829805117
Finished backup at 26-OCT-13

Starting backup at 26-OCT-13
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/db/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/db/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/db/anfei01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/db/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/db/DB/datafile/o1_mf_dbs_91x4vt9f_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/db/dbt.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/db/users01.dbf
channel c1: starting piece 1 at 26-OCT-13
channel c1: finished piece 1 at 26-OCT-13
piece handle=/u01/app/dbback/full_09onbkhv_1_1 tag=FULL_GPODB_DATA comment=NONE
channel c1: backup set complete, elapsed time: 00:01:36
Finished backup at 26-OCT-13

Starting backup at 26-OCT-13
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=13 STAMP=829805216
channel c1: starting piece 1 at 26-OCT-13
channel c1: finished piece 1 at 26-OCT-13
piece handle=/u01/app/dbback/full_0aonbkl1_1_1 tag=TAG20131026T052657 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: deleting archived log(s)
archived log file name=/u01/app/archiv/1_22_823244933.dbf RECID=13 STAMP=829805216
Finished backup at 26-OCT-13

Starting Control File and SPFILE Autobackup at 26-OCT-13
piece handle=/u01/app/dbback/config_c-1587060738-20131026-01 comment=NONE
Finished Control File and SPFILE Autobackup at 26-OCT-13

released channel: c1

RMAN>

第二步,创建pfile参数文件

[oracle@bogon dbs]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 26 05:52:14 2013

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

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

SQL> create pfile from spfile;

File created.

第三步,利用scp命令将备份文件,pfile参数文件传输到B主机
备份文件的目标在/u01/app/dbback,首先在B主机创建dbback目录
[oracle@bogon app]$ mkdir dbback

传输pfile文件(这这里将/u01/app/oracle/product/11.2.1/db_1/dbs目录下的文件全部传输到了B主机)
[oracle@bogon dbs]$ scp * 192.168.1.103:/u01/app/oracle/product/11.2.1/db_1/dbs
The authenticity of host '192.168.1.103 (192.168.1.103)' can't be established.
RSA key fingerprint is aa:25:3b:48:55:b9:e9:f5:dd:60:2d:55:b5:93:af:db.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.103' (RSA) to the list of known hosts.
reverse mapping checking getaddrinfo for bogon [192.168.1.103] failed - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.1.103's password:
hc_db.dat                                                                    100% 1544     1.5KB/s   00:00    
hc_DBUA0.dat                                                                 100% 1544     1.5KB/s   00:00    
initdb.ora                                                                   100%  975     1.0KB/s   00:00    
init.ora                                                                     100% 2851     2.8KB/s   00:00    
lkDB                                                                         100%   24     0.0KB/s   00:00    
orapwdb                                                                      100% 1536     1.5KB/s   00:00    
peshm_db_0: not a regular file
peshm_DBUA0_0: not a regular file
snapcf_db.f                                                                  100% 9520KB   9.3MB/s   00:01    
spfiledb.ora                                                                 100% 2560     2.5KB/s   00:00

传输/u01/app/dbback目录下的备份文件
[oracle@bogon dbback]$ scp * 192.168.1.102:/u01/app/dbback
The authenticity of host '192.168.1.102 (192.168.1.102)' can't be established.
RSA key fingerprint is 2e:02:60:91:68:fb:bd:0c:9c:22:82:08:74:fd:f0:42.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.102' (RSA) to the list of known hosts.
oracle@192.168.1.102's password:
config_c-1587060738-20131026-01                                              100% 9600KB   9.4MB/s   00:01    
full_08onbkhu_1_1                                                            100% 3584     3.5KB/s   00:00    
full_09onbkhv_1_1                                                            100%  950MB   5.7MB/s   02:46    
full_0aonbkl1_1_1                                                            100%   14KB  13.5KB/s   00:00    
[oracle@bogon dbback]$ cd ~

第四步,登陆B主机,创建和A主机相对应的文件夹

我主机的oracle 文件安装在/u01/app/oracle

[oracle@bogon app]$ cd oracle
[oracle@bogon oracle]$ ls        ---------------和A主机对应缺少了diag  flash_recovery_area  oradata admin  cfgtoollogs 文件夹
checkpoints  product
[oracle@bogon oracle]$
[oracle@bogon oracle]$ mkdir diag  flash_recovery_area  oradata admin  cfgtoollogs        --------创建文件夹
[oracle@bogon oracle]$ cd oradata
[oracle@bogon oradata]$ ls
[oracle@bogon oradata]$ mkdir db
[oracle@bogon oradata]$ ls
db

[oracle@bogon oracle]$ cd cfgtoollogs
[oracle@bogon cfgtoollogs]$ ls
[oracle@bogon cfgtoollogs]$ mkdir dbca  emca  netca
[oracle@bogon cfgtoollogs]$

[oracle@bogon admin]$ mkdir db
[oracle@bogon admin]$ cd db
[oracle@bogon db]$ ls
[oracle@bogon db]$ mkdir adump dpdump  pfile
[oracle@bogon db]$
[oracle@bogon oracle]$ cd flash_recovery_area
[oracle@bogon flash_recovery_area]$ ls
[oracle@bogon flash_recovery_area]$ mkdir db

[oracle@bogon app]$ pwd
/u01/app
[oracle@bogon archiv]$ mkdir archiv

第五步,启动B主机数据库到nomount状态
oracle@bogon ~]$ export ORACLE_SID=db
[oracle@bogon ~]$
[oracle@bogon ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 25 23:14:56 2013

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

Connected to an idle instance.

SQL> startup nomount;  
ORACLE instance started.

Total System Global Area  418484224 bytes
Fixed Size                  1336932 bytes
Variable Size             364906908 bytes
Database Buffers           46137344 bytes
Redo Buffers                6103040 bytes

第六步,用rman恢复数据库

[oracle@bogon admin]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Oct 25 23:23:59 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DB (not mounted)

RMAN> set dbid=1587060738;       (备份数据了时的DBID)

executing command: SET DBID

RMAN>

RMAN> restore controlfile from '/u01/app/dbback/config_c-1587060738-20131026-01';

Starting restore at 25-OCT-13
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
output file name=/u01/app/oracle/oradata/db/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/db/control02.ctl
Finished restore at 25-OCT-13

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database from tag='full_gpodb_data';

Starting restore at 25-OCT-13
Starting implicit crosscheck backup at 25-OCT-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 8 objects
Finished implicit crosscheck backup at 25-OCT-13

Starting implicit crosscheck copy at 25-OCT-13
using channel ORA_DISK_1
Finished implicit crosscheck copy at 25-OCT-13

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 00001 to /u01/app/oracle/oradata/db/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/db/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/db/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/db/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/db/anfei01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/db/DB/datafile/o1_mf_dbs_91x4vt9f_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/db/dbt.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/dbback/full_09onbkhv_1_1
channel ORA_DISK_1: piece handle=/u01/app/dbback/full_09onbkhv_1_1 tag=FULL_GPODB_DATA
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:28
Finished restore at 25-OCT-13

RMAN> recover database;

Starting recover at 25-OCT-13
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=22
channel ORA_DISK_1: reading from backup piece /u01/app/dbback/full_0aonbkl1_1_1
channel ORA_DISK_1: piece handle=/u01/app/dbback/full_0aonbkl1_1_1 tag=TAG20131026T052657
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/archiv/1_22_823244933.dbf thread=1 sequence=22
unable to find archived log
archived log thread=1 sequence=23
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/25/2013 23:32:41
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 23 and starting SCN of 1146472

RMAN> alter database open resetlogs;

database opened

RMAN> exit

数据库迁移完成
Recovery Manager complete.

oracle@bogon ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 25 23:14:56 2013

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

Connected to an idle instance.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/db/system01.dbf
/u01/app/oracle/oradata/db/sysaux01.dbf
/u01/app/oracle/oradata/db/undotbs01.dbf
/u01/app/oracle/oradata/db/users01.dbf
/u01/app/oracle/oradata/db/anfei01.dbf
/u01/app/oracle/oradata/db/DB/datafile/o1_mf_dbs_96o3mf4d_.dbf
/u01/app/oracle/oradata/db/dbt.dbf