用户管理恢复
************************************
一、Oracle恢复的体系结构ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' REUSE;
****************************************
RMAN恢复
****************************************
1、RMAN完全恢复
(1)***场景1:参数文件损坏
backup spfile;
--create pfile='/tmp/pfile.ora' from spfile;
shutdown immediate;
rm -rf $ORACLE_HOME/dbs/spfileocp.ora
startup pfile='/tmp/pfile.ora' nomount;
set dbid 43434343
restore spfile from autobackup;
restore spfile to '/temp/spfile.ora' from autobackup;
(2)***场景2:控制文件损坏
backup current controlfile;
rm -rf control*
startup nomount;
set dbid=2690543208;
restore controlfile from autobackup;--db_recovery_file_dest或$ORACLE_HOME/dbs(set dbid)
alter database mount;
recover database;
alter database open resetlogs;
(3) ***场景3 system表空间数据文件损坏
backup database;
rm -rf system01.dbf;
shutdown abort;
startup mount;
restore datafile 1;
recover datafile 1;
alter database open;
(4)***场景4 undo表空间损坏
startup mount;
restore tablespace UNDOTBS1;
recover database;
alter database open;
(5)***场景5:磁盘损坏
rm -rf tp1.dbf
select name,file# from v$datafile;
run{ shutdown abort;
startup mount;
set newname for datafile 6 to '/u01/app/oracle/oradata/ocm/tp1.dbf';
restore datafile 6;
switch datafile 6 ;
recover database;
alter database open;}
(6)***场景6:普通数据文件损坏
rm -rf tp1.dbf
方法一
run{
shutdown abort;
startup mount;
restore datafile 6;
recover datafile 6;
alter database open;}
方法二
run{
sql 'alter database datafile 6 offline';
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';}
方法三
run{
shutdown abort;
startup mount;
sql 'alter database datafile 6 offline';
alter database open;
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';}
(7)控制文件无损的情况下,只读文件损坏
***场景1:只读数据文件丢失
run{
shutdown abort;
startup mount;
restore datafile 5;
alter database open;}
***场景2:只读数据文件在实例运行时丢失
run{
sql 'alter database datafile 5 offline';
restore datafile 5;
sql 'alter database datafile 5 online';}
***场景3:只读数据文件内部数据块损坏
run{
sql 'alter database datafile 5 offline';
restore datafile 5 force;
sql 'alter database datafile 5 online';}
***场景4:起先数据文件备份时是只读状态,后来其表空间改为读写状态,但没有备份,现数据文件坏了
run{
sql 'alter database datafile 6 offline';
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';}
(8)控制文件损坏的情况下,只读文件损坏
分析只读表空间在控制文件的情况
alter database backup controlfile to trace as '/backup/control.bak01';
alter tablespace read only;
alter database backup controlfile to trace as '/backup/control.bak02';
diff control.bak01 control.bak02 --比较两个备份的控制文件
alter database rename file '' to ''; --只读表空间在重构时不考虑,要在数据库打开后,重命名数据文件
alter database tp1 online;
***场景1:只读数据文件连同控件文件一并损坏或丢失
run{
shutdown abort;
startup nomount;
restore controlfile from autobackup;
alter database mount;
restore datafile 6;
recover database;
alter database open resetlogs;}
***场景2:在数据文件为只读状态时,对该文件和控制文件进行了备份,随且对该表空间改为读写状态,但该文件和控制文件均未再有过备份,此时该数据文件连同控件文件一并损坏或丢失
run{
shutdown abort;
startup nomount;
restore controlfile from '/backup/rman/full_0cnnlmfd_1_1';
mount database;
restore datafile 6;
recover database;
recover database; --注意再次执行
alter database open resetlogs;}
(9)表空间的恢复
[oracle@redhat55 ~]$ rman target/
Recovery Manager:Release 10.2.0.1.0 - Production on 星期二 4月 30 23:23:19 2013
Copyright (c) 1982,2005, Oracle. All rights reserved.
connected to targetdatabase: ORCL (DBID=1341748519)
RMAN> list backup;
using targetdatabase control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time CompletionTime
------- ---- ------------ ----------- ------------ -------------------
1 Full 30.83M DISK 00:01:00 2013-04-30 23:21:46
BP Key: 1 Status: AVAILABLE Compressed: YES Tag: TAG20130430T232045
Piece Name:/disk1/backup/orcl/02o8dnae_1_1.bak
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- -----------------------
2 Full 573612 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/undotbs01.dbf
3 Full 573612 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/sysaux01.dbf
5 Full 573612 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/example01.dbf
BS Key Type LV Size Device Type Elapsed Time CompletionTime
------- ---- ------------ ----------- ------------ -------------------
2 Full 80.84M DISK 00:01:19 2013-04-30 23:22:05
BP Key: 2 Status: AVAILABLE Compressed: YES Tag: TAG20130430T232045
Piece Name:/disk1/backup/orcl/01o8dnae_1_1.bak
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- -----------------------
1 Full 573611 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/system01.dbf
4 Full 573611 2013-04-3023:20:46 /u01/app/oracle/oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time CompletionTime
------- ---- ------------ ----------- ------------ -------------------
3 Full 6.80M DISK 00:00:00 2013-04-30 23:22:07
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20130430T232207
Piece Name: /disk1/backup/orcl/c-1341748519-20130430-00.clt
Control File Included: Ckp SCN: 573653 Ckp time: 2013-04-30 23:22:07
SPFILE Included: Modification time:2013-04-30 23:17:26
RMAN>
[oracle@redhat55 ~]$ sqlplus /as sysdba
SQL*Plus: Release10.2.0.1.0 - Production on 星期二 4月 30 23:24:35 2013
Copyright (c) 1982,2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10gEnterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL>
SQL> create tablespace tbsdatafile '/u01/app/oracle/oradata/orcl/tbs.dbf' size 5m;
Tablespace created.
SQL> create table t (id int)tablespace tbs;
Table created.
SQL> insert into t values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
ID
----------
1
SQL> select file_name fromdba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
/u01/app/oracle/oradata/orcl/tbs.dbf
6 rows selected.
SQL> select current_scn fromv$database;
CURRENT_SCN
-----------
573950 // 恢复时恢复到这个SCN号
SQL> alter system archive logcurrent;
System altered.
SQL> alter system archive logcurrent;
System altered.
SQL> alter system archive logcurrent;
System altered.
SQL> alter system archive logcurrent;
System altered.
SQL>
SQL> drop tablespace tbsINCLUDING CONTENTS and datafiles;
Tablespace dropped.
SQL> select file_namefrom dba_data_files; // 表空间对应的数据文件已经没有了
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
SQL>
SQL> shutdown abort;
ORACLE instance shutdown.
SQL> startup nomount;
ORACLE instancestarted.
Total System GlobalArea 1224736768 bytes
Fixed Size 2020384 bytes
Variable Size 318770144 bytes
DatabaseBuffers 889192448 bytes
Redo Buffers 14753792 bytes
SQL>
SQL> exit
Disconnected fromOracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
[oracle@redhat55 ~]$ rman target/
Recovery Manager:Release 10.2.0.1.0 - Production on 星期二 4月 30 23:29:31 2013
Copyright (c) 1982,2005, Oracle. All rights reserved.
connected to targetdatabase: orcl (not mounted)
RMAN> restore controlfilefrom '/disk1/backup/orcl/c-1341748519-20130430-00.clt';
Starting restore at2013-04-30 23:29:54
using targetdatabase control file instead of recovery catalog
allocated channel:ORA_DISK_1
channel ORA_DISK_1:sid=156 devtype=DISK
channel ORA_DISK_1:restoring control file
channel ORA_DISK_1:restore complete, elapsed time: 00:00:02
outputfilename=/u01/app/oracle/oradata/orcl/control01.ctl
outputfilename=/u01/app/oracle/oradata/orcl/control02.ctl
outputfilename=/u01/app/oracle/oradata/orcl/control03.ctl
Finished restore at2013-04-30 23:29:57
RMAN> shutdown abort;
Oracle instance shutdown
RMAN> startup mount;
connected to targetdatabase (not started)
Oracle instancestarted
database mounted
Total System GlobalArea 1224736768 bytes
Fixed Size 2020384 bytes
Variable Size 318770144 bytes
DatabaseBuffers 889192448 bytes
Redo Buffers 14753792 bytes
RMAN> restore database;
Starting restore at2013-04-30 23:30:30
Starting implicitcrosscheck backup at 2013-04-30 23:30:30
allocated channel:ORA_DISK_1
channel ORA_DISK_1:sid=157 devtype=DISK
allocated channel:ORA_DISK_2
channel ORA_DISK_2:sid=155 devtype=DISK
Crosschecked 2objects
Finished implicitcrosscheck backup at 2013-04-30 23:30:33
Starting implicitcrosscheck copy at 2013-04-30 23:30:33
using channelORA_DISK_1
using channelORA_DISK_2
Finished implicitcrosscheck copy at 2013-04-30 23:30:33
searching for allfiles in the recovery area
cataloging files...
no files cataloged
using channelORA_DISK_1
using channelORA_DISK_2
channel ORA_DISK_1:starting datafile backupset restore
channel ORA_DISK_1:specifying datafile(s) to restore from backup set
restoring datafile00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile00005 to /u01/app/oracle/oradata/orcl/example01.dbf
channel ORA_DISK_1:reading from backup piece /disk1/backup/orcl/02o8dnae_1_1.bak
channel ORA_DISK_2:starting datafile backupset restore
channel ORA_DISK_2:specifying datafile(s) to restore from backup set
restoring datafile00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_2:reading from backup piece /disk1/backup/orcl/01o8dnae_1_1.bak
channel ORA_DISK_1:restored backup piece 1
piecehandle=/disk1/backup/orcl/02o8dnae_1_1.bak tag=TAG20130430T232045
channel ORA_DISK_1:restore complete, elapsed time: 00:00:46
channel ORA_DISK_2:restored backup piece 1
piecehandle=/disk1/backup/orcl/01o8dnae_1_1.bak tag=TAG20130430T232045
channel ORA_DISK_2:restore complete, elapsed time: 00:01:11
Finished restore at2013-04-30 23:31:45
RMAN>
RMAN> run{
2> set until scn 573950;
3> recover database;
4> }
executing command:SET until clause
Starting recover at2013-04-30 23:33:37
using channelORA_DISK_1
using channelORA_DISK_2
starting mediarecovery
archive logfilename=/disk1/backup/orcl/1_3_813967785.arc thread=1 sequence=3
creating datafilefno=6 name=/u01/app/oracle/oradata/orcl/tbs.dbf
archive logfilename=/disk1/backup/orcl/1_3_813967785.arc thread=1 sequence=3
media recoverycomplete, elapsed time: 00:00:03
Finished recover at2013-04-30 23:33:43
RMAN> sql'alter database openresetlogs';
sql statement: alterdatabase open resetlogs
RMAN> exit
Recovery Managercomplete.
[oracle@redhat55 ~]$ sqlplus /as sysdba
SQL*Plus: Release10.2.0.1.0 - Production on 星期二 4月 30 23:34:03 2013
Copyright (c) 1982,2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10gEnterprise Edition Release 10.2.0.1.0 - 64bit Production
With thePartitioning, OLAP and Data Mining options
SQL> select file_name fromdba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
/u01/app/oracle/oradata/orcl/tbs.dbf // 表空间已经恢复
6 rows selected.
SQL> select * from t;
ID
----------
1
SQL>
总结:表空间在没有备份的情况下被DROP,此时若想恢复被DROP的表空间,必须使用DROP之前的备份及控制文件,然后利用归档日志再将数据库恢复到DROP之间的点,表空间会被归档日志里重新创建。
*******************************************
总结
*******************************************
一、关于recover database命令
(1)SQL>recover database;
该命令用来对所有数据文件进行恢复,并且只能使用保存在文件系统上的归档日志及在线日志。使用此命令的前提是控制文件不可以是还原或重建得来的。
Oracle会以当前controlfile所记录的SCN为准,利用archive log和 redo log的redo entry, 把相关的datafile 的 block恢复到“当前controlfile所记录的SCN”
(2)SQL>recover database using backup controlfile;
该命令用来对所有数据文件及控制文件进行恢复,并且只使用保存在文件系统上的归档及在线日志。
Oracle需要把数据恢复到比当前controlfile所记录的SCN还要靠后的位置(比如说,control file是backup controlfile , 或者 controlfile是根据trace create的。),这时候,就需要用using backup controlfile. 恢复就不会受“当前controlfile所记录的SCN”的限制。
(3)RMAN>recover database;
该命令用来对所有数据文件及控制文件进行恢复,并且可以使用增量备份、备份中的和文件系统上的归档日志,以及在线日志。
二、关于resetlogs命令
(1)用备份的控制文件做恢复必须要resetlogs,使用resetlogs的原因是recover命令只能修复控制文件中数据库物理结构信息,而无法修改控制文件中的当前重做日志的序列号等信息
(2)不完全恢复的resetlogs
三、数据库的化身--Incarnation
v$database_incarnation
RMAN>list incarnation
**********本博客所有内容均为原创,如有转载请注明作者和出处!!!**********
Name: guoyJoe
QQ: 252803295
Email: [email protected]
Blog: http://blog.csdn.net/guoyJoe
ITPUB: http://www.itpub.net/space-uid-28460966.html
OCM: http://education.oracle.com/education/otn/YGuo.HTM
_____________________________________________________________
加群验证问题:哪些SGA结构是必需的,哪些是可选的?否则拒绝申请!!!
答案在:http://blog.csdn.net/guoyjoe/article/details/8624392
DSI&Core Search(QQ群):127149411