首页 > 代码库 > rac完全恢复学习

rac完全恢复学习

1、查看现有数据库文件

SQL> select name from v$datafile;NAME--------------------------------------------------------------------------------+DATA/rac/datafile/system.259.866566403+DATA/rac/datafile/undotbs1.260.866566407+DATA/rac/datafile/sysaux.261.866566407+DATA/rac/datafile/undotbs2.263.866566409+DATA/rac/datafile/users.264.866566409

2、做一个完全备份

RMAN> backup as copy database ;

 

3、创建表空间

SQL> create tablespace zxm datafile size 2m;Tablespace created.SQL> create tablespace user01 datafile +DATA size 1M;Tablespace created.SQL> alter tablespace user01 add datafile size 1m;Tablespace altered.SQL> select name from v$datafile;NAME--------------------------------------------------------------------------------+DATA/rac/datafile/system.259.866566403+DATA/rac/datafile/undotbs1.260.866566407+DATA/rac/datafile/sysaux.261.866566407+DATA/rac/datafile/undotbs2.263.866566409+DATA/rac/datafile/users.264.866566409+DATA/rac/datafile/zxm.287.866732569+DATA/rac/datafile/user01.284.866732649+DATA/rac/datafile/user01.288.8667327338 rows selected.

4、创建示例数据

SQL> create table test as select * from user_tables;Table created.SQL> create table test2 as select * from test;Table created.SQL> col TABLESPACE_NAME format a30SQL> col SEGMENT_NAME format a30SQL> select tablespace_name,segment_name from user_segments;TABLESPACE_NAME                SEGMENT_NAME------------------------------ ------------------------------USER01                         TESTUSER01                         TEST2

5、关闭数据库删除文件,模拟灾难场景

[oracle@rac1 admin]$ srvctl stop database -d rac[oracle@rac1 admin]$ export ORACLE_SID=+ASM1[oracle@rac1 admin]$ asmcmd -pASMCMD [+] > lsDATA/RECV/ASMCMD [+] > cd DATAASMCMD [+DATA] > lsRAC/TEST/ASMCMD [+DATA] > cd RACASMCMD [+DATA/RAC] > lsARCHIVELOG/CONTROLFILE/DATAFILE/ONLINELOG/PARAMETERFILE/TEMPFILE/spfilerac.oraASMCMD [+DATA/RAC] > cd DATAFILEASMCMD [+DATA/RAC/DATAFILE] > lsSYSAUX.261.866566407SYSTEM.259.866566403TEST.282.866646695UNDOTBS1.260.866566407UNDOTBS2.263.866566409USER01.284.866732649USER01.288.866732733USERS.264.866566409ZXM.287.866732569ASMCMD [+DATA/RAC/DATAFILE] > rm USER01.284.866732649ASMCMD [+DATA/RAC/DATAFILE] > rm USER01.288.866732733ASMCMD [+DATA/RAC/DATAFILE] > rm ZXM.287.866732569[oracle@rac1 admin]$ export ORACLE_SID=rac1[oracle@rac1 admin]$ sqlplus / as sysdbaSQL*Plus: Release 10.2.0.4.0 - Production on Fri Dec 19 15:31:22 2014Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.Connected to an idle instance.SQL> startup;ORACLE instance started.Total System Global Area 1610612736 bytesFixed Size                  2280840 bytesVariable Size             416100984 bytesDatabase Buffers         1157627904 bytesRedo Buffers               34603008 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 6 - see DBWR trace fileORA-01110: data file 6: +DATA/rac/datafile/zxm.287.866732569

6、recover命令只能在已有的物理文件上进行恢复,所以需要先创建数据文件

SQL> alter database create datafile 6;Database altered.SQL> recover datafile 6;             ORA-00283: recovery session canceled due to errorsORA-01110: data file 6: +DATA/rac/datafile/zxm.287.866732569ORA-01157: cannot identify/lock data file 6 - see DBWR trace fileORA-01110: data file 6: +DATA/rac/datafile/zxm.287.866732569进入目录中看新创建的文件是:ZXM.287.866734565ASMCMD [+DATA/RAC] > cd DATAFILEASMCMD [+DATA/RAC/DATAFILE] > lsSYSAUX.261.866566407SYSTEM.259.866566403TEST.282.866646695UNDOTBS1.260.866566407UNDOTBS2.263.866566409USERS.264.866566409ZXM.287.866734565而控制中的文件为:SQL> select name from v$datafile;NAME--------------------------------------------------------------------------------+DATA/rac/datafile/system.259.866566403+DATA/rac/datafile/undotbs1.260.866566407+DATA/rac/datafile/sysaux.261.866566407+DATA/rac/datafile/undotbs2.263.866566409+DATA/rac/datafile/users.264.866566409+DATA/rac/datafile/zxm.287.866732569+DATA/rac/datafile/user01.284.866732649+DATA/rac/datafile/user01.288.8667327338 rows selected.需要对数据文件进行改名,其实就是修改控制文件SQL> alter database rename file +DATA/rac/datafile/zxm.287.866732569 to +DATA/rac/datafile/ZXM.287.866734565;Database altered.再次操作,这次恢复成功了SQL> recover datafile 6;Media recovery complete.

7、恢复其他的数据文件

SQL> alter database open;alter database open*ERROR at line 1:ORA-01157: cannot identify/lock data file 7 - see DBWR trace fileORA-01110: data file 7: +DATA/rac/datafile/user01.284.866732649只恢复了一个文件,刚总共删除了3个,那现在重新再将剩下的两个创建了SQL> alter database create datafile +DATA/rac/datafile/user01.284.866732649;Database altered.SQL> recover datafile 7;ORA-00283: recovery session canceled due to errorsORA-01110: data file 7: +DATA/rac/datafile/user01.284.866732649ORA-01157: cannot identify/lock data file 7 - see DBWR trace fileORA-01110: data file 7: +DATA/rac/datafile/user01.284.866732649进入文件目录查看,发现文件名不是创建的那个ASMCMD [+DATA/RAC/DATAFILE] > lsSYSAUX.261.866566407SYSTEM.259.866566403TEST.282.866646695UNDOTBS1.260.866566407UNDOTBS2.263.866566409USER01.288.866735415USERS.264.866566409ZXM.287.866734565SQL> alter database rename file +DATA/rac/datafile/user01.284.866732649 to +DATA/rac/datafile/USER01.288.866735415;Database altered.SQL> recover datafile 7;Media recovery complete.SQL> alter database create datafile +DATA/rac/datafile/user01.288.866732733;ASMCMD [+DATA/RAC/DATAFILE] > lsSYSAUX.261.866566407SYSTEM.259.866566403TEST.282.866646695UNDOTBS1.260.866566407UNDOTBS2.263.866566409USER01.284.866736519USER01.288.866735415USERS.264.866566409ZXM.287.866734565SQL> alter database rename file +DATA/rac/datafile/user01.288.866732733 to +DATA/rac/datafile/USER01.284.866736519;SQL> alter database rename file +DATA/rac/datafile/user01.288.866732733 to +DATA/rac/datafile/USER01.284.866736519;Database altered.SQL> recover datafile 8;Media recovery complete.打开数据SQL> alter database open;Database altered.

 

rac完全恢复学习