Oracle 使用RMAN COPY 移动 整个数据库 位置 示例
一.数据迁移说明
在DBA的工作中会遇到数据迁移的情况,比如将本地磁盘迁移到ASM,亦或者需要更换存储设备,那么我就需要迁移整个数据库的存储位置。
如果只是移动表空间或者数据文件,我们可以将表空间或者数据文件offline 之后,移动位置,在用alter database rename 和alter tablespace rename 来将位置的变化写入控制文件即可。
(1)按数据文件来:
1.先将相应的数据文件 offline
ALTER DATABASE DATAFILE 'D:/ORACLE/ORADATA/DBA/TEST01.DBF' OFFLINE;
2.把数据文件 copy 到新位置
3. alter database rename file 'D:/ORACLE/ORADATA/DBA/TEST01.DBF' to 'D:/TEST01.DBF';
4. 介质恢复(offline 数据文件必须要介质恢复)
recover datafile 'D:/TEST01.DBF'
5. 将相应的数据文件 online
SQL>ALTER DATABASE DATAFILE 'D:/TEST01.DBF' ONLINE;
(2)按表空间来:
1.先将相应的表空间 offline
SQL>alter tablespace test offline;
2.把数据文件 copy 到新位置
3. alter tablespace TEST rename datafile 'D:/TEST01.DBF' to 'D:/ORACLE/ORADATA/DBA/TEST01.DBF'
4. 将表空间 online
SQL>alter tablespace test online;
ALTERDATABASE 与 ALTERTABLESPACE OFFLINE的区别
http://blog.csdn.net/tianlesoftware/article/details/4898800
在这里我们演示一下使用RMAN copy迁移整个数据库的操作。 这个操作数据库必须在mount 状态下进行。
二.在Mount 状态下转移整个数据库
如果只是移动数据文件,操作还是比较简单的,步骤和第一节里讲的类似,仅仅是数据库变成了mount状态,我们不需要去offline表空间或者数据文件而已。
如果是整库的转移,我们还需要考虑如下文件位置转移: 数据文件,undo ,Temp,Redo 和控制文件。
1. 移动数据文件位置
1.查看datafile 位置:
SQL> set lin 120
SQL>col file_name for a70
SQL>select file_name from dba_data_files
2 union all
3 select file_name from dba_temp_files;
FILE_NAME
----------------------------------------------------------------------
/u01/app/oracle/oradata/dave/users01.dbf
/u01/app/oracle/oradata/dave/undotbs01.dbf
/u01/app/oracle/oradata/dave/sysaux01.dbf
/u01/app/oracle/oradata/dave/system01.dbf
/u01/app/oracle/oradata/dave/example01.dbf
/u01/app/oracle/oradata/dave/temp01.dbf
6 rows selected.
2.创建一个新目录,用来存放数据文件:
[oracle@dave oradata]$ pwd
/u01/app/oracle/oradata
[oracle@dave oradata]$ mkdir -p/u01/app/oracle/oradata/anqing
[oracle@dave oradata]$ ls
anqing dave
3.编写RMAN 脚本:Rcopy.sh:
这里的copy可以直接敲命令,如果数据文件很多的话,还是建议用脚本,后台来跑。因为这样不会因为连接中断而出现问题,操作也会更安全一些。
#!/bin/ksh
export LANG=en_US
RMAN_LOG_FILE=${0}.out
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_HOME
RMAN=$ORACLE_HOME/bin/rman
export RMAN
ORACLE_SID=dave
export ORACLE_SID
ORACLE_USER=oracle
export ORACLE_USER
echo "ORACLE_SID:$ORACLE_SID">>$RMAN_LOG_FILE
echo"ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE
echo"ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE
echo"==========================">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
$RMAN nocatalog TARGET / msglog$RMAN_LOG_FILE append <<EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
copy datafile'/u01/app/oracle/oradata/dave/users01.dbf' to '/u01/app/oracle/oradata/anqing/users01.dbf';
copy datafile'/u01/app/oracle/oradata/dave/undotbs01.dbf' to'/u01/app/oracle/oradata/anqing/undotbs01.dbf';
copy datafile'/u01/app/oracle/oradata/dave/sysaux01.dbf' to'/u01/app/oracle/oradata/anqing/sysaux01.dbf';
copy datafile '/u01/app/oracle/oradata/dave/system01.dbf'to '/u01/app/oracle/oradata/anqing/system01.dbf';
copy datafile'/u01/app/oracle/oradata/dave/example01.dbf' to'/u01/app/oracle/oradata/anqing/example01.dbf';
copy datafile '/u01/app/oracle/oradata/dave/temp01.dbf' to '/u01/app/oracle/oradata/anqing/temp01.dbf';
/u01/app/oracle/oradata/dave/users01.dbf
release channel c2;
release channel c1;
}
EOF
echo >> $RMAN_LOG_FILE
exit
--赋执行权限:
[oracle@dave u01]$ chmod 755 rcopy.sh
4.将DB 启动到mount 状态:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 818401280 bytes
Fixed Size 2232800 bytes
Variable Size 490737184 bytes
Database Buffers 322961408 bytes
Redo Buffers 2469888 bytes
Database mounted.
5.执行rman copy 脚本:
[oracle@dave u01]$ nohup sh /u01/rcopy.sh>rcopy.out 2>&1 &
[1] 5249
[oracle@dave u01]$ jobs
[1]+ Running nohup sh/u01/rcopy.sh > rcopy.out 2>&1 &
[oracle@dave u01]$ jobs
[1]+ Done nohup sh/u01/rcopy.sh > rcopy.out 2>&1
--确认拷贝:
[root@dave anqing]# ls -lh
total 1.7G
-rw-r----- 1 oracle oinstall 347M Sep 1201:27 example01.dbf
-rw-r----- 1 oracle oinstall 571M Sep 12 01:25sysaux01.dbf
-rw-r----- 1 oracle oinstall 721M Sep 1201:26 system01.dbf
-rw-r----- 1 oracle oinstall 96M Sep 12 01:24 undotbs01.dbf
--注意,这里的temp数据文件并没有copy成功,这个后面在说明.
6. rename 数据文件
还是使用后台操作,脚本rename.sh如下:
#!/bin/ksh
sqlplus / as sysdba<< EOF
alter database rename file'/u01/app/oracle/oradata/dave/users01.dbf' to '/u01/app/oracle/oradata/anqing/users01.dbf';
alter database rename file'/u01/app/oracle/oradata/dave/undotbs01.dbf' to'/u01/app/oracle/oradata/anqing/undotbs01.dbf';
alter database rename file'/u01/app/oracle/oradata/dave/sysaux01.dbf' to'/u01/app/oracle/oradata/anqing/sysaux01.dbf';
alter database rename file'/u01/app/oracle/oradata/dave/system01.dbf' to'/u01/app/oracle/oradata/anqing/system01.dbf';
alter database rename file'/u01/app/oracle/oradata/dave/example01.dbf' to'/u01/app/oracle/oradata/anqing/example01.dbf';
exit
EOF
--给执行权限:
[oracle@dave u01]$ chmod 755 rename.sh
[oracle@dave u01]$ nohup sh rename.sh >rename.out 2>&1 &
7. open 数据库验证
SQL> set lin 120
SQL> col file_name for a70
SQL> select file_name fromdba_data_files
2 union all
3 select file_name fromdba_temp_files;
FILE_NAME
----------------------------------------------------------------------
/u01/app/oracle/oradata/anqing/users01.dbf
/u01/app/oracle/oradata/anqing/undotbs01.dbf
/u01/app/oracle/oradata/anqing/sysaux01.dbf
/u01/app/oracle/oradata/anqing/system01.dbf
/u01/app/oracle/oradata/anqing/example01.dbf
/u01/app/oracle/oradata/dave/temp01.dbf
6 rows selected.
注意这里的temp 表空间,还在原来位置。下面我们来处理temp datafile。
8. 对Temp datafile 处理
我们在第五步copy了temp file,但是实际上并没有copy成功。 RMAN copy 的错误如下:
Starting backup at 12-SEP-12
released channel: c1
released channel: c2
RMAN-00571:===========================================================
RMAN-00569: =============== ERROR MESSAGESTACK FOLLOWS ===============
RMAN-00571:===========================================================
RMAN-03002: failure of backup command at09/12/2012 01:27:20
RMAN-20201: datafile not found in therecovery catalog
RMAN-06010: error while looking updatafile: /u01/app/oracle/oradata/dave/temp01.dbf
RMAN 在备份的时候也不会备份备份locally managed 的tempfiles。原因如下:
1. Locally managed tempfiles are always setto NOLOGGING mode. So thus will have no undo.
2. Extents are managed by bitmap in each datafile to keep track of free or usedstatus of blocks in that datafile.
3. The data dictionary does not manage the tablespace.
4. Rollback information is not generated because there is no update on the datadictionary.
5. Media recovery does not recognize tempfiles.
所以我们这里在copy 数据文件时,不需要copy 临时表空间。只需要在copy 结束后给临时表空间添加一个数据文件,然后把原来目录下的临时文件drop 掉即可。这个是必须的操作,步骤如下:
--这个操作必须在dbopen 状态下执行:
SQL> alter tablespace temp add tempfile'/u01/app/oracle/oradata/anqing/temp01.dbf' size 500M autoextend off;
Tablespace altered.
SQL> alter tablespace temp drop tempfile'/u01/app/oracle/oradata/dave/temp01.dbf';
Tablespace altered.
SQL>
在次验证:
SQL> set lin 120
SQL> col file_name for a70
SQL> select file_name fromdba_data_files
2 union all
3 select file_name fromdba_temp_files;
FILE_NAME
----------------------------------------------------------------------
/u01/app/oracle/oradata/anqing/users01.dbf
/u01/app/oracle/oradata/anqing/undotbs01.dbf
/u01/app/oracle/oradata/anqing/sysaux01.dbf
/u01/app/oracle/oradata/anqing/system01.dbf
/u01/app/oracle/oradata/anqing/example01.dbf
/u01/app/oracle/oradata/anqing/temp01.dbf
6 rows selected.
这次数据文件全部转移成功,只要不进错目录,我们就可以大胆的rm掉之前的数据文件了。
http://blog.csdn.net/tianlesoftware/article/details/4974440
http://blog.csdn.net/tianlesoftware/article/details/4697417
9. 处理Redo log file:
1. 查看Redo 信息:
SQL> set lin 120
SQL> col member for a60
SQL> select group#,type, member fromv$logfile;
GROUP# TYPE MEMBER
---------- -------------------------------------------------------------------
3 ONLINE /u01/app/oracle/oradata/dave/redo03.log
2 ONLINE /u01/app/oracle/oradata/dave/redo02.log
1 ONLINE /u01/app/oracle/oradata/dave/redo01.log
SQL> selectgroup#,thread#,archived,status, bytes/1024/1024 from v$log;
GROUP# THREAD# ARC STATUS BYTES/1024/1024
---------- ---------- --- -------------------------------
1 1 NO CURRENT 50
2 1 NO INACTIVE 50
3 1 NO INACTIVE 50
SQL> select b.group# , b.status ,a.member from v$logfile a , v$log b where a.group# = b.group# order by 1;
GROUP# STATUS MEMBER
---------- ----------------------------------------------------------------------------
1 CURRENT /u01/app/oracle/oradata/dave/redo01.log
2 INACTIVE /u01/app/oracle/oradata/dave/redo02.log
3 INACTIVE /u01/app/oracle/oradata/dave/redo03.log
我们这里的处理方法很简单,给每个group 添加一个redo logfile,然后把旧目录下的logfile drop掉即可。 当然也可以添加几个新组,在把旧组drop掉。
注意的是,我们只能drop inactive 和unused 状态的log file,其他状态不能drop。
操作如下:
--先给每组加个成员:
SQL> alter database add logfile member'/u01/app/oracle/oradata/anqing/redo01.log' to group 1;
Database altered.
SQL> alter database add logfile member'/u01/app/oracle/oradata/anqing/redo02.log' to group 2;
Database altered.
SQL> alter database add logfile member'/u01/app/oracle/oradata/anqing/redo03.log' to group 3;
Database altered.
--验证:
SQL> select b.group# , b.status ,a.member from v$logfile a , v$log b where a.group# = b.group# order by 1;
GROUP#STATUS MEMBER
---------- ----------------------------------------------------------------------------
1 CURRENT /u01/app/oracle/oradata/dave/redo01.log
1 CURRENT /u01/app/oracle/oradata/anqing/redo01.log
2 INACTIVE /u01/app/oracle/oradata/anqing/redo02.log
2 INACTIVE /u01/app/oracle/oradata/dave/redo02.log
3 INACTIVE /u01/app/oracle/oradata/anqing/redo03.log
3 INACTIVE /u01/app/oracle/oradata/dave/redo03.log
6 rows selected.
2. Drop 旧目录的log file:
这里group 1是ACTIVE,我们不能drop,所以我们先drop 2和3,然后switch logfile,在drop group 1。
SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u01/app/oracle/oradata/dave/redo03.log';
Database altered.
SQL> ALTER DATABASE DROP LOGFILE MEMBER'/u01/app/oracle/oradata/dave/redo02.log';
Database altered.
SQL> ALTER DATABASE DROP LOGFILE MEMBER'/u01/app/oracle/oradata/dave/redo01.log';
ALTER DATABASE DROP LOGFILE MEMBER'/u01/app/oracle/oradata/dave/redo01.log'
*
ERROR at line 1:
ORA-01609: log 1 is the current log forthread 1 - cannot drop members
ORA-00312: online log 1 thread 1:'/u01/app/oracle/oradata/dave/redo01.log'
ORA-00312: online log 1 thread 1:'/u01/app/oracle/oradata/anqing/redo01.log'
SQL> alter system switch logfile;
System altered.
SQL> ALTER DATABASE DROP LOGFILE MEMBER'/u01/app/oracle/oradata/dave/redo01.log';
Database altered.
--验证:
SQL> select b.group# , b.status , a.memberfrom v$logfile a , v$log b where a.group# = b.group# order by 1;
GROUP# STATUS MEMBER
---------- ----------------------------------------------------------------------------
1 ACTIVE /u01/app/oracle/oradata/anqing/redo01.log
2 CURRENT /u01/app/oracle/oradata/anqing/redo02.log
3 INACTIVE /u01/app/oracle/oradata/anqing/redo03.log
到这里,redo log 也ok了。还差最后一个,控制文件。
10. 处理控制文件
控制文件的处理很简单,将库shutdown,然后把控制文件copy 到新位置,修改一下pfile参数就ok了。
这里要注意控制文件存放位置问题:
*.control_files='/u01/app/oracle/oradata/dave/control01.ctl','/u01/app/oracle/fast_recovery_area/dave/control02.ctl'
这里是Oracle 11g的配置,这里的控制文件只有2个,其中一个在FRA目录下。 而在Oracle 10g中,会有三个控制文件,他们都在一个目录下面。
SQL> create pfile from spfile;
File created.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@dave dave]$ ls
control01.ctl redo01.log redo03.log system01.dbf users01.dbf
example01.dbf redo02.log sysaux01.dbf undotbs01.dbf
[oracle@dave dave]$ cp control01.ctl../anqing
[oracle@dave dave]$ cd ..
[oracle@dave oradata]$ cd anqing
[oracle@dave anqing]$ ls
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
SQL> create spfile frompfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initdave.ora';
File created.
SQL> startup
ORACLE instance started.
Total System Global Area 818401280 bytes
Fixed Size 2232800 bytes
Variable Size 490737184 bytes
Database Buffers 322961408 bytes
Redo Buffers 2469888 bytes
Database mounted.
Database opened.
SQL> show parameter control_files
NAME TYPE VALUE
----------------------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/anqing
/control01.ctl, /u01/app/oracl
e/fast_recovery_area/dave/cont
rol02.ctl
至此,整个使用RMAN copy 转移整个数据库操作结束。 现在我们可以大胆的rm 掉之前的目录了。
[oracle@dave oradata]$ pwd
/u01/app/oracle/oradata
[oracle@dave oradata]$ ls
anqing dave
[oracle@dave oradata]$ rm -rf dave
[oracle@dave oradata]$ ls
anqing
转:http://www.cnblogs.com/tianlesoftware/archive/2012/03/07/3609339.html
Oracle 使用RMAN COPY 移动 整个数据库 位置 示例的更多相关文章
- Oracle下rman备份和还原到数据库任意一个时间点
Rman备份为物理备份,启用rman备份必须开启数据库归档,开启归档后相当于给数据库加了一层双保险.Rman备份主要备份数据库的数据文件,控制文件,归档日志. RMAN 备份 一. 检查数据库是否启用 ...
- 【Oracle】 RMAN命令汇总
RMAN命令汇总 2013年写了关于RMAN命令的汇总,先转换为MD文档,温故而知新. 1.进入RMAN 进入本地数据库 [oracle@oracle-n1 ~]$ rman target / 进入远 ...
- Oracle 11g R2 RAC with ASM存储迁移--Rman copy&ASM Rebalance(一)
ASM GROUP-Rman copy迁移 0x00--环境介绍 VMware版本:VMware12pro 主机操作系统:RHEL6.5_64 共享存储使用VMWARE创建共享磁盘文件 数据库版本:O ...
- Oracle 11G RAC For ASM 利用RMAN COPY进行存储迁移
转载请注明出处 一.需求背景 客户数据库存储空间接近存满,需购置一台新的存储,进行数据迁移,客户允许少量停机时间. 二.实施方法讨论 利用ASM rebalance 进行迁移 可以实现0宕机进行迁移, ...
- 基于RMAN的异机数据库克隆(rman duplicate)
对于基于生产环境下的数据库的版本升级或者测试新的应用程序的性能及其影响,备份恢复等等,我们可以采取从生产环境以克隆的方式将其克隆到本地而不影响生产数据库的正常使用.实现这个功能我们可以借助rman d ...
- ORACLE的RMAN
1.什么是RMAN? RMAN可以用来备份和还原数据库文件.归档日志和控制文件.它也可以用来执行完全或不完全的数据库恢复. 注意:RMAN不能用于备份初始化参数文件和口令文件. RMAN启动数据库上的 ...
- Oracle 使用RMAN进行备份
备份理论和基本语法 备份概念 执行备份或还原草的数据库称为目标.在一些环境下,有许多数据库,因此有许多RMAN目标.应一次连接每个数据库.目标的每个备份都有一些属性: 打开或关闭 完整或部分 完整或增 ...
- Oracle之RMAN备份及还原
RMAN可以进行增量备份:数据库,表空间,数据文件 只有使用过的block可以被备份成backup set 表空间与数据文件对应关系:dba_data_files / v$datafile_heade ...
- oracle之三rman 不完全恢复
rman 不完全恢复 9.1 rman 不完全恢复的三个标准模式:基于time.基于scn和基于sequence: 范例1:恢复过去某个时间点误操作,一般使用基于time或scn. 1)环境:有一套全 ...
随机推荐
- 设计模式--装饰模式C++实现
装饰模式C++实现 1定义 动态地给一个对象添加一些额外的职责.就增加功能来说,装饰模式比生成子类更加灵活.可作为继承的替代 2类图 3实现 //构件 class Component { protec ...
- Qt5.3中qml ApplicationWindow设置窗口无边框问题
这个版本的qt在这里有点bug.. 设置ApplicationWindow的flags属性为Qt.FramelessWindowHint的确可以使程序无边框,但是同时程序在任务栏的图标也没了. 看文档 ...
- TCP的time_wait、close_wait状态
转载:http://huoding.com/2013/12/31/316 http://blog.csdn.net/lxnkobe/article/details/7525317 http://k ...
- hdu 1517 A Multiplication Game 段sg 博弈 难度:0
A Multiplication Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- bzoj3623
题解: 刚看到题目,还以为是2-sat 可是似乎不对啊... 然后就只能爆搜了 看了网上的题解,woc还真是报搜 然后就ac了 当然爆搜还要随机化 代码: #include<bits/stdc+ ...
- Linux下的ASLR(PIE)内存保护机制
1.1 Linux下的ASLR内存保护机制 1.1.1 Linux下的ASLR工作原理 工作原理与window下的aslr类似 1.1.2 Linux下利用内存地址泄露绕过ASLR ⑴. ...
- python爬取商品信息
老严要爬某网购网站的商品信息,正好我最近在学python,就一起写了一个简单的爬虫程序. 需求:某网的商品信息,包括商品名,市场价和售价 工具:python2.7.8,urllib2,re #codi ...
- WAF的实现
文章来源:http://danqingdani.blog.163.com/blog/static/1860941952014101723845500/ 本篇文章从WAF产品研发的角度来YY如何实现一款 ...
- Http权威指南(服务器、缓存)
对于web服务器(软件)大家应该不会陌生,常见的web服务器有Apache.IIS.Tomcat.Nginx.Jetty等等. 1.基本功能 几乎所有的web服务器都会执行以下几项同样的任务: 1.建 ...
- CUDA Samples: Julia
以下CUDA sample是分别用C++和CUDA实现的绘制Julia集曲线,并对其中使用到的CUDA函数进行了解说,code参考了<GPU高性能编程CUDA实战>一书的第四章,各个文件内 ...