点击蓝字 关注我们

准备工作
源数据库必须开启归档模式
---创建迁移文件保存路径
mkdir oracle/oradata/orcl
sqlplus / as sysdba
sys@ORCL> select name from v$datafile;
NAME
------------------------------
/oradata/orcl/system01.dbf
/oradata/orcl/sysaux01.dbf
/oradata/orcl/undotbs01.dbf
/oradata/orcl/users01.dbf
sys@ORCL> set linesize 300
sys@ORCL> set pagesize 9999
sys@ORCL> col file_name for a60
sys@ORCL> select file_id,file_name from dba_data_files order by 1;
FILE_ID FILE_NAME
---------- ------------------------------------------------------------
1 /oradata/orcl/system01.dbf
2 /oradata/orcl/sysaux01.dbf
3 /oradata/orcl/undotbs01.dbf
4 /oradata/orcl/users01.dbf
----to的位置为新保存地址(源数据库处于mount)
-------17服务器执行------
rman target /
copy datafile 1 to '/oracle/oradata/orcl/system01.dbf';
copy datafile 2 to '/oracle/oradata/orcl/sysaux01.dbf';
copy datafile 3 to '/oracle/oradata/orcl/undotbs01.dbf';
copy datafile 4 to '/oracle/oradata/orcl/users01.dbf';
copy datafile 5to '/oracle/oradata/orcl/zhjk_gxgs.dbf';
copy datafile 6to '/oracle/oradata/orcl/system02.dbf';
copy datafile 7to '/oracle/oradata/orcl/zhjk_gxgs001.dbf';
copy datafile 8to '/oracle/oradata/orcl/zhjk_gxgs002.dbf';
copy datafile 9to '/oracle/oradata/orcl/system_01.dbf';
copy datafile 10 to '/oracle/oradata/orcl/sysaux)01.dbf';
----------22服务器执行-----
rman target /
copy datafile 1 to '/oracle/oradata/orcl/system01.dbf';
copy datafile 2 to '/oracle/oradata/orcl/sysaux01.dbf';
copy datafile 3 to '/oracle/oradata/orcl/undotbs01.dbf';
copy datafile 4 to '/oracle/oradata/orcl/users01.dbf';
copy datafile 5to '/oracle/oradata/orcl/zhjk_gxgs.dbf';
copy datafile 6to '/oracle/oradata/orcl/system02.dbf';
copy datafile 7to '/oracle/oradata/orcl/zhjk_gxgs001.dbf';
copy datafile 8to '/oracle/oradata/orcl/zhjk_gxgs002.dbf';
copy datafile 9to '/oracle/oradata/orcl/system_01.dbf';
copy datafile 10 to '/oracle/oradata/orcl/sysaux)01.dbf';
---------------------------
rman target /
RMAN> copy current controlfile to '/oracle/oradata/orcl/control01.ctl'; ----to的位置为新保存地址
cp /oradata/orcl/control01.ctl /oradata/orcl/control02.ctl------用控制文件1,复制一个控制文件2
为了迁移,临时启动一个实例:
sys@ORCL> create pfile='/tmp/pfile.txt' from spfile;
添加
*.instance_name=orclt
*.db_unique_name=orclt
export ORACLE_SID=orclt
---------------------没有就要创建------
修改dump目录到orcl(针对于部分迁移中没有创建对应实例,需重建创建)
创建dump目录
rm -rf $ORACLE_BASE/admin/$ORACLE_SID
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/bdump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/cdump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/dpdump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/udump
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/pfile
chmod -R 750 $ORACLE_BASE/admin
---------------------------------------------
将数据库启动到mount阶段
startup mount pfile='/oracle/app/oracle/prouduct/11.2.0/db_1/dbs/initorclt.ora';
查看控制文件,数据文件,临时文件,redo成员
sys@ORCL> select name from v$controlfile;
sys@ORCL> select name from v$datafile;
sys@ORCL> select name from v$tempfile;
sys@ORCL> select member from v$logfile;
修改控制文件中数据文件
rman target / <<EOF
RMAN> switch database to copy;
EOF
或者
select 'alter database rename file '||''''||name||''''||' to '||''''||name||''''||';' from v$datafile;
alter database rename file '/oradata/orcl/system01.dbf' to '/oracle/oradata/orcl/system01.dbf';
alter database rename file '/oradata/orcl/sysaux01.dbf' to '/oracle/oradata/orcl/sysaux01.dbf';
alter database rename file '/oradata/orcl/undotbs01.dbf' to '/oracle/oradata/orcl/undotbs01.dbf';
alter database rename file '/oradata/orcl/users01.dbf' to '/oracle/oradata/orcl/users01.dbf';
----修改控制文件中临时文件位置
sys@ORCL> select 'alter database rename file '||''''||name||''''||' to '||''''||name||''''||';' from v$tempfile;
'ALTERDATABASERENAMEFILE'||''''||NAME||''''||'TO'||''''||NAME||''''||';'
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
alter database rename file '/database/orcl/temp01.dbf' to '/oracle/orcl/temp01.dbf';
alter database rename file '/oracle/ordata/orcl/temp01.dbf' to '/oracle/orcl/temp01.dbf';
alter database rename file '/database/orcl/temp01.dbf' to '/oracle/orcl/temp01.dbf';
alter database rename file '/oradata/orcl/temp01.dbf' to '/oracle/oradata/orcl/temp01.dbf';
-----修改redo.log 位置
sys@ORCL> select 'alter database rename file '||''''||member||''''||' to '||''''||member||''''||';' from v$logfile;
'ALTERDATABASERENAMEFILE'||''''||MEMBER||''''||'TO'||''''||MEMBER||''''||';'
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
alter database rename file '/oracle/ordata/orcl/redo03.log' to '/oracle/ordata/orcl/redo03.log';
alter database rename file '/oracle/ordata/orcl/redo02.log' to '/oracle/ordata/orcl/redo02.log';
alter database rename file '/oracle/ordata/orcl/redo01.log' to '/oracle/ordata/orcl/redo01.log';
alter database rename file '/oracle/ordata/orcl/redo03.log' to '/oradata/orcl/redo03.log';
alter database rename file '/oracle/ordata/orcl/redo02.log' to '/oracle/orcl/redo02.log';
alter database rename file '/oracle/ordata/orcl/redo01.log' to '/oracle/orcl/redo01.log';
源库切归档,模拟生产在运行状态,数据库有变化,会生成新的归档。
alter system archive log current;
/
/
/
目标库追加归档,隔一段时间就要追加一次,一直到生产可以停机
export ORACLE_SID=orclt
rman target /
recover database;
当可以停机的时候
停应用
关闭监听
kill LOCAL=NO 的进程
暂时先不要关闭源数据库
将最后的日志切到归档里
alter system archive log current;
/
/
/
目标库再次追加归档
export ORACLE_SID=orclt
rman target /
recover database;
将目标库利用open resetlogs 打开
alter database open resetlogs;
关闭源库
创建新的spfile指向新的存储位置的控制文件
删除添加的
*.instance_name=orclt
*.db_unique_name=orclt
重新创建新的参数文件指向新存储里的控制文件
使用原来的ORACLE_SID=orcl
重新打开新库




长按识别二维码关注我们