[原创]一点一点学ORACLE_数据迁移之用RMAN迁移数据_001[原创]_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2327 | 回复: 0   主题: [原创]一点一点学ORACLE_数据迁移之用RMAN迁移数据_001[原创]        下一篇 
    本主题由 Administrator 于 2014-11-19 9:35:00 移动
tengfei.dong
注册用户
等级:中尉
经验:461
发帖:15
精华:0
注册:1970-1-1
状态:离线
发送短消息息给tengfei.dong 加好友    发送短消息息给tengfei.dong 发消息
发表于: IP:您无权察看 2014-11-13 14:24:45 | [全部帖] [楼主帖] 楼主

大家好!本人刚来此论坛,发点oracle的帖子赚赚人气,欢迎大牛高手拍砖斧正!

关于RMAN,理论的东西先暂且不说了,终归要回到实践,主要用来做数据备份恢复,当然在特定情况下(相同平台)可用来做数据迁移。今天就演示一个利用RMAN在相同平台之间做数据迁移,类似于生产环境中主机不变,只更换存储的case。

此案例的环境是在linux虚拟机上做的,oracle版本为10g,可能与生产环境有些具体细节出入,但大概原理都基本不变,其核心原理是利用RMAN的copy。由于是模拟case,我们的目的是把所有的数据从一个目录上迁移至一个新目录,如果是在生产环境,换存储的话,也只是将目录改变成新存储的路径而已,具体步骤如下:

1.执行RMAN脚本RMAN_COPY.sh:

rman target / log /tmp/rman.log <<EOF
run
{
      allocate channel c1 type disk;
      allocate channel c2 type disk;
      allocate channel c3 type disk;
      copy
      datafile '/oracle/oradata/system01.dbf' to '/oracle/rmanTransData2/system01.dbf',
      datafile '/oracle/oradata/undotbs01.dbf' to '/oracle/rmanTransData2/undotbs01.dbf',
      datafile '/oracle/oradata/sysaux01.dbf' to '/oracle/rmanTransData2/sysaux01.dbf',
      datafile '/oracle/oradata/users01.dbf' to '/oracle/rmanTransData2/users01.dbf',
      datafile '/oracle/oradata/apptab.dbf' to '/oracle/rmanTransData2/apptab.dbf';
}
EOF
--查看所有数据文件
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oracle/oradata/system01.dbf
/oracle/oradata/undotbs01.dbf
/oracle/oradata/sysaux01.dbf
/oracle/oradata/users01.dbf
/oracle/oradata/apptab.dbf
SQL>


2.copy完如下,然后copy控制文件:

[oracle@ora10g2 oracle]$ cd rmanTransData2
[oracle@ora10g2 rmanTransData2]$ ls
apptab.dbf sysaux01.dbf system01.dbf undotbs01.dbf users01.dbf
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/oracle/oradata/control01.ctl
/oracle/oradata/control02.ctl
/oracle/oradata/control03.ctl
[oracle@ora10g2 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Sat Sep 27 15:21:34 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1382672391)
RMAN> copy current controlfile to '/oracle/rmanTransData2/control01.ctl';
Starting backup at 27-SEP-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=141 devtype=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=/oracle/rmanTransData2/control01.ctl tag=TAG20140927T152323 recid=39 stamp=859389804
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 27-SEP-14
RMAN>


将control01.ctl利用cp命令原模原样复制两份control02.ctl和control03.ctl:

[oracle@ora10g2 rmanTransData2]$ ls -ltr
total 3260644
-rw-r----- 1 oracle oinstall 361766912 Sep 27 15:13 undotbs01.dbf
-rw-r----- 1 oracle oinstall 524296192 Sep 27 15:14 apptab.dbf
-rw-r----- 1 oracle oinstall 314580992 Sep 27 15:14 system01.dbf
-rw-r----- 1 oracle oinstall 125837312 Sep 27 15:14 sysaux01.dbf
-rw-r----- 1 oracle oinstall 2001477632 Sep 27 15:15 users01.dbf
-rw-r----- 1 oracle oinstall 7651328 Sep 27 15:23 control01.ctl
[oracle@ora10g2 rmanTransData2]$ cp control01.ctl control02.ctl
[oracle@ora10g2 rmanTransData2]$ cp control01.ctl control03.ctl
[oracle@ora10g2 rmanTransData2]$ ls -ltr
total 3275612
-rw-r----- 1 oracle oinstall 361766912 Sep 27 15:13 undotbs01.dbf
-rw-r----- 1 oracle oinstall 524296192 Sep 27 15:14 apptab.dbf
-rw-r----- 1 oracle oinstall 314580992 Sep 27 15:14 system01.dbf
-rw-r----- 1 oracle oinstall 125837312 Sep 27 15:14 sysaux01.dbf
-rw-r----- 1 oracle oinstall 2001477632 Sep 27 15:15 users01.dbf
-rw-r----- 1 oracle oinstall 7651328 Sep 27 15:23 control01.ctl
-rw-r----- 1 oracle oinstall 7651328 Sep 27 15:24 control02.ctl
-rw-r----- 1 oracle oinstall 7651328 Sep 27 15:24 control03.ctl
[oracle@ora10g2 rmanTransData2]$


3.create一个pfile dba.ora更改一下控制文件路径参数:

SQL> create pfile='/tmp/dba.ora' from spfile;
File created.
SQL> !


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/rmanTransData2/control01.ctl','/oracle/rmanTransData2/control02.ctl','/oracle/rmanTransData2/control03.ctl'


c.生产中还可以更改归档路径,这里就不做更改了。

d.由于是在一台机器上做实验,在参数文件中加一个参数instance_name以便以新的实例拉起库。

*.instance_name=dba


e.还需要加一个参数db_unique_name=dba才能mount数据。

*.db_unique_name=dba


否则会报如下错误:

SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-01102: cannot mount database in EXCLUSIVE mode
SQL>


4.拉起新的实例:

[oracle@ora10g2 ~]$ export ORACLE_SID=dba
[oracle@ora10g2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sat Sep 27 15:40:16 2014
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> startup mount pfile='/tmp/dba.ora';
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
Database mounted.
SQL>


5.rman recover 数据库:

[oracle@ora10g2 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Sat Sep 27 15:41:31 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1382672391, not open)
RMAN> recover database;
Starting recover at 27-SEP-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
starting media recovery
media recovery failed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/27/2014 15:42:23
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover if needed
start until cancel using backup controlfile
ORA-00283: recovery session canceled due to errors
ORA-01110: data file 1: '/oracle/oradata/system01.dbf'
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/oracle/oradata/system01.dbf'
RMAN>
--以上是控制文件中数据文件地址还指向原先的位置,运行以下脚本更改控制文件中数据文件新指向:
alter database rename file '/oracle/oradata/system01.dbf' to '/oracle/rmanTransData2/system01.dbf';
alter database rename file '/oracle/oradata/undotbs01.dbf' to '/oracle/rmanTransData2/undotbs01.dbf';
alter database rename file '/oracle/oradata/sysaux01.dbf' to '/oracle/rmanTransData2/sysaux01.dbf';
alter database rename file '/oracle/oradata/users01.dbf' to '/oracle/rmanTransData2/users01.dbf';
alter database rename file '/oracle/oradata/apptab.dbf' to '/oracle/rmanTransData2/apptab.dbf';
--然后继续recover database就没有问题了:
[oracle@ora10g2 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Sat Sep 27 15:48:14 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1382672391, not open)
RMAN> recover database;
Starting recover at 27-SEP-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
starting media recovery
archive log thread 1 sequence 1 is already on disk as file /oracle/oradata/redo01.log
archive log filename=/oracle/oradata/redo01.log thread=1 sequence=1
media recovery complete, elapsed time: 00:00:02
Finished recover at 27-SEP-14
RMAN>


5.一端以实例orcl登录切归档,一端以dba实例登录recover database(因为两个实例的归档路径一样,就省了传输归档的步骤)

实例orcl:

SQL> alter system archive log current;
System altered.
SQL> /
System altered.
SQL> /


实例dba:

RMAN> recover database;
Starting recover at 27-SEP-14
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 5 is already on disk as file /oracle/oradata/redo02.log
archive log thread 1 sequence 6 is already on disk as file /oracle/oradata/redo03.log
archive log thread 1 sequence 7 is already on disk as file /oracle/oradata/redo01.log
archive log filename=/oracle/arch/dbname_1_1_859384371.arc thread=1 sequence=1
media recovery complete, elapsed time: 00:00:03
Finished recover at 27-SEP-14


6.实例orcl停监听,杀掉非local连接,

lsnrctl stop
lsnrctl status
kill -9 `ps -ef|grep LOCAL=NO|awk '{print $2}'`
ps -ef |grep LOCAL=NO


然后还是实例orcl切归档:

alter system archive log current;


然后实例dba recover 数据库。

7.更改控制文件中redo的路径为新路径:

SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oracle/oradata/redo01.log
/oracle/oradata/redo02.log
/oracle/oradata/redo03.log
SQL>


连接实例dba运行以下脚本:

alter database rename file '/oracle/oradata/redo01.log' to '/oracle/rmanTransData2/redo01.log';
alter database rename file '/oracle/oradata/redo02.log' to '/oracle/rmanTransData2/redo02.log';
alter database rename file '/oracle/oradata/redo03.log' to '/oracle/rmanTransData2/redo03.log';


8.resetlogs方式打开库(dba实例连的):

SQL> alter database open resetlogs;
Database altered.
SQL>


9.创建临时表空间和数据文件:

dba实例连接的库还没有数据文件:

SQL> select file_name from dba_temp_files;
select file_name from dba_temp_files
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/oradata/orcl/temp01.dbf'
SQL>


给临时表空间添加一个数据文件:

alter tablespace temp add tempfile '/oracle/rmanTransData2/temp01.dbf' size 10m;


10.关闭orcl库。

export ORACLE_SID=orcl
sqlplus / as sysdba
shutdown immediate;


11.关闭dba连接的库:

shudown immediate;


12.修改参数文件/tmp/dba.ora,删掉参数:

*.instance_name=dba
*.db_unique_name=dba


然后启动数据库:

[oracle@ora10g2 ~]$ echo $ORACLE_SID
dba
[oracle@ora10g2 ~]$ export ORACLE_SID=orcl
[oracle@ora10g2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sat Sep 27 16:27:35 2014
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> create spfile from pfile='/tmp/dba.ora';
File created.
SQL> startup
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
Database mounted.
Database opened.
SQL>


至此,实验结束,数据迁移,是不是很简单?生产环境做数据迁移,只是数据量大了一点而已,原理都一样。这里由于实在一台机器上做的,因此有个添加临时实例名的环节。

该贴由system转至本版2014-11-19 9:35:00




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论