大家好,我又来了。再来一篇关于rman数据迁移的,不过这一篇和前一篇不同,这一篇模拟的是生产环境中既更换主机也更换存储的情景。既然选择用rman做,当然就要求更换前后主机平台硬件和操作系统都不变。关于异构平台的数据迁移手段,用不了rman,怎么做后续会有帖子推出。
闲话不说,这里准备环境为两台相同操作系统linux虚拟机,一台已经安装好数据库软件并且建好库,另一台只是安装了和前一台相同版本的数据库软件,没有建库。我们的目的就是将前一台的数据库迁移到后一台机器上。如果是生产环境迁移主机,也是在新主机上安装好rdbms软件,然后想办法用新主机的oracle软件拉起原来的库。具体步骤如下:
这里我们从ora10g1主机迁移到ora10g2主机,相同版本的数据库软件已经在ora10g2安装好。
1.先在ora10g1上对数据库做个rman全备
备份脚本如下:
run
{allocate channel c1 type disk;
allocate channel c2 type disk;
backup filesperset 3 database format '/oracle/rmanTransData/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 '/oracle/rmanTransData/arch_%d_%s_%p';
backup current controlfile format '/oracle/rmanTransData/ctl_%d_%s_%p';
}
删除过期的归档:
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
2.将全备传输到新主机的新存储
[oracle@ora10g1 rmanTransData]$ ls -ltr
total 371692
-rw-r----- 1 oracle oinstall 156966912 Sep 27 12:18 full_ORCL_20140927_179_1
-rw-r----- 1 oracle oinstall 213082112 Sep 27 12:18 full_ORCL_20140927_180_1
-rw-r----- 1 oracle oinstall 98304 Sep 27 12:18 full_ORCL_20140927_182_1
-rw-r----- 1 oracle oinstall 2371584 Sep 27 12:19 arch_ORCL_185_1
-rw-r----- 1 oracle oinstall 7700480 Sep 27 12:19 ctl_ORCL_186_1
[oracle@ora10g1 rmanTransData]$ scp * ora10g2:/oracle/rmanTransData
oracle@ora10g2's password:
arch_ORCL_185_1 100% 2316KB 2.3MB/s 00:00
ctl_ORCL_186_1 100% 7520KB 7.3MB/s 00:00
full_ORCL_20140927_179_1 100% 150MB 29.9MB/s 00:05
full_ORCL_20140927_180_1 100% 203MB 25.4MB/s 00:08
full_ORCL_20140927_182_1 100% 96KB 96.0KB/s 00:00
3.在源端创建一个pfile传输到目标端:
SQL> create pfile='/tmp/dba.txt' from spfile;
File created.
SQL> !
[oracle@ora10g1 rmanTransData]$ scp /tmp/dba.txt ora10g2:/oracle/rmanTransData/
oracle@ora10g2's password:
dba.txt 100% 983 1.0KB/s 00:00
[oracle@ora10g1 rmanTransData]$
4.在目标端修改源端传输过来的参数文件
a.删除内存参数部分:
orcl.__db_cache_size=260046848
orcl.__java_pool_size=159383552
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=159383552
orcl.__streams_pool_size=8388608
b.修改控制文件位置为:
源位置:
*.control_files='/oradata/orcl/control01.ctl','/oradata/orcl/control02.ctl','/oradata/orcl/control03.ctl'
新位置:
*.control_files='/oracle/oradata/control01.ctl','/oracle/oradata/control02.ctl','/oracle/oradata/control03.ctl'
c.归档路径变一下,新路径为:
.log_archive_dest_1='location=/oracle/arch'
5.然后目标端登录sqlplus创建spfile文件:
[oracle@ora10g2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sat Sep 27 12:50:40 2014
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> create spfile from pfile='/oracle/rmanTransData/dba.txt';
File created.
SQL>
6.目标端启动数据库到nomount状态:
SQL> create spfile from pfile='/oracle/rmanTransData/dba.txt';
File created.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 599785472 bytes
Fixed Size 2098112 bytes
Variable Size 322964544 bytes
Database Buffers 268435456 bytes
Redo Buffers 6287360 bytes
SQL>
7.目标端登录rman复原控制文件:
[oracle@ora10g2 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Sat Sep 27 12:58:37 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: orcl (not mounted)
RMAN> restore controlfile from '/oracle/rmanTransData/ctl_ORCL_186_1';
Starting restore at 27-SEP-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/oracle/oradata/control01.ctl
output filename=/oracle/oradata/control02.ctl
output filename=/oracle/oradata/control03.ctl
Finished restore at 27-SEP-14
RMAN>
8.目标端mount数据库:
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN>
9.源端查出数据文件编写rman脚本恢复数据文件到新的位置:
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/oradata/orcl/system01.dbf
/oradata/orcl/undotbs01.dbf
/oradata/orcl/sysaux01.dbf
/oradata/orcl/users01.dbf
/oracle/appdata/datafiles/apptab.dbf
编辑成以下脚本:
set newname for datafile '/oradata/orcl/system01.dbf' to '/oracle/oradata/system01.dbf' ;
set newname for datafile '/oradata/orcl/undotbs01.dbf' to '/oracle/oradata/undotbs01.dbf';
set newname for datafile '/oradata/orcl/sysaux01.dbf' to '/oracle/oradata/sysaux01.dbf' ;
set newname for datafile '/oradata/orcl/users01.dbf' to '/oracle/oradata/users01.dbf' ;
set newname for datafile '/oracle/appdata/datafiles/apptab.dbf' to '/oracle/oradata/apptab.dbf' ;
注意,如果有新目录,要创建好新目录。
10.目标端rman恢复数据文件:
run
{allocate channel c1 type disk;
allocate channel c2 type disk;
set newname for datafile '/oradata/orcl/system01.dbf' to '/oracle/oradata/system01.dbf' ;
set newname for datafile '/oradata/orcl/undotbs01.dbf' to '/oracle/oradata/undotbs01.dbf';
set newname for datafile '/oradata/orcl/sysaux01.dbf' to '/oracle/oradata/sysaux01.dbf' ;
set newname for datafile '/oradata/orcl/users01.dbf' to '/oracle/oradata/users01.dbf' ;
set newname for datafile '/oracle/appdata/datafiles/apptab.dbf' to '/oracle/oradata/apptab.dbf' ;
restore database;
}
RMAN>
完成后数据文件复原到新存储的新位置了:
[root@ora10g2 oradata]# ls -ltr
total 3275612
-rw-r----- 1 oracle oinstall 125837312 Sep 27 13:18 sysaux01.dbf
-rw-r----- 1 oracle oinstall 2001477632 Sep 27 13:20 users01.dbf
-rw-r----- 1 oracle oinstall 524296192 Sep 27 13:20 apptab.dbf
-rw-r----- 1 oracle oinstall 314580992 Sep 27 13:20 system01.dbf
-rw-r----- 1 oracle oinstall 361766912 Sep 27 13:20 undotbs01.dbf
-rw-r----- 1 oracle oinstall 7651328 Sep 27 13:21 control03.ctl
-rw-r----- 1 oracle oinstall 7651328 Sep 27 13:21 control02.ctl
-rw-r----- 1 oracle oinstall 7651328 Sep 27 13:21 control01.ctl
[root@ora10g2 oradata]#
11.改改控制文件中数据文件的路径信息
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oradata/orcl/system01.dbf
/oradata/orcl/undotbs01.dbf
/oradata/orcl/sysaux01.dbf
/oradata/orcl/users01.dbf
/oracle/appdata/datafiles/apptab.dbf
SQL>
此时目标端控制文件中数据文件的路径信息还是原来的,目标端运行以下脚本:
alter database rename file '/oradata/orcl/system01.dbf' to '/oracle/oradata/system01.dbf';
alter database rename file '/oradata/orcl/undotbs01.dbf' to '/oracle/oradata/undotbs01.dbf';
alter database rename file '/oradata/orcl/sysaux01.dbf' to '/oracle/oradata/sysaux01.dbf';
alter database rename file '/oradata/orcl/users01.dbf' to '/oracle/oradata/users01.dbf';
alter database rename file '/oracle/appdata/datafiles/apptab.dbf' to '/oracle/oradata/apptab.dbf';
12.目标端恢复数据库:
RMAN> recover database;
Starting recover at 27-SEP-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
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=86
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=87
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=88
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=89
channel ORA_DISK_1: reading from backup piece /oracle/rmanTransData/arch_ORCL_185_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/rmanTransData/arch_ORCL_185_1 tag=TAG20140927T121900
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/oracle/arch/dbname_1_86_858711861.arc thread=1 sequence=86
archive log filename=/oracle/arch/dbname_1_87_858711861.arc thread=1 sequence=87
archive log filename=/oracle/arch/dbname_1_88_858711861.arc thread=1 sequence=88
archive log filename=/oracle/arch/dbname_1_89_858711861.arc thread=1 sequence=89
unable to find archive log
archive log thread=1 sequence=90
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/27/2014 13:29:19
RMAN-06054: media recovery requesting unknown log: thread 1 seq 90 lowscn 3572639
RMAN>
13.在源端停止监听:
lsnrctl stop
14.源端杀掉非local连接:
kill -9 `ps -ef|grep LOCAL=NO|awk '{print $2}'`
查看是否还有非local连接:
ps -ef |grep LOCAL=NO
15.在源端做点数据变更并切一下归档:
SQL> create table abc as select * from dba_objects;
Table created.
SQL> alter system archive log current;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL>
查看归档日志又产生了4个:
-rw-r----- 1 oracle oinstall 1835008 Sep 27 13:38 dbname_1_90_858711861.arc
-rw-r----- 1 oracle oinstall 1024 Sep 27 13:38 dbname_1_91_858711861.arc
-rw-r----- 1 oracle oinstall 1536 Sep 27 13:38 dbname_1_92_858711861.arc
-rw-r----- 1 oracle oinstall 1024 Sep 27 13:38 dbname_1_93_858711861.arc
16.将新产生的归档传输到目标端recover:
RMAN> recover database;
Starting recover at 27-SEP-14
using channel ORA_DISK_1
starting media recovery
archive log filename=/oracle/arch/dbname_1_90_858711861.arc thread=1 sequence=90
archive log filename=/oracle/arch/dbname_1_91_858711861.arc thread=1 sequence=91
archive log filename=/oracle/arch/dbname_1_92_858711861.arc thread=1 sequence=92
archive log filename=/oracle/arch/dbname_1_93_858711861.arc thread=1 sequence=93
archive log filename=/oracle/arch/dbname_1_93_858711861.arc thread=1 sequence=94
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/27/2014 13:42:26
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/oracle/arch/dbname_1_93_858711861.arc'
ORA-00310: archived log contains sequence 93; sequence 94 required
ORA-00334: archived log: '/oracle/arch/dbname_1_93_858711861.arc'
17.然后目标端以只读模式打开,查看刚才的测试表是否传输过来了:
SQL> alter database open read only;
Database altered.
SQL> select count(*) from abc;
COUNT(*)
----------
10084
SQL>
表已经过来了。重新正常mount库。
shutdown immediate;
startup mount;
18.更改控制文件中redo的路径:
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oradata/orcl/redo01.log
/oradata/orcl/redo02.log
/oradata/orcl/redo03.log
SQL>
执行以下脚本:
alter database rename file '/oradata/orcl/redo01.log' to '/oracle/oradata/redo01.log';
alter database rename file '/oradata/orcl/redo02.log' to '/oracle/oradata/redo02.log';
alter database rename file '/oradata/orcl/redo03.log' to '/oracle/oradata/redo03.log';
SQL> alter database rename file '/oradata/orcl/redo01.log' to '/oracle/oradata/redo01.log';
alter database rename file '/oradata/orcl/redo02.log' to '/oracle/oradata/redo02.log';
alter database rename file '/oradata/orcl/redo03.log' to '/oracle/oradata/redo03.log';
Database altered.
SQL>
Database altered.
SQL>
Database altered.
SQL>
19.目标端resetlogs方式打开库:
SQL> alter database open resetlogs;
Database altered.
SQL>
迁移完毕。然后立刻全备数据库。
20.需要注意的地方:
rman恢复的时候如有必要需要手动注册备份片到控制文件:
catalog backuppiece '/oracle/rmanTransData/full_ORCL_20140926_172_1';
rman恢复的时候如有必要需要手动注册归档到控制文件:
catalog archivelog '/oracle/rmanTransData/dbname_1_71_858711861.arc';
该贴由system转至本版2014-11-19 9:34:59