windows环境
oracle 10.2.0.1
源库:192.168.1.81
目标库:192.168.1.2
主要流程:
停止源库->备份->恢复->改数据文件位置->resetlogs打开
迁移数据库81 到192.168.1.2上
停81库,设置归档路径,将其启动到归档模式,
以administrator身份启动数据库服务oracleserviceorcl
备份测试C:\>set oracle_sid=orcl
C:\>rman target /
RMAN> backup current controlfile format '\\192.168.1.2\oradata\81\cf_%U';
全备
run {
backup as compressed backupset database
format '\\192.168.1.2\oradata\81\dbfull_%d_%T_%s';
sql 'alter system archive log current';
}
搜集信息sqlplus "/as sysdba"
set linesize 130 pagesize 2000
set trimspool on
set echo off
set verify off
set timing off
set feedback off
set head off
set echo off
spool renfile.sql
select 'set newname for datafile '''||name||''' to ''d:\oradata\81\'|| substr(name, instr(name, '\', -1) + 1)||'''; ' cmd from v$datafile
union all
select 'set newname for tempfile '''||name||''' to ''d:\oradata\81\'|| substr(name, instr(name, '\', -1) + 1)||'''; ' cmd from v$tempfile;
spool off
创建pfile文件,拷贝到目标位置create pfile from spfile;
修改pfile文件中的路径,注意dump目录、控制文件目录、归档位置目录(最好将需要恢复的归档日志拷贝到此目录 以便恢复)
启动实例到nomount状态,恢复控制文件
set oracle_sid=orcl
rman target /
startup nomount
restore controlfile from 'd:\oradata\81\DBFULL_ORCL_20110111_21'; #控制文件得提前知道放哪了
段句柄=\\192.168.1.2\ORADATA\81\DBFULL_ORCL_20110111_21
alter database mount;
catalog start with 'e:\oradata\bak' noprompt; #备份集的位置指定一下
run{
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF' to 'd:\oradata\81\SYSTEM01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF' to 'd:\oradata\81\UNDOTBS01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF' to 'd:\oradata\81\SYSAUX01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF' to 'd:\oradata\81\USERS01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\EXAMPLE01.DBF' to 'd:\oradata\81\EXAMPLE01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_01.DBF' to 'd:\oradata\81\test_01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_02.DBF' to 'd:\oradata\81\test_02.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_0423_01.DBF' to 'd:\oradata\81\test_0423_01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_0423_02.DBF' to 'd:\oradata\81\test_0423_02.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_0423_03.DBF' to 'd:\oradata\81\test_0423_03.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_0423_04.DBF' to 'd:\oradata\81\test_0423_04.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_03.DBF' to 'd:\oradata\81\test_03.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_04.DBF' to 'd:\oradata\81\test_04.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_05.DBF' to 'd:\oradata\81\test_05.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_06.DBF' to 'd:\oradata\81\test_06.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\test_07.DBF' to 'd:\oradata\81\test_07.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\AAA.DBF' to 'd:\oradata\81\AAA.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TS_EV_01.DBF' to 'd:\oradata\81\TS_EV_01.DBF';
set newname for datafile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TS_EV_02.DBF' to 'd:\oradata\81\TS_EV_02.DBF';
set newname for tempfile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\TEMP01.DBF' to 'd:\oradata\81\TEMP01.DBF';
restore database;
switch datafile all;
switch tempfile all;
recover database;
#alter database open resetlogs;
}
如果缺少归档日志run {
set ARCHIVELOG DESTINATION to 'd:\oradata\81\arch';
recover database;
}
sqlplus "/as sysdba"
alter database rename file 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG' to 'd:\oradata\81\redo01.dbf';
alter database rename file 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO02.LOG' to 'd:\oradata\81\redo02.dbf';
alter database rename file 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO03.LOG' to 'd:\oradata\81\redo03.dbf';
检查控制文件、数据文件、日志文件、临时文件位置是否正确。
参考:run {
ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;
ALLOCATE CHANNEL dev2 DEVICE TYPE DISK;
backup full tag 'dbfullbak' database maxsetsize 30g
include current controlfile format '\\192.168.1.2\oradata\81\dbfull_%U'
plus archivelog format '\\192.168.1.2\oradata\81\arch_%U' delete all input;
}