RMAN恢复整个数据库案例-网友供稿

适合场合:恢复的目录一致,同时备份的过程中有归档日志
恢复的数据库目录和down机的数据库一致,还有一个就是RMAN备份的时候已经备份了归档日志。
备份脚本:
run{
allocalte channel ch1 type disk;
sql ‘alter system archive log current’;
backup as compressed backupset database format ‘/u02/rman/testdb_%T_%U’;
sql ‘alter system archive log current’;
backup as compressed backupset archivelog all format ‘/u02/rman/testarc_%T_%U’;
bakup current controlfile format ‘/u02/rman/testcon_%T_%U’;
release channel ch1;
}
delete force noprompt expired backup;
delete force noprompt obsoelet;
1.    安装Oracle服务器软件
版本尽量对应,安装过程中选择只安装软件,不创建数据库
2.    设置Oracle环境变量
su – oracle
vim ~/.bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/10g/db_1
export ORACLE_SID=test    –这个一定要对应
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
unset USERNAME
生效:source ~/.bash_profile
3.    创建相应的目录和文件,和之前服务器的一致,信息可以从rman备份的log文件看到,包括如下:
mkdir $ORACLE_BASE/admin/SID/{a,b,c,d,u}dump –p
mkdir $ORACLE_BASE/admin/SID/pfile–p
mkdir $ORACLE_BASE/oradata/SID –p
创建口令文件:
orapwd file=$ORACLE_HOME/dbs/orapwtest password=oracle entires=10
4.    拷贝备份和归档到恢复机器对应的路径下,特别是rman备份的路径,否则会报错
5.    配置主机名,监听,IP
6.    RMAN恢复数据库的过程


1)rman target / nocatalog
Recovery Manager: Release 10.2.0.4.0 – Production on Thu Sep 16 13:55:31 2010
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database (not started)

2)RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/10g/db_1/dbs/inittest.ora'
starting Oracle instance without parameter file for retrival of spfile
Oracle instance started
上面的意思是说:没有实例需要的初始化参数文件,由于没有参数文件,所以会报错,但实例已经启动
Total System Global Area     159383552 bytes
Fixed Size                     1266344 bytes
Variable Size                 54529368 bytes
Database Buffers             100663296 bytes
Redo Buffers                   2924544 bytes

3)恢复初始化参数文件
这里需要注意的是,要找对对应的备份文件,逐一尝试,一般找备份比较后而且小的
RMAN> restore spfile from '/u02/rman/testdb_20100916_05lo1lg0_1_1';
Starting restore at 16-SEP-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK
channel ORA_DISK_1: autobackup found: /u02/rman/testdb_20100916_05lo1lg0_1_1
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 16-SEP-10

4)恢复控制文件
RMAN> shutdown immediate;
Oracle instance shut down
RMAN> startup nomount;
connected to target database (not started)
Oracle instance started
Total System Global Area     167772160 bytes
Fixed Size                     1266392 bytes
Variable Size                 62917928 bytes
Database Buffers             100663296 bytes
Redo Buffers                   2924544 bytes
RMAN> restore controlfile from '/u02/rman/testcon_20100916_07lo1lg8_1_1';
Starting restore at 16-SEP-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=101 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/test/control01.ctl
output filename=/u01/app/oracle/oradata/test/control02.ctl
output filename=/u01/app/oracle/oradata/test/control03.ctl
Finished restore at 16-SEP-10

5)将数据启动到mount状态
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

6)恢复数据库
后面出现的错误是指个别日志不同步,所以最好就是把归档一起拷贝全
RMAN> run{
2> restore database;
3> recover database;
4> }

7)以resetlogs打开数据库
 [oracle@sdb dbs]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Thu Sep 16 14:02:58 2010
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database open resetlogs;
Database altered.
若在6)数据库恢复的过程中出现问题,可以参考如下的步骤进行
在恢复完控制文件后,启动到mount状态下,在sqlplus提示符下运行如下查询
1.  sql>select file#,checkpoint_change# from v$datafile;
注:如果出现科学记数法显示不了checkpoint_change#列的时候,可以通过如下命令让其显示完全
set numw 15;
发现所有数据文件的checkpoint scn是52873354,因此需要scn大于52873354的归档日志来修复数据库
2.在rman提示符下运行list backup of archivelog all,发现scn大于52873354的归档日志的sequence范围是1052至1097,在rman提示符下运行
restore archivelog sequence between 1052 and 1097;    恢复归档日志(mount)
3.在sqlplus提示符下运行命令alter database flashback off;关闭flashback,然后在rman提示符下运行如下命令块修复数据库
rman>Run {
Set until sequence=1098;
retore database;
Recover database;
}

By: 柏鹏先