rman恢复的基本知识

1、口令文件的恢复
口令文件的路径:$ORACLE_HOME/dbs目录下
cd  $ORACLE_HOME/dbs
rm orapworcl
orapwd file=orapworcl password=oracle entries=5; //重新建立一个文件,entries的意思:DBA的用户最多有5个

2、spfile丢失

SQL> startup nomount
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora'

rman下

RMAN> set dbid 2694191837
executing command: SET DBID

RMAN>  restore spfile from autobackup; //如果没有成功,说明configure controlfile autobackup on 没有配置,下次配置完成后,就可以恢复成功

Starting restore at 01-APR-14
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/01/2014 21:01:16
RMAN-12010: automatic channel allocation initialization failed
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory

指定路径恢复
RMAN> set dbid 2694191837
executing command: SET DBID

RMAN> startup force nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjiagulun.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area     159383552 bytes

Fixed Size                     2019224 bytes
Variable Size                 67108968 bytes
Database Buffers              83886080 bytes
Redo Buffers                   6369280 bytes

RMAN> restore spfile from '/home/oracle/rmanbak/inc0_0hp4lqu4_20140401'; //该路径可以在以前备份日志上找到

Starting restore at 01-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /home/oracle/rmanbak/inc0_0hp4lqu4_20140401
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 01-APR-14

3、controlfile 丢失:
SQL> SHOW PARAMETER CONTROL_FILES
//查看备份文件位置

SQL> startup nomount; //丢失control文件可以到nomount阶段
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  2020192 bytes
Variable Size             125832352 bytes
Database Buffers          150994944 bytes
Redo Buffers                6365184 bytes
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info

SQL> shutdown immediate
ORA-01507: database not mounted

在RMAN下
RMAN> startup nomount;

Oracle instance started

Total System Global Area     285212672 bytes

Fixed Size                     2020192 bytes
Variable Size                125832352 bytes
Database Buffers             150994944 bytes
Redo Buffers                   6365184 bytes

RMAN> restore controlfile from autobackup;//因为没有启用autobackup,所以失败

Starting restore at 01-APR-14
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/01/2014 21:43:22
RMAN-12010: automatic channel allocation initialization failed
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory


RMAN> restore controlfile from '/home/oracle/rmanbak/inc0_0gp4lqtt_20140401';

Starting restore at 01-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u01/app/oracle/oradata/JIAGULUN/controlfile/o1_mf_9mojz9ot_.ctl
output filename=/u01/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_9mojzb1m_.ctl
Finished restore at 01-APR-14
恢复成功。

但是在sql下,还是无法打开
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open RESETLOGS;
alter database open RESETLOGS
*
ERROR at line 1:
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1:
'/u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_7p5b14xs_.dbf'

出错, redo log的scn记录在controlfile里面的,因为我们有新的controlfile,所以需要resetlogs;

RMAN下
RMAN> recover database; //以当前的控制文件里所记录的SCN来恢复数据文件的数据块

Starting recover at 01-APR-14
Starting implicit crosscheck backup at 01-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=155 devtype=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 01-APR-14

Starting implicit crosscheck copy at 01-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
Finished implicit crosscheck copy at 01-APR-14

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1
using channel ORA_DISK_2

starting media recovery

archive log thread 1 sequence 102 is already on disk as file /u01/app/oracle/flash_recovery_area/JIAGULUN/onlinelog/o1_mf_2_7p5b34v6_.log
archive log thread 1 sequence 103 is already on disk as file /u01/app/oracle/flash_recovery_area/JIAGULUN/onlinelog/o1_mf_3_7p5b36x4_.log
archive log thread 1 sequence 104 is already on disk as file /u01/app/oracle/flash_recovery_area/JIAGULUN/onlinelog/o1_mf_1_7p5b31mg_.log
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/o1_mf_2_7p5b34v6_.log thread=1 sequence=102
archive log filename=/u01/app/oracle/flash_recovery_area/ ORCL /onlinelog/o1_mf_3_7p5b36x4_.log thread=1 sequence=103
archive log filename=/u01/app/oracle/flash_recovery_area/ ORCL /onlinelog/o1_mf_1_7p5b31mg_.log thread=1 sequence=104
media recovery complete, elapsed time: 00:00:02
Finished recover at 01-APR-14

成功打开数据库
SQL> alter database open RESETLOGS;// RESETLOGS 会把online redelog file清空,数据文件丢失.所以这个时候要做一个全备份。否则下次恢复会出错

Database altered.

4、redo log 丢失

SQL>  select group# , member from v$logfile;//查看redolog文件位置

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  2020192 bytes
Variable Size              88083616 bytes
Database Buffers          188743680 bytes
Redo Buffers                6365184 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/orcl/redo01.log'


SQL> recover database until cancel;
Media recovery complete.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;//RESETLOGS会把online redelog file清空,数据文件丢失.所以这个时候要做一个全备份。否则下次恢复会出错

Database altered.

5、数据文件恢复
SQL> select FILE#,  NAME,STATUS from v$datafile;  //查看数据文件位置状态

RMAN> sql "alter database datafile 4 offline"; //模拟丢失

using target database control file instead of recovery catalog
sql statement: alter database datafile 4 offline
恢复:
RMAN> restore datafile 4  ;

Starting restore at 01-APR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=141 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/inc0_0bp4m461_20140401
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/inc0_0bp4m461_20140401 tag=LEVEL0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 01-APR-14

RMAN> recover datafile 4;

Starting recover at 01-APR-14
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:05
Finished recover at 01-APR-14

RMAN> sql "alter database datafile 4 online";
sql statement: alter database datafile 4 online

6、 表空间丢失
SQL> select tablespace_name ,sum(bytes)/1024/1024 M from dba_data_files group by tablespace_name;//查看表空间及大小

RMAN> sql "alter tablespace users offline";//模拟丢失

using target database control file instead of recovery catalog
sql statement: alter tablespace users offline
恢复:
RMAN>  restore tablespace users;

Starting restore at 01-APR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=140 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/inc0_0bp4m461_20140401
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/inc0_0bp4m461_20140401 tag=LEVEL0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 01-APR-14

RMAN> recover tablespace users;

Starting recover at 01-APR-14
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 01-APR-14

RMAN> sql "alter tablespace users online";
sql statement: alter tablespace users online

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27500440/viewspace-1136796/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27500440/viewspace-1136796/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值