使用rman遷移oracle數據庫

環境:源主機hostname:localhost  平臺:rhel X86_64   數據庫版本:11g R2   數據位置:/home/oracle/app/oracle/oradata

           目標主機:主機名standby    平臺:rhel X86_64   數據庫版本:11g R2   數據位置:/home/oracle/app/mydata


一、首先在源主機進行備份

 1.png

1、這裏用rman進行壓縮備份,壓縮可以大大的節省空間

RMAN> run {
2> backup as compressed backupset full tag 'full_for_transfer' database
3> include current controlfile format '/home/oracle/full_%d_%T_%s'
4> plus archivelog format '/home/oracle/arlog_%d_%T_%s';
5> }
備份完成我們可以用list backup查看下備份

備份源數據庫口令文件(可以不備份,在目標數據庫新建也可以),口令文件路徑$ORACLE_HOME/dbs/orapw$ORACLE_SID

備份源數據庫參數文件,修改後,在目標數據庫使用。可以通過create pfile from spfile導出pfile


二、將源數據庫備份數據傳輸到目標數據庫,並在目標數據庫建立目錄

1、環境準備

     將備份數據通過ftp工具傳輸到目標數據庫

     在目標數據新建mydata目錄$ mkdir /home/oracle/app/mydata

     在目標數據庫設置環境變量,同源數據庫一樣

     在目標數據庫啓動實例到nomount狀態

SQL> startup nomount
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/inittest001.ora'
提示沒有參數文件,我們將修改好的參數文件重命名爲inittest001.ora,並放到/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/目錄

再次啓動

SQL>startup nomount
ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated
ORA-01262: Stat failed on a file destination directory
Linux-x86_64 Error: 2: No such file or directory
提示沒有文件或目錄,建立目錄,檢查參數文件中設置的目錄是否存在

# mkdir -p /home/oracle/app/oracle/admin/test001/adump
# mkdir -p /home/oracle/app/oracle/flash_recovery_area/test001/
# chown -R oracle.oinstall /home/oracle/
再次啓動

SQL> startup nomount
ORA-00119: invalid specification for system parameter LOCAL_LISTENER
ORA-00130: invalid listener address '(ADDRESS=(PROTOCOL=TCP)(HOST=standby)(PORT=1521))'
提示我們沒有建立監聽,我們可以重新建監聽也可以,複製源數據庫,進行修改

$ORACLE_HOME/network/admin 監聽配置文件目錄

建立監聽,先對我們的hosts文件進行修改

$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.30.252.17 standby

啓動監聽,再啓動實例

3.png   

三、恢復控制文件,並啓動到mount狀態

1、恢復控制文件

RMAN> restore controlfile from '/home/oracle/full_TEST001_20140311_158';

Starting restore at 11-MAR-14
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/app/mydata/control01.ctl
output file name=/home/oracle/app/oracle/flash_recovery_area/test001/control02.ctl
Finished restore at 11-MAR-14

2、啓動到mount狀態

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

四、恢復數據文件

1、使用catalog start with指定備份文件位置

RMAN> catalog start with '/home/oracle';

2、使用rman進行數據恢復

還原及恢復數據庫,由於使用了不同的位置,因此我們需要使用set newname 子句。如果使用相同目錄,直接恢復即可

RMAN> run {
2> set newname for datafile 1 to '/home/oracle/app/mydata/system01.dbf';
3> set newname for datafile 2 to '/home/oracle/app/mydata/sysaux01.dbf';
4> set newname for datafile 3 to '/home/oracle/app/mydata/undotbs01.dbf';
5> set newname for datafile 4 to '/home/oracle/app/mydata/users01.dbf';
6> set newname for datafile 5 to '/home/oracle/app/mydata/rman01.dbf';
7> set newname for datafile 6 to '/home/oracle/app/mydata/eygle.dbf';
8> restore database;
9> switch datafile all;
10> recover database;
11> }

.............................................................................................
unable to find archived log
archived log thread=1 sequence=77
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/11/2014 18:18:25
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 77 and starting SCN of 1797152

這個錯誤,因爲我們redo log丟失所以出錯

五、恢復redo log到新的目錄

啓動到open狀態

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 03/11/2014 18:20:59
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
因爲我們使用了恢復的控制文件,所以用resetlogs模式打開數據庫

SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00344: unable to re-create online log
'/home/oracle/app/oracle/oradata/test001/redo01.log'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
因爲改變了文件路徑,所以日誌文件無法創建


SQL> set linesize 200;
SQL> col member format a60;
SQL> select * from v$logfile;


    GROUP# STATUS  TYPE    MEMBER                                                       IS_
---------- ------- ------- ------------------------------------------------------------ ---
         3         ONLINE  /home/oracle/app/oracle/oradata/test001/redo03.log           NO
         2         ONLINE  /home/oracle/app/oracle/oradata/test001/redo02.log           NO
         1         ONLINE  /home/oracle/app/oracle/oradata/test001/redo01.log           NO


SQL> set heading off;


SQL> select 'alter database rename file '''||member||''' to '''||replace(member,'/home/oracle/app/oracle/oradata/test001/','/home/oracle/app/mydata/')||''';' from v$logfile;


SQL> alter database rename file '/home/oracle/app/oracle/oradata/test001/redo03.log' to '/home/oracle/app/mydata/redo03.log';

Database altered.

SQL> alter database rename file '/home/oracle/app/oracle/oradata/test001/redo02.log' to '/home/oracle/app/mydata/redo02.log';

Database altered.

SQL> alter database rename file '/home/oracle/app/oracle/oradata/test001/redo01.log' to '/home/oracle/app/mydata/redo01.log';

Database altered.


SQL> set heading on;
SQL> alter database open resetlogs;

Database altered.
成功打開數據庫

六,修改臨時表空間位置

SQL> select * from dba_temp_files;
select * 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: '/home/oracle/app/oracle/oradata/test001/temp01.dbf'

臨時數據文件位置也需要更改

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/test001/temp01.dbf

SQL> alter tablespace temp add tempfile '/home/oracle/app/mydata/temp.dbf' size 100M;

Tablespace altered.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/test001/temp01.dbf
/home/oracle/app/mydata/temp.dbf


SQL> alter tablespace temp drop tempfile '/home/oracle/app/oracle/oradata/test001/temp01.dbf';

Tablespace altered.


SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/oracle/app/mydata/temp.dbf



SQL>alter database tempfile '/home/oracle/app/mydata/temp.dbf' autoextend on;


Database altered
SQL> select * from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   FILE_ID TABLESPACE_NAME                     BYTES     BLOCKS STATUS  RELATIVE_FNO AUT   MAXBYTES  MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
---------- ------------------------------ ---------- ---------- ------- ------------ --- ---------- ---------- ------------ ---------- -----------
/home/oracle/app/mydata/temp.dbf
         2 TEMP                             52428800       6400 ONLINE             2 YES 3.4360E+10    4194302            1   51380224        6272

七、重建EM
[oracle@standby ~]$ emctl start dbconsole
Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name. 
EM無法啓動,重建EM

重建EM之前一定要要口令文件,否則無法重建

$ orapwd file=$ORACLE_HOME/dbs/orapwtest001 password=Test1234 force=y entries=10
$ ls
hc_test001.dat  init.ora  inittest001.ora  lkTEST001  orapwtest001

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章