`
sjk2013
  • 浏览: 2189145 次
文章分类
社区版块
存档分类
最新评论

同系统oracle rman异机数据库移植,oracle rman 备份和恢复详解

 
阅读更多


环境:
源服务器:
VM7.14 rhel5.5-32 oracle 11.2.0.0g
172.16.3.202
目标服务器
VM7.14 rhel5.5-32 oracle 11.2.0.0g
172.16.3.204


源服务器

一、在数据库中加入验证表和数据:

[oracle@ebs01 ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jun 10 13:09:43 2012

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table addr1(city varchar(20),phone number);

Table created.
SQL> insert into addr1 values('beijing',1580118);

1 row created.
SQL> insert into addr1 values('shanghai',1501005);

1 row created.
SQL> insert into addr1 values('nanjing',1598888);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from addr;

CITY PHONE
-------------------- ----------
beijing 1.5801E+10
shanghai 1.5010E+10
nanjing 1.5988E+10

二、清空备份目录,或者新建一个都行,并备份必要文件。

[oracle@ebs01 ~]$ cd /u01/backup
[oracle@ebs01 backup]$ rm *

1)开始备份,备份数据文件连同归档日志:

[oracle@ebs01 backup]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jun 11 09:16:52 2012

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

connected to target database: ORCL (DBID=1290854593)

RMAN> run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup incremental level 0
format '/u01/backup/db_full_%U.bkp'
tag '2012-06-11-FULL'
database plus archivelog;
release channel c1;
release channel c2;
} 2> 3> 4> 5> 6> 7> 8> 9> 10>

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=41 device type=DISK

allocated channel: c2
channel c2: SID=28 device type=DISK


Starting backup at 11-JUN-12
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=1 STAMP=784809253
input archived log thread=1 sequence=20 RECID=2 STAMP=784809551
input archived log thread=1 sequence=21 RECID=3 STAMP=785592038
channel c1: starting piece 1 at 11-JUN-12
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=4 STAMP=785592147
input archived log thread=1 sequence=23 RECID=5 STAMP=785595880
channel c2: starting piece 1 at 11-JUN-12
channel c1: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0mnd8mo1_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c1: backup set complete, elapsed time: 00:00:08
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=24 RECID=6 STAMP=785668864
channel c1: starting piece 1 at 11-JUN-12
channel c2: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0nnd8mo1_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c2: backup set complete, elapsed time: 00:00:08
channel c1: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0ond8mo9_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JUN-12

Starting backup at 11-JUN-12
channel c1: starting incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
channel c1: starting piece 1 at 11-JUN-12
channel c2: starting incremental level 0 datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel c2: starting piece 1 at 11-JUN-12
channel c2: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0qnd8mob_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c2: backup set complete, elapsed time: 00:00:56
channel c2: starting incremental level 0 datafile backup set
channel c2: specifying datafile(s) in backup set
including current control file in backup set
channel c2: starting piece 1 at 11-JUN-12
channel c2: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0rnd8mq4_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c2: backup set complete, elapsed time: 00:00:09
channel c2: starting incremental level 0 datafile backup set
channel c2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel c2: starting piece 1 at 11-JUN-12
channel c2: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0snd8mqs_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c2: backup set complete, elapsed time: 00:00:07
channel c1: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0pnd8mob_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c1: backup set complete, elapsed time: 00:01:48
Finished backup at 11-JUN-12

Starting backup at 11-JUN-12
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=25 RECID=7 STAMP=785668983
channel c1: starting piece 1 at 11-JUN-12
channel c1: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/db_full_0tnd8mro_1_1.bkp tag=2012-06-11-FULL comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JUN-12

released channel: c1

released channel: c2
2)备份当前控制文件:
RMAN> backup current controlfile format '/u01/backup/controlfile20120611.bak';

Starting backup at 11-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 11-JUN-12
channel ORA_DISK_1: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/controlfile20120611.bak tag=TAG20120611T093224 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 11-JUN-12
3)备份参数文件
RMAN> backup spfile format '/u01/backup/spfile20120611.bak';

Starting backup at 11-JUN-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-JUN-12
channel ORA_DISK_1: finished piece 1 at 11-JUN-12
piece handle=/u01/backup/spfile20120611.bak tag=TAG20120611T093402 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-JUN-12

RMAN>

目标服务器
一、前期准备

1)查看刚安装的数据库软件ORACLE_BASE目录,只有两个目录,没有flash_recovery_area,oradata ,admin等目录,这些是创建数据库加的
[oracle@localhost app]$ cd oracle
[oracle@localhost oracle]$ ls
checkpoints product
[oracle@localhost oracle]$ mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,dpdump,udump,pfile}--单独创建
[oracle@localhost oracle]$ ls
admin checkpoints product
[oracle@localhost oracle]$ cd admin/
[oracle@localhost admin]$ ls
orcl
[oracle@localhost admin]$ cd orcl/
[oracle@localhost orcl]$ ls
adump bdump cdump dpdump pfile udump
[oracle@localhost orcl]$ cd ..
[oracle@localhost admin]$ ls
orcl
[oracle@localhost admin]$ cd ..
[oracle@localhost oracle]$ ls
admin checkpoints product
[oracle@localhost oracle]$ cd ~
[oracle@localhost ~]$ mkdir -p /u01/app/oracle/oradata/orcl
[oracle@localhost oracle]$ mkdir -p /u01/app/oracle/flash_recover_area/ORCL --这个大写小写要看oracle_sid或者数据库名称,或者元数据库控制文件参数文件里规定
[oracle@localhost oracle]$ ls
admin checkpoints flash_recover_area oradata product
[oracle@localhost oracle]$ cd oracle
bash: cd: oracle: 没有那个文件或目录
[oracle@localhost oracle]$ cd oradata/
[oracle@localhost oradata]$ ls
orcl
[oracle@localhost oradata]$ cd ..
[oracle@localhost oracle]$ ls
admin checkpoints flash_recover_area oradata product --也可能是flash_recovery_area,一个y的差别
[oracle@localhost oracle]$ cd admin/
[oracle@localhost admin]$ ls
orcl
[oracle@localhost admin]$ cd ..
[oracle@localhost oracle]$ ls
admin checkpoints flash_recover_area oradata product
[oracle@localhost oracle]$ cd flash_recover_area/
[oracle@localhost flash_recover_area]$ ls
ORCL
[oracle@localhost flash_recover_area]$ echo 'db_name=orcl' > $ORACLE_HOME/dbs/initorcl.ora
--刚装的数据库,只有一个init.ora,这里要生成一个默认的pfile——initorcl.ora,只有一个参数
[oracle@localhost flash_recover_area]$ cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ ls
init.ora initorcl.ora
[oracle@localhost dbs]$ cat initorcl.ora
db_name=orcl --里面只有一个参数
[oracle@localhost dbs]$ cd ~
[oracle@localhost ~]$ echo $ORACLE_SID
orcl
二、数据传输
登录目标服务器,从源服务器把备份好的数据拷贝到目的机器:

[oracle@localhost backup]$ scp -rp 172.16.3.202:/u01/backup/* /u01/backup/
oracle@172.16.3.202's password:
controlfile20120611.bak 100% 9568KB 869.8KB/s 00:11
db_full_0mnd8mo1_1_1.bkp 100% 19MB 989.0KB/s 00:20
db_full_0nnd8mo1_1_1.bkp 100% 38MB 469.8KB/s 01:22
db_full_0ond8mo9_1_1.bkp 100% 13MB 528.1KB/s 00:25
db_full_0pnd8mob_1_1.bkp 100% 663MB 264.7KB/s 42:45
db_full_0qnd8mob_1_1.bkp 100% 419MB 661.8KB/s 10:48
db_full_0rnd8mq4_1_1.bkp 100% 9568KB 3.1MB/s 00:03
db_full_0snd8mqs_1_1.bkp 100% 96KB 96.0KB/s 00:01
db_full_0tnd8mro_1_1.bkp 100% 8192 8.0KB/s 00:00
spfile20120611.bak 100% 96KB 96.0KB/s 00:00
三、开始恢复过程
1)数据库启动到nomount
[oracle@localhost ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jun 11 10:13:09 2012

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

connected to target database (not started)

RMAN> set dbid=1290854593 --这个dbdi是从源数据库记过来的,可是select dbdi from v$DATABASE找到

executing command: SET DBID

RMAN> startup nomount

Oracle instance started

Total System Global Area 146472960 bytes

Fixed Size 1335080 bytes
Variable Size 92274904 bytes
Database Buffers 50331648 bytes
Redo Buffers 2531328 bytes
2)首先恢复参数文件
RMAN> restore spfile from '/u01/backup/spfile20120611.bak';

Starting restore at 11-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/backup/spfile20120611.bak
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 11-JUN-12
3)其次恢复控制文件

要先把数据库强制启动到nomount状态,意思是使刚才恢复的spfile生效,如下:

RMAN> startup nomount force;

Oracle instance started

Total System Global Area 539848704 bytes

Fixed Size 1337748 bytes
Variable Size 406849132 bytes
Database Buffers 125829120 bytes
Redo Buffers 5832704 bytes


RMAN> restore controlfile from '/u01/backup/controlfile20120611.bak';

Starting restore at 11-JUN-12
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/orcl/control02.ctl
Finished restore at 11-JUN-12

4)把数据库启动到mount状态,
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 11-JUN-12
Starting implicit crosscheck backup at 11-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Crosschecked 27 objects
Finished implicit crosscheck backup at 11-JUN-12

Starting implicit crosscheck copy at 11-JUN-12
using channel ORA_DISK_1
Finished implicit crosscheck copy at 11-JUN-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 backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/db_full_0qnd8mob_1_1.bkp
channel ORA_DISK_1: piece handle=/u01/backup/db_full_0qnd8mob_1_1.bkp tag=2012-06-11-FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:06:17
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/db_full_0pnd8mob_1_1.bkp
channel ORA_DISK_1: piece handle=/u01/backup/db_full_0pnd8mob_1_1.bkp tag=2012-06-11-FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:31
Finished restore at 11-JUN-12

不明白下步骤为啥出错,但是恢复alter database open resetlogs; 可以打开数据库,而且验证正确。
RMAN> recover database;

Starting recover at 11-JUN-12
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=25
channel ORA_DISK_1: reading from backup piece /u01/backup/db_full_0tnd8mro_1_1.bkp
channel ORA_DISK_1: piece handle=/u01/backup/db_full_0tnd8mro_1_1.bkp tag=2012-06-11-FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2012_06_11/o1_mf_1_25_7xbtjhnv_.arc thread=1 sequence=25
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2012_06_11/o1_mf_1_25_7xbtjhnv_.arc RECID=8 STAMP=785677583
unable to find archived log
archived log thread=1 sequence=26
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/11/2012 11:46:28
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 26 and starting SCN of 1191327

RMAN> alter database open resetlogs;

database opened

RMAN>

四、登录SQL验证:


[oracle@localhost database]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 11 08:13:42 2012

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup

SQL> select * from addr;

CITY PHONE
-------------------- ----------
beijing 1.5801E+10
shanghai 1.5010E+10
nanjing 1.5988E+10

SQL> SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/redo03.log
/u01/app/oracle/oradata/orcl/redo02.log
/u01/app/oracle/oradata/orcl/redo01.log

SQL>

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf

SQL>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics