OS:RHEL 3
CPU:4个Intel(R) Xeon(TM) MP CPU 2.70GHz
Mem:8G
Swap:16G
Disk:120G
Oracle Database 10g Enterprise Edition Release 10.1.0.3.0
数据库以archive模式运行,RMAN多级增量备份。策略如下:
设置控制文件自动备份。
每三个月做一个数据库的全备份(包括所有得数据库和只读表空间),并备份归档日志。
每一个月做一次零级备份(不包含只读表空间),并备份归档日志。
每周做一次一级备份,并备份归档日志。
每天做一次二级备份,并备份归档日志。
所有恢复的前提:已经做过数据库全备份(包括归档日志),控制文件和spfile自动备份。
(1)故障模拟
删除数据文件:rm /u02/oradata/dbnms/users01.dbf
关闭数据库:shutdown immediate;
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/u02/oradata/dbnms/users01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
强行关闭:sutdown abort;
启动数据库:startup;
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u02/oradata/dbnms/users01.dbf'
(2)恢复步骤
rman target sys@dbnms catalog rmanuser@cata
run{
allocate channel c1 type disk;
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
sql 'alter database open';
release channel c1;
}
sqlplus sys as sysdba
select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
dbnms OPEN
恢复成功
如果:数据空间没有备份,又要强行启动数据库
Sql> shutdown immediate;
Sql>startup mount;
Sql>alter database datafile '/oradata/test.dbf'' offline drop;
Sql>alter database open;
(1)故障模拟
删除数据文件:rm /u02/oradata/dbnms/*.dbf
强行关闭:sutdown abort;
启动数据库:startup;
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u02/oradata/dbnms/system01.dbf'
(2)恢复步骤
rman target sys@dbnms catalog rmanuser@cata
run{
allocate channel c1 type disk;
restore database;
recover database;
sql 'alter database open';
release channel c1;
}
sqlplus sys as sysdba
select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
dbnms OPEN
恢复临时文件:
alter database tempfile '/u02/oradata/dbnms/temp01.dbf' drop;
alter tablespace temp add tempfile '/u02/oradata/dbnms/temp01.dbf' size 50M autoextend on next 5M maxsize unlimited;
恢复成功
(1)故障模拟
删除日志文件:rm /u02/oradata/dbnms/redo01.log
关闭数据库:shutdown immediate;
启动数据库:startup;
select * from v$logfile;--可以考虑从v$log视图中去查找
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- ------------------------------ ---
3 ONLINE /u02/oradata/dbnms/redo03.log NO
2 STALE ONLINE /u02/oradata/dbnms/redo02.log NO
1 INVALID ONLINE /u02/oradata/dbnms/redo01.log NO
1 STALE ONLINE /u02/oradata/dbnms/redo11.log NO
1 STALE ONLINE /u02/oradata/dbnms/redo21.log NO
2 STALE ONLINE /u02/oradata/dbnms/redo12.log NO
3 ONLINE /u02/oradata/dbnms/redo13.log NO
2 STALE ONLINE /u02/oradata/dbnms/redo22.log NO
3 ONLINE /u02/oradata/dbnms/redo23.log NO
4 ONLINE /u02/oradata/dbnms/redo31.log NO
4 ONLINE /u02/oradata/dbnms/redo32.log NO
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- ------------------------------ ---
4 ONLINE /u02/oradata/dbnms/redo33.log NO
(2)恢复步骤
alter database drop logfile member '/u02/oradata/dbnms/redo01.log';
alter database add logfile member '/u02/oradata/dbnms/redo01.log' to group 1;
恢复成功
(1)故障模拟
删除日志文件组1的所有文件:
rm /u02/oradata/dbnms/redo01.log
rm /u02/oradata/dbnms/redo11.log
rm /u02/oradata/dbnms/redo21.log
关闭数据库:shutdown immediate;
启动数据库:startup;
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo11.log'
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo21.log'
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo01.log'
(2)恢复步骤
alter database clear logfile group 1;
如果该日志组还没有归档,则用:
alter database clear unarchived logfile group 1;
打开数据库:
alter database open;
恢复成功
(1)故障模拟
删除日志文件:rm /u02/oradata/dbnms/*.log
关闭数据库:shutdown immediate;
启动数据库:startup;
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo11.log'
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo21.log'
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo01.log'
(2)恢复步骤
shutdown immediate;
create pfile from spfile;
cd $ORACLE_HOME/dbs
vi initdbnms.ora
加一个参数:_allow_resetlogs_corruption=true
create spfile from pfile;
startup;
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo11.log'
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo21.log'
ORA-00312: online log 1 thread 1: '/u02/oradata/dbnms/redo01.log'
recover database until cancel;
alter database open resetlogs;
同步catalog:
rman target sys@dbnms catalog rmanuser@cata
reset database;
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
做一个full备份:
/home/oracle/dbbat/backup_full.sh
恢复成功
破坏的为当期的:
SQL> select GROUP#,SEQUENCE#,ARCHIVED,STATUS from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- --------- ------------------------------------------------
1 1 NO CURRENT
3 0 YES UNUSED
2 0 YES UNUSED
SQL> recover database until cancel;
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
SQL>
(1)故障模拟
删除控制文件:rm /u02/oradata/dbnms/control01.ctl
关闭数据库:shutdown immediate;
ORA-00210: cannot open the specified controlfile
ORA-00202: controlfile: '/u02/oradata/dbnms/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
(2)恢复步骤
拷贝一个好的控制文件:
cp control02.ctl control01.ctl
shutdown immediate;
startup;
Database mounted.
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u02/oradata/dbnms/system01.dbf'
ORA-01207: file is more recent than controlfile - old controlfile
rman target sys@dbnms catalog rmanuser@cata
run{
allocate channel c1 type disk;
restore database;
recover database;
sql 'alter database open';
release channel c1;
}
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of sql command on default channel at 09/08/2005 17:29:04
RMAN-11003: failure during parse/execution of SQL statement: alter database open
ORA-00322: log 3 of thread 1 is not current copy
ORA-00312: online log 3 thread 1: '/u02/oradata/dbnms/redo03.log'
ORA-00312: online log 3 thread 1: '/u02/oradata/dbnms/redo13.log'
ORA-00312: online log 3 thread 1: '/u02/oradata/dbnms/redo23.log'
alter database clear unarchived logfile group 3;
alter database open;
恢复成功
说明:如果是裸设备,文件不能直接复制,恢复一个控制文件
思路:比如ctl1损坏,可以让ctl2和ctl3工作
a. 根据spfile创建pfile
Sql>startup nomunt;
Sql>cretate pfile=' /oracle/init.ora' from spfile
b. 修改file内容,是里面的控制文件配置方式,然后从pfile启动
Sql>startup pfile=' /oracle/init.ora'
注:如果在操作系统里面不给修改,可以将文件拷出来修改
(1)故障模拟
删除控制文件:rm /u02/oradata/dbnms/control01.ctl
关闭数据库:shutdown immediate;
ORA-00210: cannot open the specified controlfile
ORA-00202: controlfile: '/u02/oradata/dbnms/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
(2)恢复步骤
shutdown abort;
startup nomount;
rman target sys catalog rmanuser@cata
run{
allocate channel c1 type disk;
restore controlfile;
restore database;
sql 'alter database mount';
recover database;
sql 'alter database open resetlogs';
release channel c1;
}
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/08/2005 17:43:31
RMAN-06054: media recovery requesting unknown log: thread 1 seq 9 lowscn 670233
alter database open resetlogs;
做一个full备份:
/home/oracle/dbbat/backup_full.sh
恢复成功
如果没有备份:可以考虑重建控制文件:但是这个是最后一步,万不得已千万不要用
重建控制文件,此时的初始化参数文件还是用的3个控制文件
Sql>shutdown immediate;
Sql>startup;
--这个时候会报缺少控制文件的错误
Sql>e'路径';
--找到目录下面的sql文件,把创建控制文件的脚步找出来,在sql窗口刷一遍,下面就可以打开数据库了
Sql> alter database open; --或者 alter database open resetlogs;
(1)故障模拟
删除临时数据文件:rm /u02/oradata/dbnms/temp01.dbf
关闭数据库:shutdown immediate;
启动数据库:startup;
(2)恢复步骤
alter database tempfile '/u02/oradata/dbnms/temp01.dbf' drop;
ERROR at line 1:
ORA-01516: nonexistent log file, datafile, or tempfile
"/u02/oradata/dbnms/temp01.dbf"
alter tablespace temp add tempfile '/u02/oradata/dbnms/temp01.dbf' size 50M autoextend on next 5M maxsize unlimited;
恢复成功
(1)故障模拟
删除spfile文件:rm $ORACLE_HOME/dbs/spfiledbnms.ora
关闭数据库:shutdown immediate;
启动数据库:startup;
(2)恢复步骤
startup nomount;
rman target sys catalog rmanuser@cata
restore spfile;
shutdown immediate;
startup;
恢复成功
(1)故障模拟
删除全部文件:rm /u02/oradata/dbnms/*
关闭数据库:shutdown immediate;
ORA-03113: end-of-file on communication channel
(2)恢复步骤
sqlplus sys as sysdba
startup nomount;
rman target sys catalog rmanuser@cata
还原控制文件:restore controlfile;
还原数据库:restore database;
mount 数据库:alter database mount;
恢复数据库:recover database;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/09/2005 10:33:13
RMAN-06054: media recovery requesting unknown log: thread 1 seq 19 lowscn 718284
用resetlogs方式打开数据库:alter database open resetlogs;
database opened
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
重建临时文件:
sqlplus sys as sysdba
alter database tempfile '/u02/oradata/dbnms/temp01.dbf' drop;
ERROR at line 1:
ORA-01516: nonexistent log file, datafile, or tempfile
"/u02/oradata/dbnms/temp01.dbf"
alter tablespace temp add tempfile '/u02/oradata/dbnms/temp01.dbf' size 50M autoextend on next 5M maxsize unlimited;
执行一次全库备份:/home/oracle/dbbat/backup_full.sh
恢复成功