白酒泡枸杞比例:ORACLE备份&恢复案例之二

来源:百度文库 编辑:偶看新闻 时间:2024/04/28 04:45:16
ORACLE备份&恢复案例之二(精品) 2006-10-22 15:54:38标签:备份 oracle 数据容灾 容灾系统 复制

4.3丢失多个数据文件,实现整个数据库的恢复

4.3.1 OS备份方案

OS备份归档模式下损坏(丢失)多个数据文件,进行整个数据库的恢复1、连接数据库,创建测试表并插入记录SQL*Plus: Release 8.1.6.0.0 - Production on Tue May 6 13:46:32 2003(c) Copyright 1999 Oracle Corporation. All rights reserved.SQL> connect internal/password as sysdba;Connected.SQL> create table test(a int);Table createdSQL> insert into test values(1);1 row insertedSQL> commit;Commit complete2、备份数据库,备份除临时数据文件后的所数据文件SQL> @hotbak.sql 或在DOS下 svrmgrl @hotbak.sql3、继续在测试表中插入记录SQL> insert into test values(2);1 row insertedSQL> commit;Commit completeSQL> select * from test;A---------------------------------------12SQL> alter system switch logfile;System altered.SQL> alter system switch logfile;System altered.4、关闭数据库,模拟丢失数据文件SQL> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut downC:>del D:ORACLEORADATATESTSYSTEM01.DBFC:>del D:ORACLEORADATATESTINDX01.DBFC:>del D:ORACLEORADATATESTTOOLS01.DBFC:>del D:ORACLEORADATATESTRBS01.DBF模拟媒体毁坏(这里删除多个数据文件)5、启动数据库,检查错误SQL> STARTUPORACLE instance started.Total System Global Area 102020364 bytesFixed Size 70924 bytesVariable Size 85487616 bytesDatabase Buffers 16384000 bytesRedo Buffers 77824 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 1 - see DBWR trace fileORA-01110: data file 1: 'D:ORACLEORADATATESTSYSTEM01.DBF'详细信息可以查看报警文件ORA-1157 signalled during: ALTER DATABASE OPEN...Thu May 08 09:39:36 2003Errors in file D:OracleadmintestbdumptestDBW0.TRC:ORA-01157: cannot identify/lock data file 1 - see DBWR trace fileORA-01110: data file 1: 'D:ORACLEORADATATESTSYSTEM01.DBF'ORA-27041: unable to open fileOSD-04002: unable to open fileO/S-Error: (OS 2) 系统找不到指定的文件。Thu May 08 09:39:36 2003Errors in file D:OracleadmintestbdumptestDBW0.TRC:ORA-01157: cannot identify/lock data file 2 - see DBWR trace fileORA-01110: data file 2: 'D:ORACLEORADATATESTRBS01.DBF'ORA-27041: unable to open fileOSD-04002: unable to open fileO/S-Error: (OS 2) 系统找不到指定的文件。Thu May 08 09:39:36 2003Errors in file D:OracleadmintestbdumptestDBW0.TRC:ORA-01157: cannot identify/lock data file 5 - see DBWR trace fileORA-01110: data file 5: 'D:ORACLEORADATATESTTOOLS01.DBF'ORA-27041: unable to open fileOSD-04002: unable to open fileO/S-Error: (OS 2) 系统找不到指定的文件。Thu May 08 09:39:36 2003Errors in file D:OracleadmintestbdumptestDBW0.TRC:ORA-01157: cannot identify/lock data file 6 - see DBWR trace fileORA-01110: data file 6: 'D:ORACLEORADATATESTINDX01.DBF'ORA-27041: unable to open fileOSD-04002: unable to open fileO/S-Error: (OS 2) 系统找不到指定的文件。通过查询v$recover_file可以看到SQL> select * from v$recover_file;FILE# ONLINE ERROR CHANGE# TIME---------- ------- ------------------ ---------- -----------1 ONLINE FILE NOT FOUND 0 2 ONLINE FILE NOT FOUND 0 5 ONLINE FILE NOT FOUND 0 6 ONLINE FILE NOT FOUND 0有四个数据文件需要恢复6、拷贝备份回到原地点(restore),开始恢复数据库(recover)restore过程:C:>copy D:DATABAKSYSTEM01.DBF D:ORACLEORADATATESTC:>copy D:DATABAKTESTINDX01.DBF D:ORACLEORADATATESTC:>copy D:DATABAKTESTTOOLS01.DBF D:ORACLEORADATATESTC:>copy D:DATABAKTESTRBS01.DBF.DBF D:ORACLEORADATATESTRecover过程:SQL> recover database;ORA-00279: change 1073849 generated at 05/08/2003 08:58:35 needed for thread 1ORA-00289: suggestion : D:ORACLEORADATATESTARCHIVETESTT001S00311.ARCORA-00280: change 1073849 for thread 1 is in sequence #311Specify log: {=suggested | filename | AUTO | CANCEL}autoORA-00279: change 1073856 generated at 05/08/2003 09:03:27 needed for thread 1ORA-00289: suggestion : D:ORACLEORADATATESTARCHIVETESTT001S00312.ARCORA-00280: change 1073856 for thread 1 is in sequence #312ORA-00278: log file 'D:ORACLEORADATATESTARCHIVETESTT001S00311.ARC' nolonger needed for this recoveryORA-00279: change 1073858 generated at 05/08/2003 09:11:43 needed for thread 1ORA-00289: suggestion : D:ORACLEORADATATESTARCHIVETESTT001S00313.ARCORA-00280: change 1073858 for thread 1 is in sequence #313ORA-00278: log file 'D:ORACLEORADATATESTARCHIVETESTT001S00312.ARC' nolonger needed for this recoveryORA-00279: change 1073870 generated at 05/08/2003 09:11:46 needed for thread 1ORA-00289: suggestion : D:ORACLEORADATATESTARCHIVETESTT001S00314.ARCORA-00280: change 1073870 for thread 1 is in sequence #314ORA-00278: log file 'D:ORACLEORADATATESTARCHIVETESTT001S00313.ARC' nolonger needed for this recoveryLog applied.Media recovery complete.7、打开数据库,检查数据库的数据(完全恢复)SQL> alter database open;Database altered.SQL> select * from test;A---------------------------------------12说明:1、只要有备份与归档存在,就可以实现数据库的完全恢复(不丢失数据)2、适合于丢失大量数据文件,或包含系统数据文件在内的数据库的恢复3、恢复过程在mount下进行,如果恢复成功,再打开数据库,down机时间可能比较长一些。

4.3.2 RMAN备份方案

RMAN备份归档模式下损坏(丢失)多个数据文件,进行整个数据库的恢复1、连接数据库,创建测试表并插入记录SQL*Plus: Release 8.1.6.0.0 - Production on Tue May 6 13:46:32 2003(c) Copyright 1999 Oracle Corporation. All rights reserved.SQL> connect internal/password as sysdba;Connected.SQL> create table test(a int);Table createdSQL> insert into test values(1);1 row insertedSQL> commit;Commit complete2、备份数据库DOS下 C:> rman cmdfile=bakup.rcv msglog=backup.log;以下是backup.log内容。Recovery Manager: Release 8.1.6.0.0 - ProductionRMAN> # script:bakup.rcv2> # creater:chenjiping3> # date:5.8.20034> # desc:backup all database datafile in archive with rman5> 6> #connect database7> connect rcvcat rman/rman@back;8> connect target internal/virpure;9> 10> #start backup database11> run{12> allocate channel c1 type disk;13> backup full tag 'dbfull' format 'd:backupfull%u_%s_%p' database14> include current controlfile;15> sql 'alter system archive log current';16> release channel c1;17> }18> #end19> RMAN-06008: connected to recovery catalog databaseRMAN-06005: connected to target database: TEST (DBID=1788174720)RMAN-03022: compiling command: allocateRMAN-03023: executing command: allocateRMAN-08030: allocated channel: c1RMAN-08500: channel c1: sid=15 devtype=DISKRMAN-03022: compiling command: backupRMAN-03023: executing command: backupRMAN-08008: channel c1: starting full datafile backupsetRMAN-08502: set_count=4 set_stamp=494074368 creation_time=15-MAY-03RMAN-08010: channel c1: specifying datafile(s) in backupsetRMAN-08522: input datafile fno=00002 name=D:ORACLEORADATATESTRBS01.DBFRMAN-08522: input datafile fno=00001 name=D:ORACLEORADATATESTSYSTEM01.DBFRMAN-08011: including current controlfile in backupsetRMAN-08522: input datafile fno=00005 name=D:ORACLEORADATATESTTOOLS01.DBFRMAN-08522: input datafile fno=00004 name=D:ORACLEORADATATESTTEMP01.DBFRMAN-08522: input datafile fno=00006 name=D:ORACLEORADATATESTINDX01.DBFRMAN-08522: input datafile fno=00003 name=D:ORACLEORADATATESTUSER01.DBFRMAN-08013: channel c1: piece 1 createdRMAN-08503: piece handle=D:BACKUPFULL04EN5UG0_4_1 comment=NONERMAN-08525: backup set complete, elapsed time: 00:01:16RMAN-03023: executing command: partial resyncRMAN-08003: starting partial resync of recovery catalogRMAN-08005: partial resync completeRMAN-03022: compiling command: sqlRMAN-06162: sql statement: alter system archive log currentRMAN-03023: executing command: sqlRMAN-03022: compiling command: releaseRMAN-03023: executing command: releaseRMAN-08031: released channel: c1Recovery Manager complete.到这里表示备份成功。3、继续在测试表中插入记录SQL> insert into test values(2);1 row insertedSQL> commit;Commit completeSQL> select * from test;A---------------------------------------12SQL> alter system switch logfile;System altered.SQL> alter system switch logfile;System altered.4、关闭数据库,模拟丢失数据文件SQL> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut downC:>del D:ORACLEORADATATESTSYSTEM01.DBFC:>del D:ORACLEORADATATESTINDX01.DBFC:>del D:ORACLEORADATATESTTOOLS01.DBFC:>del D:ORACLEORADATATESTRBS01.DBF5、启动数据库,检查错误SQL> STARTUPORACLE instance started.Total System Global Area 102020364 bytesFixed Size 70924 bytesVariable Size 85487616 bytesDatabase Buffers 16384000 bytesRedo Buffers 77824 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 1 - see DBWR trace fileORA-01110: data file 1: 'D:ORACLEORADATATESTSYSTEM01.DBF'查询v$recover_fileSQL> select * from v$recover_file;FILE# ONLINE ERROR CHANGE# TIME---------- ------- ------------------ ---------- -----------1 ONLINE FILE NOT FOUND 0 2 ONLINE FILE NOT FOUND 0 5 ONLINE FILE NOT FOUND 0 6 ONLINE FILE NOT FOUND 0可以知道有四个数据文件需要恢复6、利用RMAN进行恢复C:>rmanRecovery Manager: Release 8.1.6.0.0 - ProductionRMAN> connect rcvcat rman/rman@backRMAN-06008: connected to recovery catalog databaseRMAN> connect target internal/virpureRMAN-06005: connected to target database: TEST (DBID=1788174720)RMAN> run{2> allocate channel c1 type disk;3> restore database;4> recover database;5> sql 'alter database open';6> release channel c1;7> }RMAN-03022: compiling command: allocateRMAN-03023: executing command: allocateRMAN-08030: allocated channel: c1RMAN-08500: channel c1: sid=17 devtype=DISKRMAN-03022: compiling command: restoreRMAN-03025: performing implicit partial resync of recovery catalogRMAN-03023: executing command: partial resyncRMAN-08003: starting partial resync of recovery catalogRMAN-08005: partial resync completeRMAN-03022: compiling command: IRESTORERMAN-03023: executing command: IRESTORERMAN-08016: channel c1: starting datafile backupset restoreRMAN-08502: set_count=4 set_stamp=494074368 creation_time=15-MAY-03RMAN-08089: channel c1: specifying datafile(s) to restore from backup setRMAN-08523: restoring datafile 00001 to D:ORACLEORADATATESTSYSTEM01.DBFRMAN-08523: restoring datafile 00002 to D:ORACLEORADATATESTRBS01.DBFRMAN-08523: restoring datafile 00003 to D:ORACLEORADATATESTUSER01.DBFRMAN-08523: restoring datafile 00004 to D:ORACLEORADATATESTTEMP01.DBFRMAN-08523: restoring datafile 00005 to D:ORACLEORADATATESTTOOLS01.DBFRMAN-08523: restoring datafile 00006 to D:ORACLEORADATATESTINDX01.DBFRMAN-08023: channel c1: restored backup piece 1RMAN-08511: piece handle=D:BACKUPFULL04EN5UG0_4_1 tag=DBFULL params=NULLRMAN-08024: channel c1: restore completeRMAN-03023: executing command: partial resyncRMAN-08003: starting partial resync of recovery catalogRMAN-08005: partial resync completeRMAN-03022: compiling command: recoverRMAN-03022: compiling command: recover(1)RMAN-03022: compiling command: recover(2)RMAN-03022: compiling command: recover(3)RMAN-03023: executing command: recover(3)RMAN-08054: starting media recoveryRMAN-03022: compiling command: recover(4)RMAN-06050: archivelog thread 1 sequence 327 is already on disk as file D:ORACLEORADATATESTARCHIVETESTT001S00327.ARCRMAN-06050: archivelog thread 1 sequence 328 is already on disk as file D:ORACLEORADATATESTARCHIVETESTT001S00328.ARCRMAN-06050: archivelog thread 1 sequence 329 is already on disk as file D:ORACLEORADATATESTARCHIVETESTT001S00329.ARCRMAN-06050: archivelog thread 1 sequence 330 is already on disk as file D:ORACLEORADATATESTARCHIVETESTT001S00330.ARCRMAN-03023: executing command: recover(4)RMAN-08515: archivelog filename=D:ORACLEORADATATESTARCHIVETESTT001S00327.ARC thread=1 sequence=327RMAN-08515: archivelog filename=D:ORACLEORADATATESTARCHIVETESTT001S00328.ARC thread=1 sequence=328RMAN-08055: media recovery completeRMAN-03022: compiling command: sqlRMAN-06162: sql statement: alter database openRMAN-03023: executing command: sqlRMAN-03022: compiling command: releaseRMAN-03023: executing command: releaseRMAN-08031: released channel: c1RMAN>7、检查数据库的数据(完全恢复)SQL> select * from test;A---------------------------------------12说明:1、只要有备份与归档存在,RMAN也可以实现数据库的完全恢复(不丢失数据)2、同OS备份数据库恢复,适合于丢失大量数据文件,或包含系统数据文件在内的数据库的恢复3、目标数据库在mount下进行,如果恢复成功,再打开数据库。4、RMAN的备份与恢复命令相对比较简单并可靠,建议有条件的话,都采用RMAN进行数据库的备份。