目标服务器
一、前期准备
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>
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
