1. 環境說明:
原機:192.168.102.156 Oracle 10.2.0.1
目標:192.168.102.157 ORACLE 10.2.0.1
2.對資料庫做建立一張表。
SQL> create table rmantest(id number(9));
Table created.
SQL> insert into rmantest(id) values(88);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
3. 目標庫準備執行個體名準備:此執行個體名為原庫的執行個體名。 不要隨意設, 因控制檔案裡是有記錄DB_NAME的, 如果你隨便設定執行個體名,是沒辦法完成遷移的。
[oracle@GOLDENGATE2 ~]$ export ORACLE_SID=gg1
[oracle@GOLDENGATE2 ~]$ echo $ORACLE_SID
gg1
4. 目標庫準備參數檔案。
(1) 在原庫建立一個PFILE檔案。
SQL> create pfile='/home/oracle/initgg1.ora' from spfile;
File created.
(2) 獎參數檔案移至目標庫。
[oracle@GOLDENGATE1 ~]$ scp initgg1.oraoracle@192.168.102.157:/home/oracle
oracle@192.168.102.157'spassword:
initgg1.ora 100% 1051 1.0KB/s 00:00
5. 在目標庫建立參數檔案中所需要的目錄。
[oracle@GOLDENGATE2 ~]$ mkdir -p admin/gg1/adump
[oracle@GOLDENGATE2 ~]$ mkdir -p admin/gg1/bdump
[oracle@GOLDENGATE2 ~]$ mkdir -p admin/gg1/cdump
[oracle@GOLDENGATE2 ~]$ mkdir -p admin/gg1/dpdump
[oracle@GOLDENGATE2 ~]$ mkdir -p admin/gg1/udump
[oracle@GOLDENGATE2 ~]$ mkdir flash_recovery_area
[oracle@GOLDENGATE2 ~]$ mkdir -p oradata/gg1
[oracle@GOLDENGATE2 ~]$ mkdir archivelog
6. 在目標庫建立SPFILE檔案,並將資料庫啟動到NOMOUNT狀態。
[oracle@GOLDENGATE2 ~]$ export ORACLE_SID=gg1
[oracle@GOLDENGATE2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Sep 21 01:21:51 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile='/home/oracle/initgg1.ora';
File created.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218292 bytes
Variable Size 83888396 bytes
Database Buffers 75497472 bytes
Redo Buffers 7168000 bytes
7. 對原資料庫進行熱備份。 必備條件: 資料庫屬歸檔模式。
[oracle@GOLDENGATE1 ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Sep 21 01:21:49 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GG1 (DBID=1620494887)
RMAN> run{
allocate channel a1 type disk;
allocate channel a2 type disk;
backup format='/home/oracle/rman/full_%d_%T_%s' database;
backup format='/home/oracle/rman/arch_%d_%T_%s' archivelog all;
backup format='/home/oracle/rman/ctl_%U' current controlfile;
release channel a2;
release channel a1;
}2> 3> 4> 5> 6> 7> 8> 9>
released channel: ORA_DISK_1
allocated channel: a1
channel a1: sid=158 devtype=DISK
allocated channel: a2
channel a2: sid=141 devtype=DISK
Starting backup at 21-SEP-12
channel a1: starting full datafile backupset
channel a1: specifying datafile(s) in backupset
input datafile fno=00001 name=/home/oracle/oradata/gg1/system01.dbf
input datafile fno=00005 name=/home/oracle/oradata/gg1/example01.dbf
input datafile fno=00003 name=/home/oracle/oradata/gg1/sysaux01.dbf
channel a1: starting piece 1 at 21-SEP-12
channel a2: starting full datafile backupset
channel a2: specifying datafile(s) in backupset
input datafile fno=00006 name=/home/oracle/oradata/gg1/gg01.dbf
input datafile fno=00002 name=/home/oracle/oradata/gg1/undotbs01.dbf
input datafile fno=00004 name=/home/oracle/oradata/gg1/users01.dbf
channel a2: starting piece 1 at 21-SEP-12
channel a2: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/full_GG1_20120921_10 tag=TAG20120921T013222 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:25
channel a2: starting full datafile backupset
channel a2: specifying datafile(s) in backupset
including current control file in backupset
channel a2: starting piece 1 at 21-SEP-12
channel a2: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/full_GG1_20120921_11 tag=TAG20120921T013222 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:03
channel a2: starting full datafile backupset
channel a2: specifying datafile(s) in backupset
including current SPFILE in backupset
channel a2: starting piece 1 at 21-SEP-12
channel a2: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/full_GG1_20120921_12 tag=TAG20120921T013222 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:02
channel a1: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/full_GG1_20120921_9 tag=TAG20120921T013222 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:48
Finished backup at 21-SEP-12
Starting backup at 21-SEP-12
current log archived
channel a1: starting archive log backupset
channel a1: specifying archive log(s) in backup set
input archive log thread=1 sequence=4 recid=1 stamp=794527523
channel a1: starting piece 1 at 21-SEP-12
channel a2: starting archive log backupset
channel a2: specifying archive log(s) in backup set
input archive log thread=1 sequence=5 recid=2 stamp=794538401
input archive log thread=1 sequence=6 recid=3 stamp=794539337
input archive log thread=1 sequence=7 recid=4 stamp=794539385
channel a2: starting piece 1 at 21-SEP-12
channel a2: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/arch_GG1_20120921_13 tag=TAG20120921T013312 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:02
channel a1: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/arch_GG1_20120921_14 tag=TAG20120921T013312 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:03
channel a2: starting archive log backupset
channel a2: specifying archive log(s) in backup set
input archive log thread=1 sequence=8 recid=5 stamp=794539992
channel a2: starting piece 1 at 21-SEP-12
channel a2: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/arch_GG1_20120921_15 tag=TAG20120921T013312 comment=NONE
channel a2: backup set complete, elapsed time: 00:00:02
Finished backup at 21-SEP-12
Starting backup at 21-SEP-12
channel a1: starting full datafile backupset
channel a1: specifying datafile(s) in backupset
including current control file in backupset
channel a1: starting piece 1 at 21-SEP-12
channel a1: finished piece 1 at 21-SEP-12
piece handle=/home/oracle/rman/ctl_0gnlndut_1_1 tag=TAG20120921T013317 comment=NONE
channel a1: backup set complete, elapsed time: 00:00:02
Finished backup at 21-SEP-12
released channel: a2
released channel: a1
8. 將備份移至目標機。
[oracle@GOLDENGATE1 ~]$ cd rman/
[oracle@GOLDENGATE1 rman]$ ls
arch_GG1_20120921_13 arch_GG1_20120921_15 full_GG1_20120921_10 full_GG1_20120921_12
arch_GG1_20120921_14 ctl_0gnlndut_1_1 full_GG1_20120921_11 full_GG1_20120921_9
[oracle@GOLDENGATE1 rman]$ scp *oracle@192.168.102.157:/home/oracle/rman
oracle@192.168.102.157'spassword:
arch_GG1_20120921_13 100% 13MB 12.8MB/s 00:01
arch_GG1_20120921_14 100% 25MB 12.5MB/s 00:02
arch_GG1_20120921_15 100% 281KB 281.0KB/s 00:00
ctl_0gnlndut_1_1 100% 6944KB 6.8MB/s 00:00
full_GG1_20120921_10 100% 33MB 8.2MB/s 00:04
full_GG1_20120921_11 100% 6944KB 6.8MB/s 00:00
full_GG1_20120921_12 100% 96KB 96.0KB/s 00:01
full_GG1_20120921_9 100% 561MB 11.9MB/s 00:47
9. 在目標機上恢複控制檔案。
[oracle@GOLDENGATE2 rman]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Sep 21 01:36:10 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: gg1 (not mounted)
RMAN> restore controlfile from '/home/oracle/rman/ctl_0gnlndut_1_1';
Starting restore at 21-SEP-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/home/oracle/oradata/gg1/control01.ctl
output filename=/home/oracle/oradata/gg1/control02.ctl
output filename=/home/oracle/oradata/gg1/control03.ctl
Finished restore at 21-SEP-12
10. 啟動資料庫到MOUNT狀態。
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
11.恢複資料庫。
RMAN> restore database;
Starting restore at 21-SEP-12
Starting implicit crosscheck backup at 21-SEP-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 7 objects
Finished implicit crosscheck backup at 21-SEP-12
Starting implicit crosscheck copy at 21-SEP-12
using channel ORA_DISK_1
Finished implicit crosscheck copy at 21-SEP-12
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /home/oracle/oradata/gg1/undotbs01.dbf
restoring datafile 00004 to /home/oracle/oradata/gg1/users01.dbf
restoring datafile 00006 to /home/oracle/oradata/gg1/gg01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rman/full_GG1_20120921_10
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rman/full_GG1_20120921_10 tag=TAG20120921T013222
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /home/oracle/oradata/gg1/system01.dbf
restoring datafile 00003 to /home/oracle/oradata/gg1/sysaux01.dbf
restoring datafile 00005 to /home/oracle/oradata/gg1/example01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rman/full_GG1_20120921_9
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rman/full_GG1_20120921_9 tag=TAG20120921T013222
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 21-SEP-12
RMAN> recover database;
Starting recover at 21-SEP-12
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=8
channel ORA_DISK_1: reading from backup piece /home/oracle/rman/arch_GG1_20120921_15
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rman/arch_GG1_20120921_15 tag=TAG20120921T013312
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/home/oracle/archivelog/1_8_794474474.dbf thread=1 sequence=8
unable to find archive log
archive log thread=1 sequence=9
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/21/2012 01:38:18
RMAN-06054: media recovery requesting unknown log: thread 1 seq 9 lowscn 529513
查看原庫日誌:
[oracle@GOLDENGATE1 archivelog]$ ls
1_4_794474474.dbf 1_5_794474474.dbf 1_6_794474474.dbf 1_7_794474474.dbf 1_8_794474474.dbf
[oracle@GOLDENGATE1 archivelog]$
幹, 這裡就沒有那日誌。
因為原庫並未產生SEQ為9的日誌,這雷根本就沒有9的備份。
用SQLPLUS連進行執行恢複。
SQL> recover database using backup controlfile;
ORA-00279: change 529513 generated at 09/21/2012 01:33:11 needed for thread 1
ORA-00289: suggestion : /home/oracle/archivelog/1_9_794474474.dbf
ORA-00280: change 529513 for thread 1 is in sequence #9
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
12。 開啟資料庫。
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/home/oracle/oradata/gg1/system01.dbf'
因為控制檔案和資料檔案不一致。
解決辦法:
修改參數檔案:增加 _allow_resetlogs_corruption='TURE'
關閉資料庫,重建SPFILE檔案,並啟動到NOMOUNT狀態。
開啟資料庫:
SQL> alter database open resetlogs;
Database altered.
13。 檢查
REDO日誌和暫存資料表空間檔案會在開啟資料庫時根據控制檔案中的記錄去建立。
查看原庫所建的表:
SQL> select * from rmantest;
ID
----------
88
遷移完成。