rman 資料庫從一臺機器遷移到另外的一臺機器

perfychi發表於2014-03-04
實驗目的:將oracle資料庫從一臺機器遷移到另外的一臺機器(同為linux平臺),設定為不同的路徑


第一步:在源端取得備份資料
開始備份:
$  rman target /
RMAN> run{
allocate channel c1 device type disk format '/u01/backup/%T_%U';
backup database plus archivelog;
backup current controlfile format '/u01/backup/%T_CTL_%U';
backup spfile format '/u01/backup/%T_SPFILE_%U';
release channel c1;
}


第二步:備端的準備
1、安裝資料庫軟體
2、建立相關的目錄:
$ env | grep ORACLE
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
$ oracle@model ~> cd $ORACLE_BASE
$ oracle@model /u01/app/oracle> mkdir flash_recovery_area
$ oracle@model /u01/app/oracle> mkdir -p admin/orcl
$ oracle@model /u01/app/oracle> cd admin/orcl
$ oracle@model /u01/app/oracle/admin/orcl> mkdir {a,b,c,d,u}dump




第三步:開始恢復,此時恢復的例項名為orcl
$  export ORACLE_SID=orcl
$  rman target /
RMAN> startup nomount
1、恢復spfile:
RMAN> restore spfile from '/u01/backup/20120829_SPFILE_05njss0m_1_1';
RMAN> shutdown immediate;
2、編輯引數檔案,使引數中的相關路徑變更為新路徑
$ oracle@model ~> sqlplus / as sysdba
SYS@test > create pfile from spfile;
編輯生成的$ORACLE_HOME/dbs/inittest.ora檔案,將檔案中的路徑改為新的路徑


$ oracle@model ~> sqlplus / as sysdba
SYS@test > create spfile from pfile;


 


[oracle@weblogic01 ~]$ rman target /


Recovery Manager: Release 11.2.0.1.0 - Production on Mon Mar 3 18:28:18 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


connected to target database: ORCL (not mounted)
3、恢復控制檔案:


RMAN> restore controlfile from '/u01/backup/control_20p1otrb_1_1';


4、恢復資料檔案:
RMAN> run {
set newname for datafile 1 to '/u01/app/oracle/oradata/orcl/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/orcl/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/orcl/users01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/orcl/example01.dbf';
set newname for datafile 6 to '/u01/app/oracle/oradata/orcl/data01_A5ADMIN01.dbf';
set newname for datafile 7 to '/u01/app/oracle/oradata/orcl/schema-4-01.dbf';
set newname for datafile 8 to '/u01/app/oracle/oradata/orcl/data01_A5ADMIN_1.dbf';
restore database;
}

修改目標庫控制檔案的資料檔案路徑:

sqlplus / as sysdba
SQL > alter database rename '源庫的資料檔案路徑‘  to '目的庫的資料檔案路徑’;
例如: alter database rename '/u01/cc/ORCL/datafile/o1_mf_system_8cv0pgxr_.dbf' to '/u01/app/oracle/oradata/orcl/system01.dbf';
.......
】或者
rman target /
rman > run {
set newname for datafile 1 to '/u01/app/oracle/oradata/orcl/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/orcl/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/orcl/users01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/orcl/example01.dbf';
set newname for datafile 6 to '/u01/app/oracle/oradata/orcl/data01_A5ADMIN01.dbf';
set newname for datafile 7 to '/u01/app/oracle/oradata/orcl/schema-4-01.dbf';
set newname for datafile 8 to '/u01/app/oracle/oradata/orcl/data01_A5ADMIN_1.dbf';
switch datafile all;
}


源庫的 檔案可以從源庫中查詢:
例如源庫資料檔名:
SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
/u01/cc/ORCL/datafile/o1_mf_system_8cv0pgxr_.dbf
/u01/cc/ORCL/datafile/o1_mf_sysaux_8cv0ph23_.dbf
/u01/cc/ORCL/datafile/o1_mf_undotbs1_8cv0ph33_.dbf
/u01/cc/ORCL/datafile/o1_mf_users_8cv0ph4m_.dbf
/u01/cc/ORCL/datafile/o1_mf_example_8cv1fxl9_.dbf
/u01/cc/ORCL/datafile/data01_A5ADMIN01.dbf
/u01/cc/ORCL/datafile/schema-4-01.dbf
/u01/dmdir/data01_A5ADMIN_1.dbf

恢復資料庫:
rman target /
rman> recover database;

5、以resetlogs方式開啟資料庫
SQL> alter database open resetlogs;




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27042095/viewspace-1100693/,如需轉載,請註明出處,否則將追究法律責任。

相關文章