用rman遷移資料庫

space6212發表於2019-07-21
本文講述如何用rman將一個庫遷移到另一個伺服器上。

伺服器A:linux es4 + oracle9204 (源)
伺服器B:linux es4 + oracle9204 (目標)

一、建立目錄

為了簡單起見,在伺服器B上建立與A相同的目錄結構。如果因為空間或其他原因,可以考慮用軟連結來實現目錄結構的統一。
如果實在不能做到的話,可以用rman的set newname來實現資料的重定位。

[oracle@datasrv2 ~]$ mkdir -p /data/oradata/gpodb
[oracle@datasrv2 dbback]$ mkdir -p /data/dbback/gpofullbak
[oracle@datasrv2 admin]$ mkdir -p /data/admin/gpodb/udump
[oracle@datasrv2 admin]$ mkdir -p /data/admin/gpodb/bdump
[oracle@datasrv2 admin]$ mkdir -p /data/admin/gpodb/cdump
[oracle@datasrv2 admin]$ mkdir -p /data/archivelog/gpodb --歸檔


二、全庫備份

[oracle@datasrv1 gpofullbak]$ export ORACLE_SID=gpodb
[oracle@datasrv1 gpofullbak]$ rman target /

Recovery Manager: Release 9.2.0.4.0 - 64bit Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: GPODB (DBID=1026346035)

RMAN> run{
2> CONFIGURE CONTROLFILE AUTOBACKUP ON;
3> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data/dbback/gpofullbak/%F';
4> allocate channel c1 type disk format '/data/dbback/gpofullbak/full_%U';
5> backup database tag 'full_gpodb_data' FILESPERSET 10 PLUS ARCHIVELOG FILESPERSET 20 DELETE ALL INPUT;
6> release channel c1;
7> }

using target database controlfile instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data/dbback/gpofullbak/%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data/dbback/gpofullbak/%F';
new RMAN configuration parameters are successfully stored

allocated channel: c1
channel c1: sid=15 devtype=DISK


Starting backup at 25-4?? -07
current log archived
channel c1: starting archive log backupset
channel c1: specifying archive log(s) in backup set
input archive log thread=1 sequence=97 recid=68 stamp=620843481
channel c1: starting piece 1 at 25-4?? -07
channel c1: finished piece 1 at 25-4?? -07
piece handle=/data/dbback/gpofullbak/full_26ig2kep_1_1 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
channel c1: deleting archive log(s)
archive log filename=/data/archivelog/gpodb/1_97.dbf recid=68 stamp=620843481
Finished backup at 25-4?? -07

Starting backup at 25-4?? -07
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00007 name=/data/oradata/gpodb/ndindex01.dbf
input datafile fno=00009 name=/data/oradata/gpodb/ndindex03.dbf
input datafile fno=00011 name=/data/oradata/gpodb/ndindex05.dbf
input datafile fno=00013 name=/data/oradata/gpodb/ndmain02.dbf
input datafile fno=00015 name=/data/oradata/gpodb/ndmain04.dbf
input datafile fno=00017 name=/data/oradata/gpodb/ndmain06.dbf
input datafile fno=00004 name=/data/oradata/gpodb/indx01.dbf
input datafile fno=00003 name=/data/oradata/gpodb/drsys01.dbf
input datafile fno=00005 name=/data/oradata/gpodb/tools01.dbf
input datafile fno=00002 name=/data/oradata/gpodb/undotbs01.dbf
channel c1: starting piece 1 at 25-4?? -07
channel c1: finished piece 1 at 25-4?? -07
piece handle=/data/dbback/gpofullbak/full_27ig2ker_1_1 comment=NONE
channel c1: backup set complete, elapsed time: 00:05:45
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00006 name=/data/oradata/gpodb/users01.dbf
input datafile fno=00008 name=/data/oradata/gpodb/ndindex02.dbf
input datafile fno=00010 name=/data/oradata/gpodb/ndindex04.dbf
input datafile fno=00012 name=/data/oradata/gpodb/ndmain01.dbf
input datafile fno=00014 name=/data/oradata/gpodb/ndmain03.dbf
input datafile fno=00016 name=/data/oradata/gpodb/ndmain05.dbf
input datafile fno=00001 name=/data/oradata/gpodb/system01.dbf
channel c1: starting piece 1 at 25-4?? -07
channel c1: finished piece 1 at 25-4?? -07
piece handle=/data/dbback/gpofullbak/full_28ig2kpk_1_1 comment=NONE
channel c1: backup set complete, elapsed time: 00:05:35
Finished backup at 25-4?? -07

Starting backup at 25-4?? -07
current log archived
channel c1: starting archive log backupset
channel c1: specifying archive log(s) in backup set
input archive log thread=1 sequence=98 recid=69 stamp=620844163
channel c1: starting piece 1 at 25-4?? -07
channel c1: finished piece 1 at 25-4?? -07
piece handle=/data/dbback/gpofullbak/full_29ig2l43_1_1 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
channel c1: deleting archive log(s)
archive log filename=/data/archivelog/gpodb/1_98.dbf recid=69 stamp=620844163
Finished backup at 25-4?? -07

Starting Control File and SPFILE Autobackup at 25-4?? -07
piece handle=/data/dbback/gpofullbak/c-1026346035-20070425-07 comment=NONE
Finished Control File and SPFILE Autobackup at 25-4?? -07

released channel: c1

RMAN> exit


Recovery Manager complete.

--建立spfile
[oracle@datasrv1 gpofullbak]$ sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on D??úèy 4?? 25 10:48:17 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production

SQL> create pfile from spfile;

File created.


三、傳送檔案
把檔案放到B伺服器上的同樣目錄下。
[oracle@datasrv1 gpofullbak]$ scp * 172.25.13.51:`pwd`
oracle@172.25.13.51's password:
c-1026346035-20070425-07 100% 1696KB 1.7MB/s 00:01
full_26ig2kep_1_1 100% 901KB 900.5KB/s 00:00
full_27ig2ker_1_1 100% 1591MB 11.0MB/s 02:25
full_28ig2kpk_1_1 100% 1281MB 11.0MB/s 01:57
full_29ig2l43_1_1 100% 140KB 139.5KB/s 00:00
[oracle@datasrv1 dbs]$ scp initgpodb.ora 172.25.13.51:`pwd`
oracle@172.25.13.51's password:
initgpodb.ora 100% 1021 1.0KB/s 00:00

[oracle@datasrv1 dbs]$ scp orapwgpodb 172.25.13.51:`pwd`
oracle@172.25.13.51's password:
orapwgpodb 100% 1536 1.5KB/s 00:00


四、在B機恢復

[oracle@datasrv2 dbback]$ export ORACLE_SID=gpodb
[oracle@datasrv2 dbback]$ sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on D??úèy 4?? 25 11:00:50 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> startup pfile=?/dbs/init@.ora nomount
ORACLE instance started.

Total System Global Area 2585760448 bytes
Fixed Size 746176 bytes
Variable Size 486539264 bytes
Database Buffers 2097152000 bytes
Redo Buffers 1323008 bytes

SQL> exit
[oracle@datasrv2 gpofullbak]$ rman target /

Recovery Manager: Release 9.2.0.4.0 - 64bit Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: gpodb (not mounted)

RMAN> set dbid=1026346035;

executing command: SET DBID

RMAN> restore controlfile from '/data/dbback/gpofullbak/c-1026346035-20070425-07';

Starting restore at 25-4?? -2007 16:57:38

using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=12 devtype=DISK
channel ORA_DISK_1: restoring controlfile
channel ORA_DISK_1: restore complete
replicating controlfile
input filename=/data/oradata/gpodb/control01.ctl
output filename=/data/oradata/gpodb/control02.ctl
output filename=/data/oradata/gpodb/control03.ctl
Finished restore at 25-4?? -2007 16:57:46

RMAN> alter database mount;

database mounted

RMAN> restore database from tag='full_gpodb_data';

Starting restore at 25-4?? -2007 16:58:39

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 /data/oradata/gpodb/undotbs01.dbf
restoring datafile 00003 to /data/oradata/gpodb/drsys01.dbf
restoring datafile 00004 to /data/oradata/gpodb/indx01.dbf
restoring datafile 00005 to /data/oradata/gpodb/tools01.dbf
restoring datafile 00007 to /data/oradata/gpodb/ndindex01.dbf
restoring datafile 00009 to /data/oradata/gpodb/ndindex03.dbf
restoring datafile 00011 to /data/oradata/gpodb/ndindex05.dbf
restoring datafile 00013 to /data/oradata/gpodb/ndmain02.dbf
restoring datafile 00015 to /data/oradata/gpodb/ndmain04.dbf
restoring datafile 00017 to /data/oradata/gpodb/ndmain06.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/data/dbback/gpofullbak/full_27ig2ker_1_1 tag=FULL_GPODB_DATA params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /data/oradata/gpodb/system01.dbf
restoring datafile 00006 to /data/oradata/gpodb/users01.dbf
restoring datafile 00008 to /data/oradata/gpodb/ndindex02.dbf
restoring datafile 00010 to /data/oradata/gpodb/ndindex04.dbf
restoring datafile 00012 to /data/oradata/gpodb/ndmain01.dbf
restoring datafile 00014 to /data/oradata/gpodb/ndmain03.dbf
restoring datafile 00016 to /data/oradata/gpodb/ndmain05.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/data/dbback/gpofullbak/full_28ig2kpk_1_1 tag=FULL_GPODB_DATA params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 25-4?? -2007 17:09:24

RMAN> recover database;

Starting recover at 26-4?? -07
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=8 devtype=DISK

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=98
channel ORA_DISK_1: restored backup piece 1
piece handle=/data/dbback/gpofullbak/full_29ig2l43_1_1 tag=TAG20070425T164243 params=NULL
channel ORA_DISK_1: restore complete
archive log filename=/data/archivelog/gpodb/1_98.dbf thread=1 sequence=98
unable to find archive log
archive log thread=1 sequence=99
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/26/2007 09:58:41
RMAN-06054: media recovery requesting unknown log: thread 1 scn 32837861

RMAN> alter database open resetlogs;

database opened

由於聯機日誌沒有傳送過來,一般需要用resetlogs開啟資料庫。

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

相關文章