当前位置:文档之家› 2016年9月1日rman备份恢复脚本

2016年9月1日rman备份恢复脚本

rman备份恢复1.通过rman备份文件恢复spfile2.通过rman备份文件恢复controlfile3.通过rman备份文件恢复datafile4.利用恢复回来的controlfile和datafile生成redolog5.测试交易是否存在,并全备我系统环境所有的文件如下:[oracle@fowaydbs]$ pwd/opt/oracle/10g/dbs[oracle@fowaydbs]$ lsinitdw.orainit.ora[oracle@fowaydbs]$ls /opt/oracle/oradata已没有任何资料[oracle@fowaydbs]$ls /opt/oracle/admin已没有任何资料[oracle@fowaydbs] ls /opt/oracle/flash_recovery_area/ ORCL[oracle@fowaydbs]ls/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18[oracle@fowaydbs]ls/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_ 18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkpo1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp在我这台电脑上, ,系统中所有的ORCL相关的数据文件,参数文件,日志文件,控制文件全部不在了, 没有其他可用的备份文件了,只有rman备份的文件在,这可怎么办呢?没办法只能恢复了,可怎么恢复呢?要恢复数据文件用rman备份? 能吗? 当然不能了,因为restore 必须在mount or open状态下.参数文件,控制文件都没有怎么mount?要mount必须有参数文件,控制文件,为此我们必须解决这2个难题了.在解决难题前先准备ORCL的必须的目录:[oracle@fowaydbs]mkdir /opt/oracle/oradata/orcl[oracle@fowaydbs]mkdir /opt/oracle/admin/orcl/adump –p [oracle@fowaydbs]mkdir /opt/oracle/admin/orcl/cdump [oracle@fowaydbs]mkdir /opt/oracle/admin/orcl/bdump [oracle@fowaydbs]mkdir /opt/oracle/admin/orcl/udump [oracle@fowaydbs]mkdir /opt/oracle/admin/orcl/dpdump [oracle@fowaydbs]mkdir /opt/oracle/admin/orcl/pfile难题1:spfile有人说没参数文件我新建立一个pfile,当然这个办法是可行的,不过在10g中rman备份是自动备份了spfile的,所以我们可以利用rman来恢复spfile了.[oracle@fowaydbs]rman target / nocatalogRecovery Manager: Release 10.2.0.4.0 - Production on Fri Jul 18 21:21:47 2008Copyright (c) 1982, 2005, Oracle.All rights reserved.connected to target database (not started)RMAN> list backup;RMAN-00571:======================================================= ====RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571:======================================================= ====RMAN-03002: failure of list command at 07/18/2008 21:24:37 RMAN-06403: could not obtain a fully authorized session ORA-01034: ORACLE not availableORA-27101: shared memory realm does not existLinux Error: 2: No such file or directorylist copy;RMAN-00571:======================================================= ====RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571:======================================================= ====RMAN-03002: failure of list command at 07/18/2008 21:24:51 RMAN-06403: could not obtain a fully authorized session ORA-01034: ORACLE not availableORA-27101: shared memory realm does not existLinux Error: 2: No such file or directory看到上面的是正常的,因为数据库没有启动呢.于是我们先启动数据库到nomout下RMAN>startup nomountstartup failed: ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file '/opt/oracle/10g/dbs/initorcl.ora'starting Oracle instance without parameter file for retrival of spfileOracle instance startedTotal System Global Area159383552 bytesFixed Size1218268 bytesVariable Size54528292 bytesDatabase Buffers100663296 bytesRedo Buffers2973696 bytesRMAN>list backup;RMAN>list copy;将与上次执行看到的一样,此时也是正常的,不必担心,下面就是利用rman备份文件来解决难题1了.RMAN> restore spfilefrom'/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp'; Starting restore at 18-JUL-08allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=36 devtype=DISKchannel ORA_DISK_1: autobackup found: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_ 18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkpchannel ORA_DISK_1: SPFILE restore from autobackup completeFinished restore at 18-JUL-08下面是来验证spfileorcl.ora文件是否已存在:[oracle@fowaydbs]$ pwd/opt/oracle/10g/dbs[oracle@fowaydbs]$ lsinitdw.orainit.oraspfileorcl.ora恭喜你:spfile已恢复了有了参数文件,就需要解决控制文件恢复了难题2. 控制文件恢复这个又怎么恢复呢? 用rman的自动备份控制文件的rman备份吗? 是的没错,只有从rman备份文件中提取出来的controlfile才能使用rman备份文件恢复datafile的.那么这里有来种办法来实现从rman备份文件中提取出controlfie了.方法1.RMAN>restore controlfile from ‘/…备份文件..’;恢复的控制文件将放在$ORACLE_HOME/dbs/cncontrl.dbf不过这个方法有时恢复的控制文件中记录的dbname与实际不一致.方法2: 利用dbms_backup_restore提取controlfile步骤:[oracle@fowaydbs]$sqlplus /nologSQL*Plus: Release 10.2.0.4.0 - Production on Fri Jul 18 21:38:21 2008Copyright (c) 1982, 2005, Oracle. All rights reserved.SQL> conn /as sysdbaConnected.由于在刚才使用rman时执行了startup nomount,所以这里是connected,下面我们到nomount状态SQL> startup force nomountORACLE instance started.Total System Global Area 167772160 bytesFixed Size 1218316 bytesVariable Size 62916852 bytesDatabase Buffers 100663296 bytesRedo Buffers 2973696 bytesSQL>DECLARE2devtype varchar2(256);3done boolean;4BEGIN5devtype:=sys.dbms_backup_restore.deviceAllocate(type=> '',ident=>'T1');6sys.dbms_backup_restore.restoreSetDatafile;7sys.dbms_backup_restore.restoreControlfileTo(cfname=>' /opt/oracle/oradata/orcl/control01.ctl');8sys.dbms_backup_restore.restoreBackupPiece(done=>done, handle=>'/opt/oracle/flash_recovery_area/ORCL/backupset /2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bk p',params=>null);9 sys.dbms_backup_restore.deviceDeallocate;10 end;11/PL/SQL procedure successfully completed.下面验证control01.ctl是否恢复:[oracle@fowaydbs]$ ls /opt/oracle/oradata/orcl/control01.ctl[oracle@fowaydbs]$看到了control01.ctl 恭喜你:难题2 解决了.于是我们可以启动数据库到mount状态了.[oracle@fowaydbs]$sqlplus /nologSQL*Plus: Release 10.2.0.4 - Production on Fri Jul 18 21:45:32 2008Copyright (c) 1982, 2005, Oracle. All rights reserved.SQL> conn /as sysdbaConnected.SQL> startup force mountORACLE instance started.Total System Global Area 167772160 bytesFixed Size 1218316 bytesVariable Size 62916852 bytesDatabase Buffers 100663296 bytesRedo Buffers 2973696 bytesORA-00205: error in identifying control file, check alert log for more info我们已经恢复了控制文件了,怎么还是有错误呢,其实不用担心,看看spfile中的记录先SQL> show parameter control_filesNAME TYPE VALUE------------------------------------ ----------- ------------------------------control_files string /opt/oracle/oradata/orcl/control01.ctl, /opt/oracle/oradata/orcl/control02.ctl, /opt/oracle/oradata/orcl/control03.ctlSQL>既然如此,我们就把控制文件同步下好了.SQL> ho cp /opt/oracle/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/control02.ctlSQL> ho cp /opt/oracle/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/control03.ctlSQL> alter database mount;Database altered.SQL> ho ls /opt/oracle/oradata/orcl/control01.ctl control02.ctl control03.ctl好了到这里我们已经成功解决了难题2了.有了恢复后的控制文件,我们就可以使用rman查看与使用以前的rman备份了.恢复datafile 步骤:rman target / nocatalogRecovery Manager: Release 10.2.0.4 - Production on Fri Jul 18 21:49:10 2008Copyright (c) 1982, 2005, Oracle. All rights reserved.connected to target database: ORCL (DBID=1188209463, not open)using target database control file instead of recovery catalogRMAN>看到了红色部分了吗,太好了终于看到了正常的rman登陆信息了.那就list copy|backup 看看能找到我们的o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkpo1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp文件吗.RMAN> list copy;specification does not match any archive log in the recovery catalogRMAN> list backup;List of Backup Sets===================BS Key Type LV Size Device Type Elapsed Time Completion Time------- ---- -- ---------- ----------- ------------ ---------------1 Full 495.41M DISK 00:00:41 18-JUL-08BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20080718T203240Piece Name: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_ 18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkpList of Datafiles in backup set 1File LV Type Ckp SCN Ckp Time Name---- -- ---- ---------- --------- ----1 Full 453304 18-JUL-08 /opt/oracle/oradata/orcl/system01.dbf2 Full 453304 18-JUL-08 /opt/oracle/oradata/orcl/undotbs01.dbf3 Full 453304 18-JUL-08 /opt/oracle/oradata/orcl/sysaux01.dbf4 Full 453304 18-JUL-08 /opt/oracle/oradata/orcl/users01.dbfRMAN>太好了,总于可以使用restore,recover来恢复datafile了.RMAN> restore database;Starting restore at 18-JUL-08Starting implicit crosscheck backup at 18-JUL-08allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=156 devtype=DISK Crosschecked 1 objectsFinished implicit crosscheck backup at 18-JUL-08 Starting implicit crosscheck copy at 18-JUL-08 using channel ORA_DISK_1Finished implicit crosscheck copy at 18-JUL-08 searching for all files in the recovery area cataloging files...cataloging doneList of Cataloged Files=======================File Name: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_ 18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkpusing channel ORA_DISK_1channel ORA_DISK_1: starting datafilebackupset restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setrestoringdatafile 00001 to /opt/oracle/oradata/orcl/system01.dbfrestoringdatafile 00002 to /opt/oracle/oradata/orcl/undotbs01.dbfrestoringdatafile 00003 to /opt/oracle/oradata/orcl/sysaux01.dbfrestoringdatafile 00004 to /opt/oracle/oradata/orcl/users01.dbfchannel ORA_DISK_1: reading from backup piece /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_ 18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkpchannel ORA_DISK_1: restored backup piece 1piecehandle=/opt/oracle/flash_recovery_area/ORCL/backupset/2 008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp tag=TAG20080718T203240channel ORA_DISK_1: restore complete, elapsed time: 00:00:56Finished restore at 18-JUL-08RMAN>此时可以在$ORACLE_BASE/oradata/orcl/下看到期望已久的datafile了.[oracle@fowaydbs] ls /opt/oracle/oradata/orcl/control01.ctl control02.ctl control03.ctl sysaux01.dbf system01.dbf undotbs01.dbf users01.dbf[oracle@fowaydbs]不过此时还没有完哈,需要在接在励.由于没有redo log日志文件所以我们不应用日志恢复:RMAN> recover database noredo;Starting recover at 18-JUL-08using channel ORA_DISK_1Finished recover at 18-JUL-08RMAN>到目前我们已经拥有了参数文件,控制文件,数据文件了:[oracle@fowaydbs] ls /opt/oracle/oradata/orcl/ls /opt/oracle/oradata/orcl/control01.ctl control02.ctl control03.ctl sysaux01.dbf system01.dbfundotbs01.dbf users01.dbf[oracle@fowaydbs] ls /opt/oracle/10g/dbs/alert_orcl.log hc_orcl.dat initdw.orainit.oralkORCLspfileorcl.ora还差一个密码文件,以及相关的日志文件了.先解决密码文件:[oracle@fowaydbs]orapwdfile=/opt/oracle/10g/dbs/orapworclpassword=uplooking entries=5[oracle@fowaydbs] ls /opt/oracle/10g/dbs/ls /opt/oracle/10g/dbs/alert_orcl.log initdw.oralkORCLspfileorcl.orahc_orcl.dat init.oraorapworcl下面需要大家坚持不懈的完成最后一个工作了.通过已经恢复的controlfile and datafile 来演算出redo log file了.步骤:[oracle@fowaydbs]sqlplus /nologSQL*Plus: Release 10.2.0.4 - Production on Fri Jul 18 21:58:05 2008Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> conn /as sysdbaConnected.SQL> startup force mountORACLE instance started.Total System Global Area 167772160 bytesFixed Size 1218316 bytesVariable Size 62916852 bytesDatabase Buffers 100663296 bytesRedo Buffers 2973696 bytesDatabase mounted.SQL>alter system set "_allow_resetlogs_corruption"=TRUE;alter system set "_allow_resetlogs_corruption"=TRUE*ERROR at line 1:ORA-02095: specified initialization parameter cannot be modifiedSQL> alter system set "_allow_resetlogs_corruption"=TRUE scope=spfile;System altered.SQL>ho ls /opt/oracle/oradata/orcl/control01.ctl control03.ctl sysaux01.dbf undotbs01.dbfcontrol02.ctlorapworcl system01.dbf users01.dbf下面没有redo log file ,下面我将演算出redo logSQL>startup forceORACLE instance started.Total System Global Area 167772160 bytesFixed Size 1218316 bytesVariable Size 62916852 bytesDatabase Buffers 100663296 bytesRedo Buffers 2973696 bytesDatabase mounted.ORA-01589: must use RESETLOGS or NORESETLOGS option for database openSQL>alter database open resetlogs;Database altered.SQL> ho ls /opt/oracle/oradata/orcl/control01.ctlorapworcl redo03.log temp01.dbfcontrol02.ctl redo01.log sysaux01.dbf undotbs01.dbf control03.ctl redo02.log system01.dbf users01.dbf SQL>好了到这里,非常高兴了,你已经成功的从只有rman备份文件中恢复了参数文件,控制文件,所有数据文件,日志文件了.。

相关主题