一、前言

常言道-“有备无患”,备份对于一套数据库来说十分重要,当遇到天灾人祸的时候有效的备份是数据库最后的希望,也是DBA从业人员自救的最后手段。一款不错的备份软件,一个适用的备份策略,对于数据保护来说是十分必要的,对于数据库系统要定时做有效的全备,以便随时恢复到任意时间点。在不同环境下有多种恢复环境,不同环境也会使用不同的方式来恢复,有时候方式不止一种。总之,有效的备份和不同环境下的恢复手段对于DBA从业人员来说是十分重要的。

二、Oracle备份

1、Oracle冷备

冷备是指Oracle数据库处于冷状态(即停机状态)的备份,此类型的备份操作简单,但是不能恢复到任意时间点、每次备份需要停机且数据量大的话停机时间长,恢复不灵活不适用核心7*24小时的生产Oracle数据库。备份只需将数据库停机复制数据文件、控制文件和参数文件即可,生产环境使用罕见此处不再讨论。

[oracle@edsir4p1-PROD1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Sat Dec 14 08:39:25 2019Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSYS@PROD1> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SYS@PROD1> exitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@edsir4p1-PROD1 ~]$ cd /u01/app/oracle/oradata/[oracle@edsir4p1-PROD1 oradata]$ tar -zcvf PROD1.tar.gz PROD1PROD1/PROD1/tools.dbfPROD1/oltp.dbfPROD1/temp1.dbfPROD1/test.dbfPROD1/datafile/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbfPROD1/datafile/o1_mf_users_bpy12gjt_.dbfPROD1/datafile/o1_mf_example_bpy15nf0_.dbfPROD1/datafile/o1_mf_temp_bpy15m62_.tmpPROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbfPROD1/datafile/o1_mf_system_bpy12gck_.dbfPROD1/indx.dbfPROD1/controlfile/PROD1/controlfile/control01.ctlPROD1/controlfile/control02.ctlPROD1/onlinelog/PROD1/onlinelog/o1_mf_2_bpy15d87_.logPROD1/onlinelog/o1_mf_3_bpy15h47_.logPROD1/onlinelog/o1_mf_1_bpy159nj_.logPROD1/temp2.dbf[oracle@edsir4p1-PROD1 oradata]$[oracle@edsir4p1- PROD1]$ cd /u01/app/oracle/flash_recovery_area/PROD1/controlfile[oracle@edsir4p1- controlfile]$ tar -zcvf control03.ctl.tar.gz control03.ctlcontrol03.ctl[oracle@edsir4p1- controlfile]$

2、Oracle热备

热备是相对于冷备来说的,是指Oracle数据库处于热状态(即运行状态)的备份,此类型的备份有很多方式实现,主要优点是数据库一直运行,适用于7*24小时的生产Oracle数据库环境。下边对热备份的一种常用方式进行讨论:

exp

exp是Oracle数据库集成的一种逻辑备份工具。可在服务端和客户端运行,备份会在指定的file路径下生成一个同数据库中表同等大小的dmp转储文件,转储文件是一个二进制的不可读文件,实际上exp命令会在Oracle后台运行PLSQL过程,将表中的数据逻辑导出。

①数据逻辑备份,不存在物理坏块。

②在备份过程中不影响生产,对数据库性能影响不大。

③只能将数据库恢复到备份时刻,不能恢复到任意时间点。

详细可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sutil/oracle-original-export-utility.html#GUID-8DC1DEF0-13D8-44F7-A5E1-373642DE2C4B

expdp

expdp是Oracle 10g以后集成的一种新型的逻辑备份工具,是exp的增强只能在服务端运行,备份同样会在directory下生成一个同数据库中表同等大小的dmp转储文件(一般比exp转储文件较小),同样也是二进制不可读文件,通过后台PLSQL过程逻辑导出表数据。

①数据逻辑备份,不存在物理坏块。

②导出速度比exp方式快同样对数据库影响不大。

③只能将数据库恢复到备份时刻,不能恢复到任意时间点。

详细可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sutil/oracle-data-pump-export-utility.html#GUID-2BBE8F6C-6D58-4C99-8A49-ED4DA53BECD2

rman

rman是Oracle集成的一种物理备份免安装工具,它通过调用sys.DBMS_RCVMAN和sys.DBMS_BACKUP_RESTORE两个数据包来进行备份,不依赖与Oracle运行,在备份过程中会进行块校验和块压缩,将数据块在pga中整合成备份集备份到磁带或磁盘中。

①恢复不依赖与Oracle运行,可在Oracle未运行状态下恢复数据库。

②可对数据库进行全备,增量备份,归档备份。并且恢复到任意时间点。

③备份过程中将数据块在pga中整合成备份集备份到磁带或磁盘中,备份方式更灵活。

④相比冷备简化了恢复的过程,在Oracle 11g引入了DRA(Data Recovery Advisor)更是简化了恢复的难度。

⑤由于物理备份会进行块校验和块压缩,可能会存在物理坏块的情况。

⑥由于rman备份需要分配内存写入磁盘,整个过程中对数据库性能有一定影响,一般都是在业务低峰期进行时间较长的备份(全量备份)。

archivelog模式:此模式下Oracle能够在open状态下进行一致性备份

[oracle@edsir4p1-PROD1 ~]$ cat rman.shrman target / <<EOFrun{backup database format '/home/oracle/backup/full_%d_%U.bak';sql 'alter system switch logfile';backup archivelog all format '/home/oracle/backup/full_%d_%U.arch';backup current controlfile format '/home/oracle/backup/full_%d_%U.ctl';}EOF[oracle@edsir4p1-PROD1 ~]$ ./rman.shRecovery Manager: Release 11.2.0.1.0 - Production on Sat Dec 14 08:46:09 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015)RMAN> 2> 3> 4> 5> 6>Starting backup at 14-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=23 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=172 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=25 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=173 device type=DISKchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setinput datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_bpy12gck_.dbfinput datafile file number=00008 name=/u01/app/oracle/oradata/PROD1/tools.dbfinput datafile file number=00007 name=/u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_1: starting piece 1 at 14-DEC-19channel ORA_DISK_2: starting full datafile backup setchannel ORA_DISK_2: specifying datafile(s) in backup setinput datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/test.dbfinput datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbfinput datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_bpy12gjt_.dbfchannel ORA_DISK_2: starting piece 1 at 14-DEC-19channel ORA_DISK_3: starting full datafile backup setchannel ORA_DISK_3: specifying datafile(s) in backup setinput datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbfinput datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_bpy15nf0_.dbfinput datafile file number=00009 name=/u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_3: starting piece 1 at 14-DEC-19channel ORA_DISK_2: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_0qujd02m_1_1.bak tag=TAG20191214T084613 comment=NONEchannel ORA_DISK_2: backup set complete, elapsed time: 00:00:08channel ORA_DISK_1: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_0pujd02m_1_1.bak tag=TAG20191214T084613 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:26channel ORA_DISK_3: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_0rujd02m_1_1.bak tag=TAG20191214T084613 comment=NONEchannel ORA_DISK_3: backup set complete, elapsed time: 00:00:26Finished backup at 14-DEC-19Starting Control File and SPFILE Autobackup at 14-DEC-19piece handle=/u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982001_gz98ck8t_.bkp comment=NONEFinished Control File and SPFILE Autobackup at 14-DEC-19sql statement: alter system switch logfileStarting backup at 14-DEC-19current log archivedusing channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4skipping archived log file /home/oracle/arch1/1_23_881415849.dbf; already backed up 1 time(s)skipping archived log file /home/oracle/arch1/1_24_881415849.dbf; already backed up 1 time(s)channel ORA_DISK_1: starting archived log backup setchannel ORA_DISK_1: specifying archived log(s) in backup setinput archived log thread=1 sequence=25 RECID=3 STAMP=1013263599input archived log thread=1 sequence=26 RECID=4 STAMP=1015907299input archived log thread=1 sequence=27 RECID=5 STAMP=1015912834input archived log thread=1 sequence=28 RECID=6 STAMP=1015920206input archived log thread=1 sequence=29 RECID=7 STAMP=1015927655channel ORA_DISK_1: starting piece 1 at 14-DEC-19channel ORA_DISK_2: starting archived log backup setchannel ORA_DISK_2: specifying archived log(s) in backup setinput archived log thread=1 sequence=30 RECID=8 STAMP=1015983209input archived log thread=1 sequence=31 RECID=9 STAMP=1015995608input archived log thread=1 sequence=32 RECID=10 STAMP=1016000056input archived log thread=1 sequence=33 RECID=11 STAMP=1017805874channel ORA_DISK_2: starting piece 1 at 14-DEC-19channel ORA_DISK_3: starting archived log backup setchannel ORA_DISK_3: specifying archived log(s) in backup setinput archived log thread=1 sequence=34 RECID=12 STAMP=1017813651input archived log thread=1 sequence=35 RECID=13 STAMP=1018342838input archived log thread=1 sequence=36 RECID=14 STAMP=1018343869input archived log thread=1 sequence=37 RECID=15 STAMP=1018343906input archived log thread=1 sequence=38 RECID=16 STAMP=1018352461channel ORA_DISK_3: starting piece 1 at 14-DEC-19channel ORA_DISK_4: starting archived log backup setchannel ORA_DISK_4: specifying archived log(s) in backup setinput archived log thread=1 sequence=39 RECID=17 STAMP=1018352621input archived log thread=1 sequence=40 RECID=18 STAMP=1026981487input archived log thread=1 sequence=41 RECID=19 STAMP=1026981604input archived log thread=1 sequence=42 RECID=20 STAMP=1026982003input archived log thread=1 sequence=43 RECID=21 STAMP=1026982003channel ORA_DISK_4: starting piece 1 at 14-DEC-19channel ORA_DISK_2: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_0uujd03k_1_1.arch tag=TAG20191214T084643 comment=NONEchannel ORA_DISK_2: backup set complete, elapsed time: 00:00:06channel ORA_DISK_3: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_0vujd03k_1_1.arch tag=TAG20191214T084643 comment=NONEchannel ORA_DISK_3: backup set complete, elapsed time: 00:00:09channel ORA_DISK_4: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_10ujd03m_1_1.arch tag=TAG20191214T084643 comment=NONEchannel ORA_DISK_4: backup set complete, elapsed time: 00:00:08channel ORA_DISK_1: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_0tujd03j_1_1.arch tag=TAG20191214T084643 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:19Finished backup at 14-DEC-19Starting backup at 14-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4channel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setincluding current control file in backup setchannel ORA_DISK_1: starting piece 1 at 14-DEC-19channel ORA_DISK_1: finished piece 1 at 14-DEC-19piece handle=/home/oracle/backup/full_PROD1_11ujd046_1_1.ctl tag=TAG20191214T084702 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01Finished backup at 14-DEC-19Starting Control File and SPFILE Autobackup at 14-DEC-19piece handle=/u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982024_gz98d8sr_.bkp comment=NONEFinished Control File and SPFILE Autobackup at 14-DEC-19RMAN>Recovery Manager complete.

noarchivelog模式:此模式下Oracle不能再open状态下进行一致性备份,需要在mount状态下才能进行一致性备份。


SYS@PROD1> alter database open;Database altered.SYS@PROD1> archive log list;Database log mode No Archive ModeAutomatic archival DisabledArchive destination /home/oracle/arch1Oldest online log sequence 15Current log sequence 17SYS@PROD1> select open_mode from v$database;OPEN_MODE--------------------READ WRITE[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 05:00:31 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015)RMAN> backup database format '/home/oracle/full_%s%t%d%U.bak';Starting backup at 15-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=166 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=160 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=18 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=167 device type=DISKchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setRMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/15/2019 05:00:41ORA-19602: cannot backup or copy active file in NOARCHIVELOG modecontinuing other job steps, job failed will not be re-runchannel ORA_DISK_2: starting full datafile backup setchannel ORA_DISK_2: specifying datafile(s) in backup setRMAN-03009: failure of backup command on ORA_DISK_2 channel at 12/15/2019 05:00:41ORA-19602: cannot backup or copy active file in NOARCHIVELOG modecontinuing other job steps, job failed will not be re-runchannel ORA_DISK_3: starting full datafile backup setchannel ORA_DISK_3: specifying datafile(s) in backup setRMAN-03009: failure of backup command on ORA_DISK_3 channel at 12/15/2019 05:00:41ORA-19602: cannot backup or copy active file in NOARCHIVELOG modecontinuing other job steps, job failed will not be re-runchannel ORA_DISK_4: starting full datafile backup setchannel ORA_DISK_4: specifying datafile(s) in backup setRMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03009: failure of backup command on ORA_DISK_4 channel at 12/15/2019 05:00:41ORA-19602: cannot backup or copy active file in NOARCHIVELOG modeSYS@PROD1> shutdown immediate;startup mount;Database closed.Database dismounted.ORACLE instance shut down.SYS@PROD1> ORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesDatabase mounted.SYS@PROD1> select open_mode from v$database;OPEN_MODE--------------------MOUNTED[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 05:01:17 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015, not open)RMAN> backup database format '/home/oracle/full_%s%t%d%U.bak';Starting backup at 15-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setinput datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbfchannel ORA_DISK_1: starting piece 1 at 15-DEC-19channel ORA_DISK_2: starting full datafile backup setchannel ORA_DISK_2: specifying datafile(s) in backup setinput datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbfinput datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbfinput datafile file number=00008 name=/u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_2: starting piece 1 at 15-DEC-19channel ORA_DISK_3: starting full datafile backup setchannel ORA_DISK_3: specifying datafile(s) in backup setinput datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/test.dbfinput datafile file number=00009 name=/u01/app/oracle/oradata/PROD1/oltp.dbfinput datafile file number=00007 name=/u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_3: starting piece 1 at 15-DEC-19channel ORA_DISK_4: starting full datafile backup setchannel ORA_DISK_4: specifying datafile(s) in backup setinput datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbfinput datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbfinput datafile file number=00010 name=/u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_4: starting piece 1 at 15-DEC-19channel ORA_DISK_1: finished piece 1 at 15-DEC-19piece handle=/home/oracle/full_831027054888PROD12jujf798_1_1.bak tag=TAG20191215T050127 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:26channel ORA_DISK_2: finished piece 1 at 15-DEC-19piece handle=/home/oracle/full_841027054888PROD12kujf798_1_1.bak tag=TAG20191215T050127 comment=NONEchannel ORA_DISK_2: backup set complete, elapsed time: 00:00:27channel ORA_DISK_3: finished piece 1 at 15-DEC-19piece handle=/home/oracle/full_851027054888PROD12lujf798_1_1.bak tag=TAG20191215T050127 comment=NONEchannel ORA_DISK_3: backup set complete, elapsed time: 00:00:27channel ORA_DISK_4: finished piece 1 at 15-DEC-19piece handle=/home/oracle/full_861027054889PROD12mujf799_1_1.bak tag=TAG20191215T050127 comment=NONEchannel ORA_DISK_4: backup set complete, elapsed time: 00:00:26Finished backup at 15-DEC-19Starting Control File and SPFILE Autobackup at 15-DEC-19piece handle=/u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054861_gzchl3h1_.bkp comment=NONEFinished Control File and SPFILE Autobackup at 15-DEC-19

rman除了进行备份恢复以外,还能对数据库进行数据传输(dulplicate),坏块修复(recover block)甚至XTTS底层也是perl语言调用的rman包。可以说功能巨大。

关于rman详细可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/bradv/rman-architecture.html#GUID-8ECC1FB0-7D25-4883-B9A6-2593FDB35940 或https://blog.csdn.net/renyanjie123/article/details/103539981

copy

copy是rman里的一个数据文件复制命令,同样也可以做数据备份,它同rman备份的区别在与copy只是单纯的复制数据文件,并不会像rman备份那样生成一个备份集备份到磁带或磁盘中,但是copy由于不会产生备份集只是简单的cp命令,所以并没有rman那样消耗性能。同时此命令还可用于生产库更改数据文件,用法相同。

SYS@PROD1> select tablespace_name ,status from dba_tablespaces;TABLESPACE_NAME STATUS------------------------------ ---------SYSTEM ONLINESYSAUX ONLINEUNDOTBS1 ONLINETEMP ONLINEUSERS ONLINEEXAMPLE ONLINETEMP1 ONLINETEMP2 ONLINETEST ONLINEINDX ONLINETOOLS ONLINEOLTP ONLINE12 rows selected.SYS@PROD1> alter tablespace oltp read only;Tablespace altered.SYS@PROD1> select tablespace_name ,status from dba_tablespaces;TABLESPACE_NAME STATUS------------------------------ ---------SYSTEM ONLINESYSAUX ONLINEUNDOTBS1 ONLINETEMP ONLINEUSERS ONLINEEXAMPLE ONLINETEMP1 ONLINETEMP2 ONLINETEST ONLINEINDX ONLINETOOLS ONLINEOLTP READ ONLY12 rows selected.SYS@PROD1> select file#,name from v$datafile;FILE# NAME---------- --------------------------------------------------------------------------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_bpy12gck_.dbf2 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbf3 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbf4 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_bpy12gjt_.dbf5 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_bpy15nf0_.dbf6 /u01/app/oracle/oradata/PROD1/test.dbf7 /u01/app/oracle/oradata/PROD1/indx.dbf8 /u01/app/oracle/oradata/PROD1/tools.dbf9 /u01/app/oracle/oradata/PROD1/oltp.dbf9 rows selected.SYS@PROD1> exitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sat Dec 14 08:51:30 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015)RMAN> copy datafile '/u01/app/oracle/oradata/PROD1/oltp.dbf' to '/home/oracle/backup/oltp_bak.dbf';Starting backup at 14-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=24 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=26 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=175 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=30 device type=DISKchannel ORA_DISK_1: starting datafile copyinput datafile file number=00009 name=/u01/app/oracle/oradata/PROD1/oltp.dbfoutput file name=/home/oracle/backup/oltp_bak.dbf tag=TAG20191214T085214 RECID=2 STAMP=1026982335channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03Finished backup at 14-DEC-19Starting Control File and SPFILE Autobackup at 14-DEC-19piece handle=/u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982337_gz98p1j0_.bkp comment=NONEFinished Control File and SPFILE Autobackup at 14-DEC-19RMAN> exitSYS@PROD1> select tablespace_name ,status from dba_tablespaces;TABLESPACE_NAME STATUS------------------------------ ---------SYSTEM ONLINESYSAUX ONLINEUNDOTBS1 ONLINETEMP ONLINEUSERS ONLINEEXAMPLE ONLINETEMP1 ONLINETEMP2 ONLINETEST ONLINEINDX ONLINETOOLS ONLINEOLTP ONLINE12 rows selected.[oracle@edsir4p1-PROD1 backup]$ ll-rw-r----- 1 oracle oinstall 50339840 Dec 14 08:52 oltp_bak.dbf[oracle@edsir4p1-PROD1 backup]$ ll /u01/app/oracle/oradata/PROD1/oltp.dbf-rw-r----- 1 oracle oinstall 50339840 Dec 14 08:53 /u01/app/oracle/oradata/PROD1/oltp.dbf

总结:以上四种备份方式,rman备份是最常用的,expdp/exp常用于数据导出,一般这两种方式配合使用对数据库进行备份。

三、Oracle冷备恢复

冷备恢复也是比较简单的一种恢复,它只能基于冷备份来恢复,若archivelog连续且完整并且redo没有损坏可以恢复到当前时间状态,若redo已经损坏那么只能恢复到down机较近的归档时间点,若archivelog丢失,只能恢复到有效冷备的时间点。而且需要注意的是,冷备情况下应用archivelog实际上是利用归档日志反写通过system中的数据库元数据来恢复数据,这个过程如果没有数据文件增加则不需要额外的操作就能正常恢复到open状态,若这个过程中有数据文件增加,那么就需要指定数据文件来恢复数据。

关闭数据库冷备,备份时间是10:28

[oracle@edsir4p1-PROD1 oradata]$ tar -zcvf PROD1.tar.gz PROD1PROD1/PROD1/tools.dbfPROD1/oltp.dbfPROD1/temp1.dbfPROD1/test.dbfPROD1/datafile/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbfPROD1/datafile/o1_mf_users_bpy12gjt_.dbfPROD1/datafile/o1_mf_example_bpy15nf0_.dbfPROD1/datafile/o1_mf_temp_bpy15m62_.tmpPROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbfPROD1/datafile/o1_mf_system_bpy12gck_.dbfPROD1/indx.dbfPROD1/controlfile/PROD1/controlfile/control01.ctlPROD1/controlfile/control02.ctlPROD1/onlinelog/PROD1/onlinelog/o1_mf_2_bpy15d87_.logPROD1/onlinelog/o1_mf_3_bpy15h47_.logPROD1/onlinelog/o1_mf_1_bpy159nj_.logPROD1/temp2.dbf[oracle@edsir4p1-PROD1 oradata]$ lltotal 348232drwxr-x--- 5 oracle oinstall 4096 Jul 6 10:08 PROD1-rw-r--r-- 1 oracle oinstall 356225568 Dec 14 10:28 PROD1.tar.gzdrwxr-x--- 5 oracle oinstall 4096 Jun 3 2015 PROD2[oracle@edsir4p1-PROD1 oradata]$ cd /u01/app/oracle/flash_recovery_area/PROD1/controlfile/[oracle@edsir4p1-PROD1 controlfile]$ lscontrol03.ctl control03.ctl.tar.gz[oracle@edsir4p1-PROD1 controlfile]$ rm control03.ctl.tar.gz[oracle@edsir4p1-PROD1 controlfile]$ tar -zcvf control03.ctl.tar.gz control03.ctlcontrol03.ctl[oracle@edsir4p1-PROD1 controlfile]$ lltotal 9564-rw-r----- 1 oracle oinstall 9748480 Dec 14 10:25 control03.ctl-rw-r--r-- 1 oracle oinstall 25874 Dec 14 10:29 control03.ctl.tar.gz模拟业务继续进行,创建表空间SYS@PROD1> create tablespace tbs datafile '/u01/app/oracle/oradata/PROD1/tbs01.dbf' size 50m;Tablespace created.SYS@PROD1> select file#,name from v$datafile;FILE# NAME---------- --------------------------------------------------------------------------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_bpy12gck_.dbf2 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbf3 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbf4 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_bpy12gjt_.dbf5 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_bpy15nf0_.dbf6 /u01/app/oracle/oradata/PROD1/test.dbf7 /u01/app/oracle/oradata/PROD1/indx.dbf8 /u01/app/oracle/oradata/PROD1/tools.dbf9 /u01/app/oracle/oradata/PROD1/oltp.dbf10 /u01/app/oracle/oradata/PROD1/tbs01.dbf10 rows selected.SYS@PROD1> create table test (id int,name varchar2(20)) ;Table created.SYS@PROD1> insert into test values(1,'ren');1 row created.SYS@PROD1> commit;Commit complete.SYS@PROD1> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1 1 4 52428800 512 2 YES INACTIVE 1363368 14-DEC-19 1363371 14-DEC-192 1 5 52428800 512 2 YES INACTIVE 1363371 14-DEC-19 1363375 14-DEC-193 1 6 52428800 512 2 NO CURRENT 1363375 14-DEC-19 2.8147E+14SYS@PROD1> alter system switch logfile;System altered.切换归档之后现在归档SEQUENCE#到6[oracle@edsir4p1- arch1]$ lltotal 956-rw-r----- 1 oracle oinstall 750592 Dec 14 10:31 1_1_1026987841.dbf-rw-r----- 1 oracle oinstall 1024 Dec 14 10:31 1_2_1026987841.dbf-rw-r----- 1 oracle oinstall 2048 Dec 14 10:31 1_3_1026987841.dbf-rw-r----- 1 oracle oinstall 1024 Dec 14 10:31 1_4_1026987841.dbf-rw-r----- 1 oracle oinstall 1024 Dec 14 10:31 1_5_1026987841.dbf-rw-r----- 1 oracle oinstall 197120 Dec 14 10:34 1_6_1026987841.dbfSYS@PROD1> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1 1 7 52428800 512 2 NO CURRENT 1363882 14-DEC-19 2.8147E+142 1 5 52428800 512 2 YES INACTIVE 1363371 14-DEC-19 1363375 14-DEC-193 1 6 52428800 512 2 YES ACTIVE 1363375 14-DEC-19 1363882 14-DEC-19业务进行下去,突然宕机,该事物没有提交SYS@PROD1> insert into test values(2,'li');1 row created.SYS@PROD1> select * from test;ID NAME---------- --------------------------------------------------------------------------------1 ren2 liSYS@PROD1> shutdown abortORACLE instance shut down.这里分解动作启动到mount手动恢复。SYS@PROD1> startup mount;ORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesDatabase mounted.冷备数据文件过早没有新加的表空间,需要应用归档恢复SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_bpy12gck_.dbf 1363224 13632242 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbf 1363224 13632243 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbf 1363224 13632244 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_bpy12gjt_.dbf 1363224 13632245 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_bpy15nf0_.dbf 1363224 13632246 /u01/app/oracle/oradata/PROD1/test.dbf 1363224 13632247 /u01/app/oracle/oradata/PROD1/indx.dbf 1363224 13632248 /u01/app/oracle/oradata/PROD1/tools.dbf 1363224 13632249 /u01/app/oracle/oradata/PROD1/oltp.dbf 1363224 13632249 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 13632242 13632243 13632244 13632245 13632246 13632247 13632248 13632249 13632249 rows selected.SYS@PROD1> recover database using backup controlfile;ORA-00279: change 1363224 generated at 12/14/2019 10:25:46 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_1_1026987841.dbfORA-00280: change 1363224 for thread 1 is in sequence #1Specify log: {<RET>=suggested | filename | AUTO | CANCEL}autoORA-00279: change 1363360 generated at 12/14/2019 10:31:12 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_2_1026987841.dbfORA-00280: change 1363360 for thread 1 is in sequence #2ORA-00278: log file '/home/oracle/arch1/1_1_1026987841.dbf' no longer needed for this recoveryORA-00279: change 1363363 generated at 12/14/2019 10:31:13 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_3_1026987841.dbfORA-00280: change 1363363 for thread 1 is in sequence #3ORA-00278: log file '/home/oracle/arch1/1_2_1026987841.dbf' no longer needed for this recoveryORA-00279: change 1363368 generated at 12/14/2019 10:31:15 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_4_1026987841.dbfORA-00280: change 1363368 for thread 1 is in sequence #4ORA-00278: log file '/home/oracle/arch1/1_3_1026987841.dbf' no longer needed for this recoveryORA-00279: change 1363371 generated at 12/14/2019 10:31:15 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_5_1026987841.dbfORA-00280: change 1363371 for thread 1 is in sequence #5ORA-00278: log file '/home/oracle/arch1/1_4_1026987841.dbf' no longer needed for this recoveryORA-00279: change 1363375 generated at 12/14/2019 10:31:15 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_6_1026987841.dbfORA-00280: change 1363375 for thread 1 is in sequence #6ORA-00278: log file '/home/oracle/arch1/1_5_1026987841.dbf' no longer needed for this recoveryORA-00283: recovery session canceled due to errorsORA-01244: unnamed datafile(s) added to control file by media recoveryORA-01110: data file 10: '/u01/app/oracle/oradata/PROD1/tbs01.dbf'ORA-01112: media recovery not started发现没有tbs01.dbf文件,查看数据文件,新增了一个UNNAMED00010在ORACLE_HOME/dbs下,实际上并没有这个文件SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_bpy12gck_.dbf 13633752 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbf 13633753 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbf 13633754 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_bpy12gjt_.dbf 13633755 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_bpy15nf0_.dbf 13633756 /u01/app/oracle/oradata/PROD1/test.dbf 13633757 /u01/app/oracle/oradata/PROD1/indx.dbf 13633758 /u01/app/oracle/oradata/PROD1/tools.dbf 13633759 /u01/app/oracle/oradata/PROD1/oltp.dbf 136337510 /u01/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00010 136342210 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 13634272 13634273 13634274 13634275 13634276 13634277 13634278 13634279 136342710 010 rows selected.[oracle@edsir4p1-PROD1 dbs]$ ll /u01/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00010ls: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00010: No such file or directory[oracle@edsir4p1-PROD1 controlfile]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/[oracle@edsir4p1-PROD1 dbs]$ lltotal 19128-rw-rw---- 1 oracle oinstall 1544 Aug 27 2014 hc_DBUA0.dat-rw-rw---- 1 oracle oinstall 1544 Aug 27 2014 hc_PROD1.dat-rw-rw---- 1 oracle oinstall 1544 Aug 27 2014 hc_PROD2.dat-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora-rw-r----- 1 oracle oinstall 24 Jun 3 2015 lkPROD1-rw-r----- 1 oracle oinstall 24 Jun 3 2015 lkPROD2-rw-r----- 1 oracle oinstall 1536 Aug 10 04:25 orapwPROD1-rw-r----- 1 oracle oinstall 1536 Jun 3 2015 orapwPROD2drwx------ 2 oracle oinstall 4096 Aug 27 2014 peshm__0drwx------ 2 oracle oinstall 4096 Aug 27 2014 peshm_DBUA0_0drwx------ 2 oracle oinstall 4096 Aug 27 2014 peshm_PROD1_0drwx------ 2 oracle oinstall 4096 Aug 27 2014 peshm_PROD2_0-rw-r----- 1 oracle oinstall 9748480 Dec 14 10:24 snapcf_PROD1.f-rw-r----- 1 oracle oinstall 9748480 Jul 10 14:06 snapcf_PROD2.f-rw-r----- 1 oracle oinstall 3584 Dec 14 10:37 spfilePROD1.ora-rw-r----- 1 oracle oinstall 3584 Sep 7 08:42 spfilePROD2.ora实际上数据目录下也没有这个文件[oracle@edsir4p1-PROD1 PROD1]$ lltotal 613040drwxr-x--- 2 oracle oinstall 4096 Sep 7 09:12 controlfiledrwxr-x--- 2 oracle oinstall 4096 Jun 3 2015 datafile-rw-r----- 1 oracle oinstall 41951232 Dec 14 10:38 indx.dbf-rw-r----- 1 oracle oinstall 50339840 Dec 14 10:38 oltp.dbfdrwxr-x--- 2 oracle oinstall 4096 Jun 3 2015 onlinelog-rw-r----- 1 oracle oinstall 52436992 Sep 7 12:28 temp1.dbf-rw-r----- 1 oracle oinstall 52436992 Dec 14 08:38 temp2.dbf-rw-r----- 1 oracle oinstall 419438592 Dec 14 10:38 test.dbf-rw-r----- 1 oracle oinstall 10493952 Dec 14 10:38 tools.dbf重建数据文件之后再次查看,如果使用rman恢复这个过程是自动创建的。SYS@PROD1> alter database create datafile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00010' as '/u01/app/oracle/oradata/PROD1/tbs01.dbf';Database altered.[oracle@edsir4p1-PROD1 PROD1]$ lltotal 664304drwxr-x--- 2 oracle oinstall 4096 Sep 7 09:12 controlfiledrwxr-x--- 2 oracle oinstall 4096 Jun 3 2015 datafile-rw-r----- 1 oracle oinstall 41951232 Dec 14 10:38 indx.dbf-rw-r----- 1 oracle oinstall 50339840 Dec 14 10:38 oltp.dbfdrwxr-x--- 2 oracle oinstall 4096 Jun 3 2015 onlinelog-rw-r----- 1 oracle oinstall 52436992 Dec 14 10:41 tbs01.dbf-rw-r----- 1 oracle oinstall 52436992 Sep 7 12:28 temp1.dbf-rw-r----- 1 oracle oinstall 52436992 Dec 14 08:38 temp2.dbf-rw-r----- 1 oracle oinstall 419438592 Dec 14 10:38 test.dbf-rw-r----- 1 oracle oinstall 10493952 Dec 14 10:38 tools.dbf继续恢复查看,需要7号归档,这个归档实际上是当前数据,没有归档到归档目录。SYS@PROD1> recover database using backup controlfile;ORA-00279: change 1363882 generated at 12/14/2019 10:34:12 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_7_1026987841.dbfORA-00280: change 1363882 for thread 1 is in sequence #7Specify log: {<RET>=suggested | filename | AUTO | CANCEL}cancelMedia recovery cancelled.查看数据文件头和控制文件头已经不需要恢复了。SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_bpy12gck_.dbf 13638822 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_bpy12gfm_.dbf 13638823 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_bpy12ggz_.dbf 13638824 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_bpy12gjt_.dbf 13638825 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_bpy15nf0_.dbf 13638826 /u01/app/oracle/oradata/PROD1/test.dbf 13638827 /u01/app/oracle/oradata/PROD1/indx.dbf 13638828 /u01/app/oracle/oradata/PROD1/tools.dbf 13638829 /u01/app/oracle/oradata/PROD1/oltp.dbf 136388210 /u01/app/oracle/oradata/PROD1/tbs01.dbf 136388210 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 13638822 13638823 13638824 13638825 13638826 13638827 13638828 13638829 136388210 136388210 rows selected.SYS@PROD1> recover database using backup controlfile until cancel;ORA-00279: change 1363882 generated at 12/14/2019 10:34:12 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_7_1026987841.dbfORA-00280: change 1363882 for thread 1 is in sequence #7Specify log: {<RET>=suggested | filename | AUTO | CANCEL}cancelMedia recovery cancelled.SYS@PROD1> alter database open resetlogs;Database altered.SYS@PROD1> select * from test;ID NAME---------- --------------------------------------------------------------------------------1 renSYS@PROD1>

发现此时已经恢复了,但是当前redo丢失导致数据丢失。

四、Oracle热备恢复

1、imp

利用dmp文件导入相关表

imp '\/ as sysdba\' file=xx.dmp log=xx.log fromuser=old_owner touser=new_owner buffer=6553600 ignore=y

详细可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sutil/oracle-original-import-utility.html#GUID-507CDEA3-1244-4C0C-B4F4-92E838A3376F

2、impdp

利用dmp文件导入相关表

impdp '\/ as sysdba\' directory=d1 dumpfile=xx.dmp dumplog=xx.log

详细可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sutil/datapump-import-utility.html#GUID-AF614D9B-71B1-4234-AD0D-D33B53A16A6E

3、rman

rman恢复是生产中使用最多的数据恢复方式之一,它可以将有效的备份集恢复到任意时刻满足生产库数据不丢失的先决条件。在数据库中分为归档模式和非归档模式,此处不在详细描述这两者的区别,重点讨论两种不同模式下的rman恢复方式。

noarchive模式

此模式下在Oracleopen状态无法进行一致性备份,需将数据库置于mount状态才能进行一致性备份,在有有效rman备份集的情况下可正常进行介质恢复。由于归档模式Oracle会将在buffercache中的变化同时记录在log buffer中,通过lgwr进程将数据写出内存到online redo中,在通过arch进程将redo内容写到archivelog中,此日志用于Oracle数据恢复时使用。在非归档模式就不会有arch写出online redo这一动作。实例恢复是不需要备份介质的恢复方式,使用recover database 即可使用online redo来恢复当前数据库。在ORACLE RAC中,redo磁盘组存放在共享存储中,recover database 需要从online redo中恢复当前实例。所以在该环境下所有的rman恢复都是不完全恢复,一旦故障就意味着丢失一定量级的数据,在实际生产中使用非常少。

在非归档模式下由于没有连续的归档产生,历史备份数据较老,所以这种环境下一定是一个不完全恢复。

SYS@PROD1> archive log list;Database log mode No Archive ModeAutomatic archival DisabledArchive destination /home/oracle/arch1Oldest online log sequence 1Current log sequence 3[oracle@edsir4p1-PROD1 PROD1]$ rm *.dbf[oracle@edsir4p1-PROD1 oradata]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 04:12:12 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015, not open)RMAN> restore database;Starting restore at 15-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKcreating datafile file number=10 name=/u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbfchannel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbfchannel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_15ujf0a4_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00001 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbfchannel ORA_DISK_2: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_2: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_14ujf0a4_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbfchannel ORA_DISK_3: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbfchannel ORA_DISK_3: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_16ujf0a4_1_1.bakchannel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_15ujf0a4_1_1.bak tag=TAG20191215T030228channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:16channel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_14ujf0a4_1_1.bak tag=TAG20191215T030228channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:26channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_16ujf0a4_1_1.bak tag=TAG20191215T030228channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:26Finished restore at 15-DEC-19--查看当前数据文件头SCN和控制文件SCN,明显不一致,控制文件很新且中间归档丢失,只能进行不完全恢复SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 14679652 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 14679653 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 14679654 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 14679655 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 14679656 /u01/app/oracle/oradata/PROD1/test.dbf 14679657 /u01/app/oracle/oradata/PROD1/indx.dbf 14679658 /u01/app/oracle/oradata/PROD1/tools.dbf 14679659 /u01/app/oracle/oradata/PROD1/oltp.dbf 146796510 /u01/app/oracle/oradata/PROD1/tbs01.dbf 146796510 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 13630912 13630953 13630934 13630935 13630956 13630937 13630918 13630919 136309510 136346810 rows selected.--尝试恢复数据库RMAN> recover database;Starting recover at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 1 is already on disk as file /home/oracle/arch1/1_1_1027047663.dbfarchived log for thread 1 with sequence 2 is already on disk as file /home/oracle/arch1/1_2_1027047663.dbfarchived log for thread 1 with sequence 3 is already on disk as file /home/oracle/arch1/1_3_1027047663.dbfarchived log for thread 1 with sequence 4 is already on disk as file /home/oracle/arch1/1_4_1027047663.dbfarchived log for thread 1 with sequence 5 is already on disk as file /home/oracle/arch1/1_5_1027047663.dbfarchived log for thread 1 with sequence 6 is already on disk as file /home/oracle/arch1/1_6_1027047663.dbfarchived log for thread 1 with sequence 7 is already on disk as file /home/oracle/arch1/1_7_1027047663.dbfarchived log for thread 1 with sequence 8 is already on disk as file /home/oracle/arch1/1_8_1027047663.dbfarchived log for thread 1 with sequence 9 is already on disk as file /home/oracle/arch1/1_9_1027047663.dbfarchived log for thread 1 with sequence 10 is already on disk as file /home/oracle/arch1/1_10_1027047663.dbfarchived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcdtfll_.logarchived log file name=/home/oracle/arch1/1_1_1027047663.dbf thread=1 sequence=1archived log file name=/home/oracle/arch1/1_2_1027047663.dbf thread=1 sequence=2archived log file name=/home/oracle/arch1/1_3_1027047663.dbf thread=1 sequence=3archived log file name=/home/oracle/arch1/1_4_1027047663.dbf thread=1 sequence=4archived log file name=/home/oracle/arch1/1_5_1027047663.dbf thread=1 sequence=5archived log file name=/home/oracle/arch1/1_6_1027047663.dbf thread=1 sequence=6archived log file name=/home/oracle/arch1/1_7_1027047663.dbf thread=1 sequence=7archived log file name=/home/oracle/arch1/1_8_1027047663.dbf thread=1 sequence=8archived log file name=/home/oracle/arch1/1_9_1027047663.dbf thread=1 sequence=9archived log file name=/home/oracle/arch1/1_10_1027047663.dbf thread=1 sequence=10RMAN-08187: WARNING: media recovery until SCN 1363915 completearchived log file name=/home/oracle/arch1/1_10_1027047663.dbf thread=1 sequence=1RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of recover command at 12/15/2019 04:20:19ORA-00283: recovery session canceled due to errorsRMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/home/oracle/arch1/1_10_1027047663.dbf'ORA-00283: recovery session canceled due to errorsORA-01112: media recovery not startedRMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 1 and starting SCN of 1363915--发现由于非归档模式日志缺失只能进行不完全恢复,将数据库恢复到sequence 10,发现恢复完scn为1363915RMAN> recover database until sequence 10;Starting recover at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcdtfll_.logRMAN-08187: WARNING: media recovery until SCN 1363915 completeFinished recover at 15-DEC-19--由于进行不完全恢复,需要resetlogs重置lsn起库,关于RESETLOGS可详见:https://blog.csdn.net/renyanjie123/article/details/82935937SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 1363915 13639152 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 1363915 13639153 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 1363915 13639154 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 1363915 13639155 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 1363915 13639156 /u01/app/oracle/oradata/PROD1/test.dbf 1363915 13639157 /u01/app/oracle/oradata/PROD1/indx.dbf 1363915 13639158 /u01/app/oracle/oradata/PROD1/tools.dbf 1363915 13639159 /u01/app/oracle/oradata/PROD1/oltp.dbf 1363915 136391510 /u01/app/oracle/oradata/PROD1/tbs01.dbf 1363915 136391510 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 13639152 13639153 13639154 13639155 13639156 13639157 13639158 13639159 136391510 136391510 rows selected.RMAN> alter database open resetlogs;database opened

archive模式

在此模式下rman不仅在open状态下能进行一致性备份。还能利用有效备份集进行介质恢复,在存在全量或增量备份集以后连续的归档文件并且不存在online redo损坏的前提下,可将数据库恢复到任意时刻。在ORACLE RAC中,各个节点都要有各个节点归档目录的读权限和对当前节点归档目录的写权限,在生产中各个节点事物变化都是串行的,当一节点或多节点down机时,也可通过recover database 通过读取所有节点的archIvelog来恢复,在介质恢复时是利用rman将介质中的备份集恢复到数据磁盘组中,在通过归档或增量备份恢复到当前时间点。

常用命令:

restore database from 'xxx';

recover database from 'xxx';

restore controlfile from 'xxx';

recover controlfile from 'xxx';

recover datafile 8 block 13;

关于Oraclerman恢复,这里简单讨论数据文件损坏的情况,后面会详细讨论不同类型文件损坏的恢复方式。

[oracle@edsir4p1-PROD1 PROD1]$ rm *.dbfSYS@PROD1> startup mount;ORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesDatabase mounted.[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 04:37:13 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015, not open)RMAN> restore database;Starting restore at 15-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_1uujf5mi_1_1.bak --从rman备份中恢复channel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00001 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_1sujf5mi_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbfchannel ORA_DISK_3: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbfchannel ORA_DISK_3: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_1tujf5mi_1_1.bakchannel ORA_DISK_4: starting datafile backup set restorechannel ORA_DISK_4: specifying datafile(s) to restore from backup setchannel ORA_DISK_4: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbfchannel ORA_DISK_4: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbfchannel ORA_DISK_4: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_4: reading from backup piece /home/oracle/backup/full_PROD1_1vujf5mj_1_1.bakchannel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_1uujf5mi_1_1.bak tag=TAG20191215T043426channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:26channel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_1sujf5mi_1_1.bak tag=TAG20191215T043426channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:28channel ORA_DISK_4: piece handle=/home/oracle/backup/full_PROD1_1vujf5mj_1_1.bak tag=TAG20191215T043426channel ORA_DISK_4: restored backup piece 1channel ORA_DISK_4: restore complete, elapsed time: 00:00:28channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_1tujf5mi_1_1.bak tag=TAG20191215T043426channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:38Finished restore at 15-DEC-19RMAN> recover database;Starting recover at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoverymedia recovery complete, elapsed time: 00:00:00Finished recover at 15-DEC-19--查看数据文件头scn和控制文件头scn是否一致,一致可尝试open数据库SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 1385736 13857362 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 1385736 13857363 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 1385736 13857364 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 1385736 13857365 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 1385736 13857366 /u01/app/oracle/oradata/PROD1/test.dbf 1385736 13857367 /u01/app/oracle/oradata/PROD1/indx.dbf 1385736 13857368 /u01/app/oracle/oradata/PROD1/tools.dbf 1385736 13857369 /u01/app/oracle/oradata/PROD1/oltp.dbf 1385736 138573610 /u01/app/oracle/oradata/PROD1/tbs01.dbf 1385736 138573610 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 13857362 13857363 13857364 13857365 13857366 13857367 13857368 13857369 138573610 138573610 rows selected.RMAN> alter database open;database opened在Oracle11g以后Oracle引入了DRA(Data Recovery Advisor),DRA简化了数据库的恢复步骤。[oracle@edsir4p1-PROD1 PROD1]$ rm *.dbfSYS@PROD1> startupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 6 - see DBWR trace fileORA-01110: data file 6: '/u01/app/oracle/oradata/PROD1/test.dbf'SYS@PROD1>[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 04:40:24 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> list failure; --列出当前数据库的故障using target database control file instead of recovery catalogList of Database Failures=========================Failure ID Priority Status Time Detected Summary---------- -------- --------- ------------- -------2345 HIGH OPEN 15-DEC-19 One or more non-system datafiles are missing8 HIGH OPEN 15-DEC-19 One or more non-system datafiles need media recovery2402 HIGH OPEN 15-DEC-19 Name for datafile 10 is unknown in the control fileRMAN> advise failure; --Oracle建议怎样恢复List of Database Failures=========================Failure ID Priority Status Time Detected Summary---------- -------- --------- ------------- -------2345 HIGH OPEN 15-DEC-19 One or more non-system datafiles are missing8 HIGH OPEN 15-DEC-19 One or more non-system datafiles need media recovery2402 HIGH OPEN 15-DEC-19 Name for datafile 10 is unknown in the control fileanalyzing automatic repair options; this may take some timeallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=10 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKanalyzing automatic repair options completeMandatory Manual Actions========================no manual actions availableOptional Manual Actions=======================1. If file /u01/app/oracle/oradata/PROD1/test.dbf was unintentionally renamed or moved, restore it2. If file /u01/app/oracle/oradata/PROD1/indx.dbf was unintentionally renamed or moved, restore it3. If file /u01/app/oracle/oradata/PROD1/tools.dbf was unintentionally renamed or moved, restore it4. If file /u01/app/oracle/oradata/PROD1/oltp.dbf was unintentionally renamed or moved, restore it5. If file /u01/app/oracle/oradata/PROD1/tbs01.dbf was unintentionally renamed or moved, restore it6. If you restored the wrong version of data file /u01/app/oracle/oradata/PROD1/test.dbf, then replace it with the correct one7. If you restored the wrong version of data file /u01/app/oracle/oradata/PROD1/indx.dbf, then replace it with the correct one8. If you restored the wrong version of data file /u01/app/oracle/oradata/PROD1/tools.dbf, then replace it with the correct one9. If you restored the wrong version of data file /u01/app/oracle/oradata/PROD1/oltp.dbf, then replace it with the correct one10. If you restored the wrong version of data file /u01/app/oracle/oradata/PROD1/tbs01.dbf, then replace it with the correct one11. Rename datafile 10 to the name of the real fileAutomated Repair Options========================Option Repair Description------ ------------------1 Restore and recover datafile 6; Restore and recover datafile 7; Restore and recover datafile 8; ...Strategy: The repair includes complete media recovery with no data lossRepair script: /u01/app/oracle/diag/rdbms/prod1/PROD1/hm/reco_1722683907.hmRMAN> repair failure; --使用顾问方式恢复Strategy: The repair includes complete media recovery with no data lossRepair script: /u01/app/oracle/diag/rdbms/prod1/PROD1/hm/reco_1722683907.hmcontents of repair script:# restore and recover datafilerestore datafile 6, 7, 8, 9, 10;recover datafile 6, 7, 8, 9, 10;Do you really want to execute the above repair (enter YES or NO)? yesexecuting repair scriptStarting restore at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_1uujf5mi_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_1tujf5mi_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_1vujf5mj_1_1.bakchannel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_1tujf5mi_1_1.bak tag=TAG20191215T043426channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:01channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_1vujf5mj_1_1.bak tag=TAG20191215T043426channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:03channel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_1uujf5mi_1_1.bak tag=TAG20191215T043426channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:07Finished restore at 15-DEC-19Starting recover at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 13 is already on disk as file /home/oracle/arch1/1_13_1027052494.dbfarchived log for thread 1 with sequence 14 is already on disk as file /home/oracle/arch1/1_14_1027052494.dbfarchived log for thread 1 with sequence 15 is already on disk as file /home/oracle/arch1/1_15_1027052494.dbfarchived log file name=/home/oracle/arch1/1_13_1027052494.dbf thread=1 sequence=13media recovery complete, elapsed time: 00:00:00Finished recover at 15-DEC-19repair failure completeDo you want to open the database (enter YES or NO)? yesdatabase openedRMAN>

详细信息可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/bradv/part-diagnosing-responding-failures.html#GUID-ED89DC53-A816-450B-BFF4-A712D2694EEC

恢复表空间

recover tablespace xxx from '/bak1/tablespace_bak_XXX.bak';

恢复数据文件

recover datafile 11 from '/bak1/back.bak';

恢复单个表

RECOVER TABLE username.tablename UNTIL TIME 'TIMESTAMP…'

五、恢复spfile

1、从备份中恢复spfile

① 设置dbid

SYS@PROD1> show parameter spfileNAME TYPE VALUE------------------------------------ ----------- ------------------------------spfile string /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilePROD1.ora[oracle@edsir4p1-PROD1 PROD1]$ cd $ORACLE_HOME/dbs[oracle@edsir4p1-PROD1 dbs]$ ls -larttotal 19684-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora-rw-r----- 1 oracle oinstall 1536 Aug 10 04:25 orapwPROD1drwxr-xr-x 6 oracle oinstall 4096 Dec 15 05:01 .-rw-r----- 1 oracle oinstall 4608 Dec 15 05:01 spfilePROD1.ora[oracle@edsir4p1-PROD1 dbs]$ mv spfilePROD1.ora spfilePROD1.ora.bak[oracle@edsir4p1-PROD1 dbs]$ ls -larttotal 19684-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.oradrwxr-xr-x 75 oracle oinstall 4096 Jul 10 13:03 ..-rw-r----- 1 oracle oinstall 1536 Aug 10 04:25 orapwPROD1-rw-r----- 1 oracle oinstall 4608 Dec 15 05:01 spfilePROD1.ora.bakdrwxr-xr-x 6 oracle oinstall 4096 Dec 15 05:23 .删除参数文件之后并不会有报错,该参数文件只有在数据库启动的时候才会读取,删除参数文件对正常运行状态下的数据库不影响。SYS@PROD1> alter system switch logfile;System altered.SYS@PROD1> alter system switch logfile;System altered.Thread 1 advanced to log sequence 18 (LGWR switch)Current log# 3 seq# 18 mem# 0: /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_3_gzcf6jm9_.logCurrent log# 3 seq# 18 mem# 1: /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcf6jxh_.logSun Dec 15 05:24:20 2019Archived Log entry 110 added for thread 1 sequence 17 ID 0x8604367b dest 1:Thread 1 advanced to log sequence 19 (LGWR switch)Current log# 1 seq# 19 mem# 0: /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_1_gzcf6h1o_.logCurrent log# 1 seq# 19 mem# 1: /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcf6hdr_.logSun Dec 15 05:24:24 2019Archived Log entry 111 added for thread 1 sequence 18 ID 0x8604367b dest 1:[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 05:31:57 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database (not started)--设置DBIDRMAN> set DBID = 387098034executing command: SET DBIDRMAN> startup nomount;startup failed: ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initPROD1.ora'starting Oracle instance without parameter file for retrieval of spfileOracle instance startedTotal System Global Area 159019008 bytesFixed Size 1335192 bytesVariable Size 79691880 bytesDatabase Buffers 71303168 bytesRedo Buffers 6688768 bytesRMAN> restore spfile from '/u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkp';Starting restore at 15-DEC-19allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=96 device type=DISKchannel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkpchannel ORA_DISK_1: SPFILE restore from AUTOBACKUP completeFinished restore at 15-DEC-19[oracle@edsir4p1-PROD1 dbs]$ ls -larttotal 19684-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.oradrwxr-xr-x 75 oracle oinstall 4096 Jul 10 13:03 ..-rw-r----- 1 oracle oinstall 1536 Aug 10 04:25 orapwPROD1-rw-r----- 1 oracle oinstall 4608 Dec 15 05:01 spfilePROD1.ora.bak-rw-r----- 1 oracle oinstall 4608 Dec 15 05:32 spfilePROD1.oradrwxr-xr-x 6 oracle oinstall 4096 Dec 15 05:23 .--重启数据库SYS@PROD1> shutdown immediate;ORA-01507: database not mountedORACLE instance shut down.SYS@PROD1>startupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesDatabase mounted.Database opened.SYS@PROD1>

②使用默认spfile

[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 05:39:04 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database (not started)--生成一个默认spfileRMAN> startup nomountstartup failed: ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initPROD1.ora'starting Oracle instance without parameter file for retrieval of spfileOracle instance startedTotal System Global Area 159019008 bytesFixed Size 1335192 bytesVariable Size 79691880 bytesDatabase Buffers 71303168 bytesRedo Buffers 6688768 bytesRMAN> restore spfile from '/u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkp';Starting restore at 15-DEC-19using channel ORA_DISK_1channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkpchannel ORA_DISK_1: SPFILE restore from AUTOBACKUP completeFinished restore at 15-DEC-19RMAN> shutdown immediateOracle instance shut downRMAN> startupconnected to target database (not started)Oracle instance starteddatabase mounteddatabase openedTotal System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesRMAN>

2、从启动信息中获取spfile

在启动的时候在alert中会有启动信息,在这个信息中会有参数文件的一些信息,但是在长久稳定运行的数据库系统中这个信息是比较难找的。

cat /u01/app/oracle/diag/rdbms/prod1/PROD1/trace/cat alert_PROD1.logStarting up:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options.Using parameter settings in server-side spfile /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilePROD1.oraSystem parameters with non-default values:processes = 135sessions = 300sga_target = 608Mcontrol_files = "/u01/app/oracle/oradata/PROD1/controlfile/control01.ctl"control_files = "/u01/app/oracle/oradata/PROD1/controlfile/control02.ctl"control_files = "/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctl"db_block_size = 8192compatible = "11.2.0.0.0"log_archive_dest_1 = "location=/home/oracle/arch1"db_create_file_dest = "/u01/app/oracle/oradata"db_recovery_file_dest = "/u01/app/oracle/flash_recovery_area"db_recovery_file_dest_size= 3852Mundo_management = "AUTO"undo_tablespace = "UNDOTBS1"undo_retention = 5400remote_login_passwordfile= "EXCLUSIVE"db_domain = "US.ORACLE.COM"dispatchers = "(PROTOCOL=TCP) (dispatcher=3)"shared_servers = 10max_shared_servers = 30max_dispatchers = 10shared_server_sessions = 200local_listener = "PROD1"local_listener = "PROD_S"utl_file_dir = "/oracle/home/"utl_file_dir = "/oracle/home/temp"utl_file_dir = "/oracle/home/scripts"job_queue_processes = 1000cursor_sharing = "EXACT"audit_file_dest = "/u01/app/oracle/admin/PROD1/adump"audit_trail = "DB"db_name = "PROD1"open_cursors = 300pga_aggregate_target = 202Mdiagnostic_dest = "/u01/app/oracle"Oracle instance running with ODM: Oracle Direct NFS ODM Library Version 2.0Sun Dec 15 05:41:12 2019

3、从$ORACLE_HOME/dbs/init.ora中获取参数文件

若参数文件没有备份,且数据库长时间未启动还可从int.ora中获取参数文件

[oracle@edsir4p1-PROD1 dbs]$ cat init.ora## $Header: rdbms/admin/init.ora /main/23 2009/05/15 13:35:38 ysarig Exp $## Copyright (c) 1991, 1997, 1998 by Oracle Corporation# NAME# init.ora# FUNCTION# NOTES# MODIFIED# ysarig 05/14/09 - Updating compatible to 11.2# ysarig 08/13/07 - Fixing the sample for 11g# atsukerm 08/06/98 - fix for 8.1.# hpiao 06/05/97 - fix for 803# glavash 05/12/97 - add oracle_trace_enable comment# hpiao 04/22/97 - remove ifile=, events=, etc.# alingelb 09/19/94 - remove vms-specific stuff# dpawson 07/07/93 - add more comments regarded archive start# maporter 10/29/92 - Add vms_sga_use_gblpagfile=TRUE# jloaiza 03/07/92 - change ALPHA to BETA# danderso 02/26/92 - change db_block_cache_protect to _db_block_cache_p# ghallmar 02/03/92 - db_directory -> db_domain# maporter 01/12/92 - merge changes from branch 1.8.308.1# maporter 12/21/91 - bug 76493: Add control_files parameter# wbridge 12/03/91 - use of %c in archive format is discouraged# ghallmar 12/02/91 - add global_names=true, db_directory=us.acme.com# thayes 11/27/91 - Change default for cache_clone# jloaiza 08/13/91 - merge changes from branch 1.7.100.1# jloaiza 07/31/91 - add debug stuff# rlim 04/29/91 - removal of char_is_varchar2# Bridge 03/12/91 - log_allocation no longer exists# Wijaya 02/05/91 - remove obsolete parameters################################################################################ Example INIT.ORA file## This file is provided by Oracle Corporation to help you start by providing# a starting point to customize your RDBMS installation for your site.## NOTE: The values that are used in this file are only intended to be used# as a starting point. You may want to adjust/tune those values to your# specific hardware and needs. You may also consider using Database# Configuration Assistant tool (DBCA) to create INIT file and to size your# initial set of tablespaces based on the user input.################################################################################ Change '<ORACLE_BASE>' to point to the oracle base (the one you specify at# install time)db_name='ORCL'memory_target=1Gprocesses = 150audit_file_dest='<ORACLE_BASE>/admin/orcl/adump'audit_trail ='db'db_block_size=8192db_domain=''db_recovery_file_dest='<ORACLE_BASE>/flash_recovery_area'db_recovery_file_dest_size=2Gdiagnostic_dest='<ORACLE_BASE>'dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'open_cursors=300remote_login_passwordfile='EXCLUSIVE'undo_tablespace='UNDOTBS1'# You may want to ensure that control files are created on separate physical# devicescontrol_files = (ora_control1, ora_control2)compatible ='11.2.0'

4、手动编辑spfile

如果整个dbs目录都损坏了,那么也还可以通过手动编辑参数文件来启动,只需编辑基础参数,然后在后期优化参数

六、恢复controlfile

1、冷备恢复

在实际生产环境中控制文件至少有2个,有些环境还存在控制文件多路复用,若一个控制文件损坏可将其他控制文件复制过来即可。

2、从备份中恢复控制文件

控制文件中记录了数据文件头信息,备份信息等诸多信息,在重建控制文件之后需重新进行全量备份

[oracle@edsir4p1-PROD1 controlfile]$ rm -rf control0*[oracle@edsir4p1-PROD1 controlfile]$ rm /u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlSYS@PROD1> startupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesORA-00205: error in identifying control file, check alert log for more infoSYS@PROD1>[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 07:40:25 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> restore controlfile from '/home/oracle/backup/full_PROD1_28ujf5nl_1_1.ctl';Starting restore at 15-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/PROD1/controlfile/control01.ctloutput file name=/u01/app/oracle/oradata/PROD1/controlfile/control02.ctloutput file name=/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlFinished restore at 15-DEC-19RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1

--查看此时数据文件头SCN和控制文件SCN,由于控制文件较老,在recover database的时候是根据数据文件来将现在的数据文件头信息写入控制文件中,不过此时控制文件已经不包含备份集时间点到宕机时间点的备份信息,在恢复控制文件之后需要重新全备。

SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 13655322 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 13655343 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 13655394 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 13655345 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 13655396 /u01/app/oracle/oradata/PROD1/test.dbf 13655367 /u01/app/oracle/oradata/PROD1/indx.dbf 13655368 /u01/app/oracle/oradata/PROD1/tools.dbf 13655349 /u01/app/oracle/oradata/PROD1/oltp.dbf 136553610 /u01/app/oracle/oradata/PROD1/tbs01.dbf 136553910 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 14112102 14112103 14112104 14112105 14112106 14112107 14112108 14112109 141121010 141121010 rows selected.RMAN> recover database;Starting recover at 15-DEC-19Starting implicit crosscheck backup at 15-DEC-19allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKCrosschecked 24 objectsFinished implicit crosscheck backup at 15-DEC-19Starting implicit crosscheck copy at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4Finished implicit crosscheck copy at 15-DEC-19searching for all files in the recovery areacataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985546_gz9fh3lc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985321_gz9cm9rk_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982337_gz98p1j0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026989209_gz9hdsdh_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982024_gz98d8sr_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026984092_gz9bpmmc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026987847_gz9g28b0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054861_gzchl3h1_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027047781_gzc8m5og_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054729_gzchd9n2_.bkpusing channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 17 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_2_gzcf6j5o_.logarchived log for thread 1 with sequence 18 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcf6jxh_.logarchived log for thread 1 with sequence 19 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcf6hdr_.logarchived log file name=/home/oracle/arch1/1_15_1027052494.dbf thread=1 sequence=15archived log file name=/home/oracle/arch1/1_16_1027052494.dbf thread=1 sequence=16archived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_2_gzcf6j5o_.log thread=1 sequence=17archived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcf6jxh_.log thread=1 sequence=18archived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcf6hdr_.log thread=1 sequence=19media recovery complete, elapsed time: 00:00:01Finished recover at 15-DEC-19SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 1430609 14306092 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 1430609 14306093 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 1430609 14306094 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 1430609 14306095 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 1430609 14306096 /u01/app/oracle/oradata/PROD1/test.dbf 1430609 14306097 /u01/app/oracle/oradata/PROD1/indx.dbf 1430609 14306098 /u01/app/oracle/oradata/PROD1/tools.dbf 1430609 14306099 /u01/app/oracle/oradata/PROD1/oltp.dbf 1430609 143060910 /u01/app/oracle/oradata/PROD1/tbs01.dbf 1430609 143060910 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 14306092 14306093 14306094 14306095 14306096 14306097 14306098 14306099 143060910 143060910 rows selected.--由于控制文件重建了,所以启动需要resetlogs,详细可参考:https://blog.csdn.net/renyanjie123/article/details/82935937RMAN> alter database open;RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of alter db command at 12/15/2019 07:42:23ORA-01589: must use RESETLOGS or NORESETLOGS option for database openRMAN> alter database open resetlogs;database openedSYS@PROD1> archive log list;Database log mode Archive ModeAutomatic archival EnabledArchive destination /home/oracle/arch1Oldest online log sequence 1Next log sequence to archive 1Current log sequence 1

3、基于数据文件生成控制文件

当控制文件损坏,而备份中有无有效的控制文件备份,还可通过手工创建控制文件起库,但是前提是数据文件必须完整,若数据文件损坏则不能通过手工创建控制文件来恢复。

CREATE CONTROLFILESET DATABASE prod1LOGFILE GROUP 1 ('/u01/oracle/prod/redo01_01.log','/u01/oracle/prod/redo01_02.log'),GROUP 2 ('/u01/oracle/prod/redo02_01.log','/u01/oracle/prod/redo02_02.log'),GROUP 3 ('/u01/oracle/prod/redo03_01.log','/u01/oracle/prod/redo03_02.log')RESETLOGSDATAFILE '/u01/oracle/prod/system01.dbf' SIZE 3M,'/u01/oracle/prod/rbs01.dbs' SIZE 5M,'/u01/oracle/prod/users01.dbs' SIZE 5M,'/u01/oracle/prod/temp01.dbs' SIZE 5MMAXLOGFILES 50MAXLOGMEMBERS 3MAXLOGHISTORY 400MAXDATAFILES 200MAXINSTANCES 6ARCHIVELOG;

详见可参照:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/admin/managing-control-files.html#GUID-E4677C95-CDBE-4FB5-9A9E-A227B3547FAE

七、恢复数据文件

1、冷备恢复

冷备恢复数据文件是将某个表空间数据文件或者多个表空间恢复到备份时间点,这种情况下是没有进行热备份的环境,会丢失部分数据。

2、rman恢复

[oracle@edsir4p1-PROD1 PROD1]$ rm -rf tbs01.dbfSYS@PROD1> startupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 243270632 bytesDatabase Buffers 385875968 bytesRedo Buffers 5615616 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 10 - see DBWR trace fileORA-01110: data file 10: '/u01/app/oracle/oradata/PROD1/tbs01.dbf'[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 08:16:49 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2102759015, not open)RMAN> restore datafile 10;Starting restore at 15-DEC-19using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_2eujfiht_1_1.bakchannel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_2eujfiht_1_1.bak tag=TAG20191215T081348channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:01Finished restore at 15-DEC-19--查看10号文件的数据文件头SCN比较小,需要recoverSYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 14335452 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 14335453 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 14335454 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 14335455 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 14335456 /u01/app/oracle/oradata/PROD1/test.dbf 14335457 /u01/app/oracle/oradata/PROD1/indx.dbf 14335458 /u01/app/oracle/oradata/PROD1/tools.dbf 14335459 /u01/app/oracle/oradata/PROD1/oltp.dbf 143354510 /u01/app/oracle/oradata/PROD1/tbs01.dbf 143354510 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 14335452 14335453 14335454 14335455 14335456 14335457 14335458 14335459 143354510 143337510 rows selected.RMAN> recover datafile 10;Starting recover at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 1 is already on disk as file /home/oracle/arch1/1_1_1027064551.dbfarchived log for thread 1 with sequence 2 is already on disk as file /home/oracle/arch1/1_2_1027064551.dbfarchived log for thread 1 with sequence 3 is already on disk as file /home/oracle/arch1/1_3_1027064551.dbfarchived log for thread 1 with sequence 4 is already on disk as file /home/oracle/arch1/1_4_1027064551.dbfarchived log for thread 1 with sequence 5 is already on disk as file /home/oracle/arch1/1_5_1027064551.dbfarchived log for thread 1 with sequence 6 is already on disk as file /home/oracle/arch1/1_6_1027064551.dbfarchived log for thread 1 with sequence 7 is already on disk as file /home/oracle/arch1/1_7_1027064551.dbfarchived log for thread 1 with sequence 8 is already on disk as file /home/oracle/arch1/1_8_1027064551.dbfarchived log for thread 1 with sequence 9 is already on disk as file /home/oracle/arch1/1_9_1027064551.dbfarchived log for thread 1 with sequence 10 is already on disk as file /home/oracle/arch1/1_10_1027064551.dbfarchived log for thread 1 with sequence 11 is already on disk as file /home/oracle/arch1/1_11_1027064551.dbfarchived log for thread 1 with sequence 12 is already on disk as file /home/oracle/arch1/1_12_1027064551.dbfarchived log for thread 1 with sequence 13 is already on disk as file /home/oracle/arch1/1_13_1027064551.dbfarchived log for thread 1 with sequence 14 is already on disk as file /home/oracle/arch1/1_14_1027064551.dbfarchived log for thread 1 with sequence 15 is already on disk as file /home/oracle/arch1/1_15_1027064551.dbfarchived log for thread 1 with sequence 16 is already on disk as file /home/oracle/arch1/1_16_1027064551.dbfarchived log for thread 1 with sequence 17 is already on disk as file /home/oracle/arch1/1_17_1027064551.dbfarchived log for thread 1 with sequence 18 is already on disk as file /home/oracle/arch1/1_18_1027064551.dbfarchived log for thread 1 with sequence 19 is already on disk as file /home/oracle/arch1/1_19_1027064551.dbfarchived log file name=/home/oracle/arch1/1_1_1027064551.dbf thread=1 sequence=1archived log file name=/home/oracle/arch1/1_2_1027064551.dbf thread=1 sequence=2archived log file name=/home/oracle/arch1/1_3_1027064551.dbf thread=1 sequence=3archived log file name=/home/oracle/arch1/1_4_1027064551.dbf thread=1 sequence=4archived log file name=/home/oracle/arch1/1_5_1027064551.dbf thread=1 sequence=5archived log file name=/home/oracle/arch1/1_6_1027064551.dbf thread=1 sequence=6archived log file name=/home/oracle/arch1/1_7_1027064551.dbf thread=1 sequence=7archived log file name=/home/oracle/arch1/1_8_1027064551.dbf thread=1 sequence=8archived log file name=/home/oracle/arch1/1_9_1027064551.dbf thread=1 sequence=9archived log file name=/home/oracle/arch1/1_10_1027064551.dbf thread=1 sequence=10archived log file name=/home/oracle/arch1/1_11_1027064551.dbf thread=1 sequence=11archived log file name=/home/oracle/arch1/1_12_1027064551.dbf thread=1 sequence=12archived log file name=/home/oracle/arch1/1_13_1027064551.dbf thread=1 sequence=13archived log file name=/home/oracle/arch1/1_14_1027064551.dbf thread=1 sequence=14archived log file name=/home/oracle/arch1/1_15_1027064551.dbf thread=1 sequence=15archived log file name=/home/oracle/arch1/1_16_1027064551.dbf thread=1 sequence=16archived log file name=/home/oracle/arch1/1_17_1027064551.dbf thread=1 sequence=17media recovery complete, elapsed time: 00:00:01Finished recover at 15-DEC-19--recover之后发现10号数据文件头SCN和控制文件中的scn已经一致,由于其他数据文件是read only状态,还没有应用日志。SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;select file#,checkpoint_change# from v$datafile_header;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 14335452 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 14335453 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 14335454 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 14335455 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 14335456 /u01/app/oracle/oradata/PROD1/test.dbf 14335457 /u01/app/oracle/oradata/PROD1/indx.dbf 14335458 /u01/app/oracle/oradata/PROD1/tools.dbf 14335459 /u01/app/oracle/oradata/PROD1/oltp.dbf 143354510 /u01/app/oracle/oradata/PROD1/tbs01.dbf 1453587 145358710 rows selected.SYS@PROD1>FILE# CHECKPOINT_CHANGE#---------- ------------------1 14335452 14335453 14335454 14335455 14335456 14335457 14335458 14335459 143354510 145358710 rows selected.RMAN> alter database open;database openedRMAN>--发现数据文件头SCN和控制文件SCN已经完全一致了SYS@PROD1> set linesize 200;SYS@PROD1> col name for a80;SYS@PROD1> select file#,name,checkpoint_change#,last_change# from v$datafile;FILE# NAME CHECKPOINT_CHANGE# LAST_CHANGE#---------- -------------------------------------------------------------------------------- ------------------ ------------1 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf 14535902 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbf 14535903 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbf 14535904 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbf 14535905 /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbf 14535906 /u01/app/oracle/oradata/PROD1/test.dbf 14535907 /u01/app/oracle/oradata/PROD1/indx.dbf 14535908 /u01/app/oracle/oradata/PROD1/tools.dbf 14535909 /u01/app/oracle/oradata/PROD1/oltp.dbf 145359010 /u01/app/oracle/oradata/PROD1/tbs01.dbf 145359010 rows selected.SYS@PROD1> select file#,checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 14535902 14535903 14535904 14535905 14535906 14535907 14535908 14535909 145359010 145359010 rows selected.SYS@PROD1>

3、归档日志反写恢复数据文件

SYS@PROD1> create tablespace tbs2 datafile '/u01/app/oracle/oradata/PROD1/tbs02.dbf'size 10m;Tablespace created.SYS@PROD1> create table test1 (id int,name varchar2(20));Table created.SYS@PROD1> insert into test1 values(3,'a');1 row created.SYS@PROD1> commit;Commit complete.SYS@PROD1> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1 1 19 52428800 512 2 YES INACTIVE 1433541 15-DEC-19 1433545 15-DEC-192 1 20 52428800 512 2 YES INACTIVE 1433545 15-DEC-19 1453589 15-DEC-193 1 21 52428800 512 2 NO CURRENT 1453589 15-DEC-19 2.8147E+14SYS@PROD1> alter system switch logfile;System altered.SYS@PROD1> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1 1 22 52428800 512 2 NO CURRENT 1454529 15-DEC-19 2.8147E+142 1 20 52428800 512 2 YES INACTIVE 1433545 15-DEC-19 1453589 15-DEC-193 1 21 52428800 512 2 YES ACTIVE 1453589 15-DEC-19 1454529 15-DEC-19SYS@PROD1> insert into test1 values(3,'b');1 row created.SYS@PROD1> shutdown abortORACLE instance shut down.SYS@PROD1> startupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 239076328 bytesDatabase Buffers 390070272 bytesRedo Buffers 5615616 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 1 - see DBWR trace fileORA-01110: data file 1: '/u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbf'SYS@PROD1>[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 15 08:33:44 2019Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> restore controlfile from '/home/oracle/backup/full_PROD1_2lujfiiq_1_1.ctl';Starting restore at 15-DEC-19using channel ORA_DISK_1channel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/PROD1/controlfile/control01.ctloutput file name=/u01/app/oracle/oradata/PROD1/controlfile/control02.ctloutput file name=/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlFinished restore at 15-DEC-19RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1RMAN> restore database;Starting restore at 15-DEC-19Starting implicit crosscheck backup at 15-DEC-19allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKCrosschecked 35 objectsFinished implicit crosscheck backup at 15-DEC-19Starting implicit crosscheck copy at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4Finished implicit crosscheck copy at 15-DEC-19searching for all files in the recovery areacataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985546_gz9fh3lc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985321_gz9cm9rk_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982337_gz98p1j0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026989209_gz9hdsdh_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982024_gz98d8sr_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026984092_gz9bpmmc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026987847_gz9g28b0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054861_gzchl3h1_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027066460_gzcttwrd_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027047781_gzc8m5og_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054729_gzchd9n2_.bkpusing channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_gzcd23sz_.dbfchannel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcd268x_.dbfchannel ORA_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_2eujfiht_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00001 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcd23sr_.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_2bujfiht_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcd242h_.dbfchannel ORA_DISK_3: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_gzcd23v7_.dbfchannel ORA_DISK_3: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_2cujfiht_1_1.bakchannel ORA_DISK_4: starting datafile backup set restorechannel ORA_DISK_4: specifying datafile(s) to restore from backup setchannel ORA_DISK_4: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_4: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_4: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_4: reading from backup piece /home/oracle/backup/full_PROD1_2dujfiht_1_1.bakchannel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_2bujfiht_1_1.bak tag=TAG20191215T081348channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:15channel ORA_DISK_4: piece handle=/home/oracle/backup/full_PROD1_2dujfiht_1_1.bak tag=TAG20191215T081348channel ORA_DISK_4: restored backup piece 1channel ORA_DISK_4: restore complete, elapsed time: 00:00:18channel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_2eujfiht_1_1.bak tag=TAG20191215T081348channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:28channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_2cujfiht_1_1.bak tag=TAG20191215T081348channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:28Finished restore at 15-DEC-19RMAN> recover database;Starting recover at 15-DEC-19using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 1 is already on disk as file /home/oracle/arch1/1_1_1027064551.dbfarchived log for thread 1 with sequence 2 is already on disk as file /home/oracle/arch1/1_2_1027064551.dbfarchived log for thread 1 with sequence 21 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcf6jxh_.logarchived log for thread 1 with sequence 22 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcf6hdr_.logarchived log for thread 1 with sequence 23 is already on disk as file /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_2_gzcf6j5o_.logarchived log file name=/home/oracle/arch1/1_1_1027064551.dbf thread=1 sequence=1archived log file name=/home/oracle/arch1/1_2_1027064551.dbf thread=1 sequence=2archived log file name=/home/oracle/arch1/1_3_1027064551.dbf thread=1 sequence=3archived log file name=/home/oracle/arch1/1_4_1027064551.dbf thread=1 sequence=4archived log file name=/home/oracle/arch1/1_5_1027064551.dbf thread=1 sequence=5archived log file name=/home/oracle/arch1/1_6_1027064551.dbf thread=1 sequence=6archived log file name=/home/oracle/arch1/1_7_1027064551.dbf thread=1 sequence=7archived log file name=/home/oracle/arch1/1_8_1027064551.dbf thread=1 sequence=8archived log file name=/home/oracle/arch1/1_9_1027064551.dbf thread=1 sequence=9archived log file name=/home/oracle/arch1/1_10_1027064551.dbf thread=1 sequence=10archived log file name=/home/oracle/arch1/1_11_1027064551.dbf thread=1 sequence=11archived log file name=/home/oracle/arch1/1_12_1027064551.dbf thread=1 sequence=12archived log file name=/home/oracle/arch1/1_13_1027064551.dbf thread=1 sequence=13archived log file name=/home/oracle/arch1/1_14_1027064551.dbf thread=1 sequence=14archived log file name=/home/oracle/arch1/1_15_1027064551.dbf thread=1 sequence=15archived log file name=/home/oracle/arch1/1_16_1027064551.dbf thread=1 sequence=16archived log file name=/home/oracle/arch1/1_17_1027064551.dbf thread=1 sequence=17archived log file name=/home/oracle/arch1/1_18_1027064551.dbf thread=1 sequence=18archived log file name=/home/oracle/arch1/1_19_1027064551.dbf thread=1 sequence=19archived log file name=/home/oracle/arch1/1_20_1027064551.dbf thread=1 sequence=20archived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcf6jxh_.log thread=1 sequence=21creating datafile file number=11 name=/u01/app/oracle/oradata/PROD1/tbs02.dbfarchived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcf6jxh_.log thread=1 sequence=21archived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcf6hdr_.log thread=1 sequence=22archived log file name=/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_2_gzcf6j5o_.log thread=1 sequence=23media recovery complete, elapsed time: 00:00:00Finished recover at 15-DEC-19RMAN> alter database open resetlogs;database openedRMAN>

八、恢复redo文件

1、恢复inactive redo

非在线redo损坏可将redo删掉后重建redo

SQL> startup mount;ORACLE instance started.Total System Global Area 3156877312 bytesFixed Size 2217424 bytesVariable Size 989858352 bytesDatabase Buffers 2147483648 bytesRedo Buffers 17317888 bytesDatabase mounted.SQL> alter database drop logfile group 1;Database altered.SQL> alter database open;Database altered.如果该联机日志还未完成归档,需使用如下命令删除alter database clear unarchived logfile group 3;2、恢复online redo如果当前redo损坏就意味着一定会丢数据。SYS@PROD1> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1 1 10 52428800 512 2 NO CURRENT 1475864 15-DEC-19 2.8147E+142 1 8 52428800 512 2 YES INACTIVE 1475857 15-DEC-19 1475860 15-DEC-193 1 9 52428800 512 2 YES INACTIVE 1475860 15-DEC-19 1475864 15-DEC-19SYS@PROD1> insert into test1 values(4,'b');1 row created.SYS@PROD1> commit;Commit complete.SYS@PROD1> select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1 1 10 52428800 512 2 NO CURRENT 1475864 15-DEC-19 2.8147E+142 1 8 52428800 512 2 YES INACTIVE 1475857 15-DEC-19 1475860 15-DEC-193 1 9 52428800 512 2 YES INACTIVE 1475860 15-DEC-19 1475864 15-DEC-19SYS@PROD1> select * from v$logfile;GROUP# STATUS TYPE MEMBER IS_---------- ------- ------- -------------------------------------------------------------------------------- ---3 ONLINE /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_3_gzcw6t13_.log NO3 ONLINE /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_3_gzcw6t81_.log YES2 ONLINE /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_2_gzcw6sk4_.log NO2 ONLINE /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_2_gzcw6sr5_.log YES1 ONLINE /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_1_gzcw6s19_.log NO1 ONLINE /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcw6s8v_.log YES6 rows selected.SYS@PROD1> alter system switch logfile;System altered.SYS@PROD1> shutdown immediate;[oracle@edsir4p1-PROD1 PROD1]$ mv /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_1_gzcw6s19_.log /u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_1_gzcw6s19_.log.bak[oracle@edsir4p1-PROD1 PROD1]$ mv /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcw6s8v_.log /u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcw6s8v_.log.bak[oracle@edsir4p1-PROD1 PROD1]$SYS@PROD1> startupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 239076328 bytesDatabase Buffers 390070272 bytesRedo Buffers 5615616 bytesDatabase mounted.ORA-03113: end-of-file on communication channelProcess ID: 999Session ID: 1 Serial number: 5SYS@PROD1>Sun Dec 15 08:53:17 2019Errors in file /u01/app/oracle/diag/rdbms/prod1/PROD1/trace/PROD1_arc1_31402.trc:ORA-00313: open failed for members of log group 1 of thread 1ORA-00312: online log 1 thread 1: '/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcw6s8v_.log'ORA-27037: unable to obtain file statusLinux Error: 2: No such file or directoryAdditional information: 3ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_1_gzcw6s19_.log'ORA-27037: unable to obtain file statusLinux Error: 2: No such file or directoryAdditional information: 3Errors in file /u01/app/oracle/diag/rdbms/prod1/PROD1/trace/PROD1_arc1_31402.trc:ORA-00313: open failed for members of log group 1 of thread 1ORA-00312: online log 1 thread 1: '/u01/app/oracle/flash_recovery_area/PROD1/onlinelog/o1_mf_1_gzcw6s8v_.log'ORA-27037: unable to obtain file statusLinux Error: 2: No such file or directoryAdditional information: 3ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_1_gzcw6s19_.log'ORA-27037: unable to obtain file statusLinux Error: 2: No such file or directoryAdditional information: 3SYS@PROD1> startup mount;ORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 239076328 bytesDatabase Buffers 390070272 bytesRedo Buffers 5615616 bytesDatabase mounted.SYS@PROD1>SYS@PROD1> recover database using backup controlfile until cancel;ORA-00279: change 1475864 generated at 12/15/2019 08:51:30 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_10_1027067864.dbfORA-00280: change 1475864 for thread 1 is in sequence #10Specify log: {<RET>=suggested | filename | AUTO | CANCEL}cancelMedia recovery cancelled.SYS@PROD1> alter database open resetlogs;Database altered.

九、隐含参数强拉数据库

在实际生产环境中不可避免会有一些极端情况,存储掉电,存储损坏,服务器宕机都会引起备份失效,归档丢失,redo损坏等不能进行恢复数据库的情况。那么就需要使用隐含参数来将数据库跳过一致性检查强拉数据库,此方式强拉数据库之后数据库会随时宕机,源库数据应及时导出。

create pfile='/home/oracle/pfile.ora' from spfilevi /home/oracle/pfile.ora -在参数文件中加入*._allow_resetlogs_corruption=TRUE*._corrupted_rollback_segments=(_syssmu1$,_syssmu2$,_syssmu3$,_syssmu4$,_syssmu5$,_syssmu6$,_syssmu7$,_syssmu8$,_syssmu9$,_syssmu10$,_syssmu11$,_syssmu12$,_syssmu13$,_syssmu14$,_syssmu15$,_syssmu16$,_syssmu17$,_syssmu18$,_syssmu19$,_syssmu20$,_syssmu21$,_syssmu22$,_syssmu23$,_syssmu24$,_syssmu25$,_syssmu26$,_syssmu27$,_syssmu28$,_syssmu29$,_syssmu30$,_syssmu31$,_syssmu32$,_syssmu33$)startup pfile='/oracle/pfile.ora' mount;alter database open resetlogs;

十、恢复数据块

1、物理坏块

物理坏块是由于硬件问题引发的磁盘损坏造成的,这也是比较常见的坏块现象,在alert中有明显报错,且该方式可以检查。

可使用rman修复

RMAN>backup validate datafile 4;

RMAN> run {blockrecover datafile 4 block 133;}

2、逻辑坏块

逻辑坏块是由于数据库逻辑层面的问题造成的坏块,在alert日志没有明显ora报错,可通过v$database_block_corruption查看;

同样依然可使用rman进行修复blockrecover datafile 5 block 2969045,也可直接通过DBMS_REPAIR.SKIP_CORRUPT_BLOCKS跳过坏块;

详见可参考:https://blog.csdn.net/renyanjie123/article/details/103551042

十一、Oracle不完全恢复(Incomplete recover)

Oracle不完全恢复是Oraclerman恢复的另一个比较灵活的恢复方式,他可以让DBA在有效备份的前提下,将数据库恢复到任意时间点,还可用于对于缺失某些归档文件或者online redo、某个过去时间点数据被破坏、误删除表空间的恢复环境中。

1、基于时间点

[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sat Jan 4 03:11:04 2020Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> restore controlfile from '/home/oracle/backup/full_PROD1_3iul3nb5_1_1.ctl';Starting restore at 04-JAN-20using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=1 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/PROD1/controlfile/control01.ctloutput file name=/u01/app/oracle/oradata/PROD1/controlfile/control02.ctloutput file name=/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlFinished restore at 04-JAN-20RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1RMAN>RMAN> run{2> set until time "to_date('2020/01/04 02:54:50','YYYY/MM/DD HH24:MI:SS')";3> restore database;4> recover database;5> }executing command: SET until clauseStarting restore at 04-JAN-20using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=1 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=161 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=10 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=160 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_38ul3na8_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00001 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_gzcw3c5f_.dbfchannel ORA_DISK_2: restoring datafile 00011 to /u01/app/oracle/oradata/PROD1/tbs02.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_36ul3na7_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_gzcw3c6b_.dbfchannel ORA_DISK_3: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_h100prcj_.dbfchannel ORA_DISK_3: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_37ul3na7_1_1.bakchannel ORA_DISK_4: starting datafile backup set restorechannel ORA_DISK_4: specifying datafile(s) to restore from backup setchannel ORA_DISK_4: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_h100pr37_.dbfchannel ORA_DISK_4: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_gzcw3c61_.dbfchannel ORA_DISK_4: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_4: reading from backup piece /home/oracle/backup/full_PROD1_39ul3na8_1_1.bakchannel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_38ul3na8_1_1.bak tag=TAG20200104T025358channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:07channel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_36ul3na7_1_1.bak tag=TAG20200104T025358channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:26channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_37ul3na7_1_1.bak tag=TAG20200104T025358channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:26channel ORA_DISK_4: piece handle=/home/oracle/backup/full_PROD1_39ul3na8_1_1.bak tag=TAG20200104T025358channel ORA_DISK_4: restored backup piece 1channel ORA_DISK_4: restore complete, elapsed time: 00:00:26Finished restore at 04-JAN-20Starting recover at 04-JAN-20using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 2 is already on disk as file /home/oracle/arch1/1_2_1027069479.dbfarchived log for thread 1 with sequence 3 is already on disk as file /home/oracle/arch1/1_3_1027069479.dbfarchived log file name=/home/oracle/arch1/1_2_1027069479.dbf thread=1 sequence=2archived log file name=/home/oracle/arch1/1_3_1027069479.dbf thread=1 sequence=3archived log file name=/home/oracle/arch1/1_4_1027069479.dbf thread=1 sequence=4media recovery complete, elapsed time: 00:00:01Finished recover at 04-JAN-20RMAN> alter database open resetlogs;database openedRMAN>[oracle@edsir4p1- arch1]$ ls -larttotal 33352-rw-r----- 1 oracle oinstall 1024 Jan 4 02:54 1_3_1027069479.dbf-rw-r----- 1 oracle oinstall 34050048 Jan 4 02:54 1_2_1027069479.dbf-rw-r----- 1 oracle oinstall 6656 Jan 4 02:55 1_4_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_5_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_8_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_7_1027069479.dbf-rw-r----- 1 oracle oinstall 1536 Jan 4 02:55 1_6_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_9_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_10_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_11_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_12_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_14_1027069479.dbf-rw-r----- 1 oracle oinstall 1024 Jan 4 02:55 1_13_1027069479.dbf

2、基于scn

SYS@PROD1> select current_scn from v$database;CURRENT_SCN-----------1499926SYS@PROD1> shutdown immediate;[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sat Jan 4 03:31:37 2020Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> restore controlfile from '/home/oracle/backup/full_PROD1_4aul3pae_1_1.ctl';Starting restore at 04-JAN-20using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/PROD1/controlfile/control01.ctloutput file name=/u01/app/oracle/oradata/PROD1/controlfile/control02.ctloutput file name=/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlFinished restore at 04-JAN-20RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1RMAN> restore database until SCN 1499880;Starting restore at 04-JAN-20Starting implicit crosscheck backup at 04-JAN-20allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKCrosschecked 34 objectsCrosschecked 50 objectsFinished implicit crosscheck backup at 04-JAN-20Starting implicit crosscheck copy at 04-JAN-20using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4Finished implicit crosscheck copy at 04-JAN-20searching for all files in the recovery areacataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985546_gz9fh3lc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985321_gz9cm9rk_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982337_gz98p1j0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026989209_gz9hdsdh_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982024_gz98d8sr_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026984092_gz9bpmmc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026987847_gz9g28b0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054861_gzchl3h1_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027066460_gzcttwrd_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027047781_gzc8m5og_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054729_gzchd9n2_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2020_01_04/o1_mf_s_1028775272_h0zzm83v_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2020_01_04/o1_mf_s_1028777296_h101ljry_.bkpusing channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_h100sw75_.dbfchannel ORA_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/PROD1/tbs02.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_3vul3p9i_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_2: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_2: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_41ul3p9i_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_h100sw8m_.dbfchannel ORA_DISK_3: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_h100swd1_.dbfchannel ORA_DISK_3: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_42ul3p9j_1_1.bakchannel ORA_DISK_4: starting datafile backup set restorechannel ORA_DISK_4: specifying datafile(s) to restore from backup setchannel ORA_DISK_4: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_h100sw7x_.dbfchannel ORA_DISK_4: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_h100sw94_.dbfchannel ORA_DISK_4: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_4: reading from backup piece /home/oracle/backup/full_PROD1_40ul3p9i_1_1.bakchannel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_41ul3p9i_1_1.bak tag=TAG20200104T032745channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:15channel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_3vul3p9i_1_1.bak tag=TAG20200104T032745channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:27channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_42ul3p9j_1_1.bak tag=TAG20200104T032745channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:27channel ORA_DISK_4: piece handle=/home/oracle/backup/full_PROD1_40ul3p9i_1_1.bak tag=TAG20200104T032745channel ORA_DISK_4: restored backup piece 1channel ORA_DISK_4: restore complete, elapsed time: 00:00:37Finished restore at 04-JAN-20RMAN> recover database until SCN 1499880;Starting recover at 04-JAN-20using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 6 is already on disk as file /home/oracle/arch1/1_6_1028776938.dbfarchived log for thread 1 with sequence 7 is already on disk as file /home/oracle/arch1/1_7_1028776938.dbfarchived log file name=/home/oracle/arch1/1_6_1028776938.dbf thread=1 sequence=6archived log file name=/home/oracle/arch1/1_7_1028776938.dbf thread=1 sequence=7archived log file name=/home/oracle/arch1/1_8_1028776938.dbf thread=1 sequence=8media recovery complete, elapsed time: 00:00:00Finished recover at 04-JAN-20RMAN> alter database open resetlogs;database openedRMAN>

3、基于sequence

[oracle@edsir4p1-PROD1 ~]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Sat Jan 4 04:06:23 2020Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> restore controlfile from '/home/oracle/backup/full_PROD1_4aul3pae_1_1.ctl';Starting restore at 04-JAN-20using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/PROD1/controlfile/control01.ctloutput file name=/u01/app/oracle/oradata/PROD1/controlfile/control02.ctloutput file name=/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlFinished restore at 04-JAN-20RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1RMAN> restore database until sequence 16 thread 1;Starting restore at 04-JAN-20Starting implicit crosscheck backup at 04-JAN-20allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=11 device type=DISKallocated channel: ORA_DISK_3channel ORA_DISK_3: SID=161 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=12 device type=DISKCrosschecked 34 objectsCrosschecked 50 objectsFinished implicit crosscheck backup at 04-JAN-20Starting implicit crosscheck copy at 04-JAN-20using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4Finished implicit crosscheck copy at 04-JAN-20searching for all files in the recovery areacataloging files...cataloging doneList of Cataloged Files=======================File Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985546_gz9fh3lc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026985321_gz9cm9rk_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982337_gz98p1j0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026989209_gz9hdsdh_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026982024_gz98d8sr_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026984092_gz9bpmmc_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_14/o1_mf_s_1026987847_gz9g28b0_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054861_gzchl3h1_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027066460_gzcttwrd_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027053303_gzcfzqjg_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027047781_gzc8m5og_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2019_12_15/o1_mf_s_1027054729_gzchd9n2_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2020_01_04/o1_mf_s_1028777834_h1023bbr_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2020_01_04/o1_mf_s_1028775272_h0zzm83v_.bkpFile Name: /u01/app/oracle/flash_recovery_area/PROD1/autobackup/2020_01_04/o1_mf_s_1028777296_h101ljry_.bkpusing channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_h100sw75_.dbfchannel ORA_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/PROD1/tbs02.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/backup/full_PROD1_3vul3p9i_1_1.bakchannel ORA_DISK_2: starting datafile backup set restorechannel ORA_DISK_2: specifying datafile(s) to restore from backup setchannel ORA_DISK_2: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/test.dbfchannel ORA_DISK_2: restoring datafile 00007 to /u01/app/oracle/oradata/PROD1/indx.dbfchannel ORA_DISK_2: restoring datafile 00009 to /u01/app/oracle/oradata/PROD1/oltp.dbfchannel ORA_DISK_2: reading from backup piece /home/oracle/backup/full_PROD1_41ul3p9i_1_1.bakchannel ORA_DISK_3: starting datafile backup set restorechannel ORA_DISK_3: specifying datafile(s) to restore from backup setchannel ORA_DISK_3: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_undotbs1_h100sw8m_.dbfchannel ORA_DISK_3: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_example_h100swd1_.dbfchannel ORA_DISK_3: restoring datafile 00010 to /u01/app/oracle/oradata/PROD1/tbs01.dbfchannel ORA_DISK_3: reading from backup piece /home/oracle/backup/full_PROD1_42ul3p9j_1_1.bakchannel ORA_DISK_4: starting datafile backup set restorechannel ORA_DISK_4: specifying datafile(s) to restore from backup setchannel ORA_DISK_4: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_sysaux_h100sw7x_.dbfchannel ORA_DISK_4: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/datafile/o1_mf_users_h100sw94_.dbfchannel ORA_DISK_4: restoring datafile 00008 to /u01/app/oracle/oradata/PROD1/tools.dbfchannel ORA_DISK_4: reading from backup piece /home/oracle/backup/full_PROD1_40ul3p9i_1_1.bakchannel ORA_DISK_2: piece handle=/home/oracle/backup/full_PROD1_41ul3p9i_1_1.bak tag=TAG20200104T032745channel ORA_DISK_2: restored backup piece 1channel ORA_DISK_2: restore complete, elapsed time: 00:00:15channel ORA_DISK_1: piece handle=/home/oracle/backup/full_PROD1_3vul3p9i_1_1.bak tag=TAG20200104T032745channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:27channel ORA_DISK_3: piece handle=/home/oracle/backup/full_PROD1_42ul3p9j_1_1.bak tag=TAG20200104T032745channel ORA_DISK_3: restored backup piece 1channel ORA_DISK_3: restore complete, elapsed time: 00:00:27channel ORA_DISK_4: piece handle=/home/oracle/backup/full_PROD1_40ul3p9i_1_1.bak tag=TAG20200104T032745channel ORA_DISK_4: restored backup piece 1channel ORA_DISK_4: restore complete, elapsed time: 00:00:27Finished restore at 04-JAN-20RMAN>recover database until sequence 16 thread 1;Starting recover at 04-JAN-20using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4starting media recoveryarchived log for thread 1 with sequence 6 is already on disk as file /home/oracle/arch1/1_6_1028776938.dbfarchived log for thread 1 with sequence 7 is already on disk as file /home/oracle/arch1/1_7_1028776938.dbfarchived log file name=/home/oracle/arch1/1_6_1028776938.dbf thread=1 sequence=6archived log file name=/home/oracle/arch1/1_7_1028776938.dbf thread=1 sequence=7archived log file name=/home/oracle/arch1/1_8_1028776938.dbf thread=1 sequence=8archived log file name=/home/oracle/arch1/1_9_1028776938.dbf thread=1 sequence=9archived log file name=/home/oracle/arch1/1_10_1028776938.dbf thread=1 sequence=10archived log file name=/home/oracle/arch1/1_11_1028776938.dbf thread=1 sequence=11archived log file name=/home/oracle/arch1/1_12_1028776938.dbf thread=1 sequence=12archived log file name=/home/oracle/arch1/1_13_1028776938.dbf thread=1 sequence=13archived log file name=/home/oracle/arch1/1_14_1028776938.dbf thread=1 sequence=14archived log file name=/home/oracle/arch1/1_15_1028776938.dbf thread=1 sequence=15media recovery complete, elapsed time: 00:00:02Finished recover at 04-JAN-20RMAN> alter database open resetlogs;database openedRMAN>

4、基于控制文件

--删除控制文件[oracle@edsir4p1- controlfile]$ rm control0*.ctl[oracle@edsir4p1- controlfile]$ rm /u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlSYS@PROD1> shutdown abortsORACLE instance shut down.SYS@PROD1> tartupORACLE instance started.Total System Global Area 636100608 bytesFixed Size 1338392 bytesVariable Size 260047848 bytesDatabase Buffers 369098752 bytesRedo Buffers 5615616 bytesORA-00205: error in identifying control file, check alert log for more info[oracle@edsir4p1-PROD1 backup]$ rman target /Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jan 6 14:08:06 2020Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (not mounted)RMAN> restore controlfile from '/home/oracle/backup/full_PROD1_6uula70u_1_1.ctl';Starting restore at 06-JAN-20using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=160 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/PROD1/controlfile/control01.ctloutput file name=/u01/app/oracle/oradata/PROD1/controlfile/control02.ctloutput file name=/u01/app/oracle/flash_recovery_area/PROD1/controlfile/control03.ctlFinished restore at 06-JAN-20RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1RMAN>SYS@PROD1> recover database using backup controlfile;ORA-00279: change 1524061 generated at 01/06/2020 13:58:51 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_7_1028987512.dbfORA-00280: change 1524061 for thread 1 is in sequence #7Specify log: {<RET>=suggested | filename | AUTO | CANCEL}autoORA-00279: change 1524106 generated at 01/06/2020 13:59:37 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_8_1028987512.dbfORA-00280: change 1524106 for thread 1 is in sequence #8ORA-00278: log file '/home/oracle/arch1/1_7_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524109 generated at 01/06/2020 13:59:38 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_9_1028987512.dbfORA-00280: change 1524109 for thread 1 is in sequence #9ORA-00278: log file '/home/oracle/arch1/1_8_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524114 generated at 01/06/2020 13:59:39 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_10_1028987512.dbfORA-00280: change 1524114 for thread 1 is in sequence #10ORA-00278: log file '/home/oracle/arch1/1_9_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524123 generated at 01/06/2020 13:59:53 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_11_1028987512.dbfORA-00280: change 1524123 for thread 1 is in sequence #11ORA-00278: log file '/home/oracle/arch1/1_10_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524126 generated at 01/06/2020 13:59:55 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_12_1028987512.dbfORA-00280: change 1524126 for thread 1 is in sequence #12ORA-00278: log file '/home/oracle/arch1/1_11_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524131 generated at 01/06/2020 13:59:58 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_13_1028987512.dbfORA-00280: change 1524131 for thread 1 is in sequence #13ORA-00278: log file '/home/oracle/arch1/1_12_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524645 generated at 01/06/2020 14:06:41 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_14_1028987512.dbfORA-00280: change 1524645 for thread 1 is in sequence #14ORA-00278: log file '/home/oracle/arch1/1_13_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524648 generated at 01/06/2020 14:06:42 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_15_1028987512.dbfORA-00280: change 1524648 for thread 1 is in sequence #15ORA-00278: log file '/home/oracle/arch1/1_14_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524653 generated at 01/06/2020 14:06:45 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_16_1028987512.dbfORA-00280: change 1524653 for thread 1 is in sequence #16ORA-00278: log file '/home/oracle/arch1/1_15_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524656 generated at 01/06/2020 14:06:46 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_17_1028987512.dbfORA-00280: change 1524656 for thread 1 is in sequence #17ORA-00278: log file '/home/oracle/arch1/1_16_1028987512.dbf' no longer needed for this recoveryORA-00279: change 1524660 generated at 01/06/2020 14:06:48 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_18_1028987512.dbfORA-00280: change 1524660 for thread 1 is in sequence #18ORA-00278: log file '/home/oracle/arch1/1_17_1028987512.dbf' no longer needed for this recoveryORA-00308: cannot open archived log '/home/oracle/arch1/1_18_1028987512.dbf'ORA-27037: unable to obtain file statusLinux Error: 2: No such file or directoryAdditional information: 3SYS@PROD1>host ls -larttotal 1272drwxrwxrwx 27 oracle oinstall 4096 Jan 6 13:45 ..-rw-r----- 1 oracle oinstall 258048 Jan 6 13:55 1_1_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 13:55 1_2_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 13:56 1_4_1028987512.dbf-rw-r----- 1 oracle oinstall 8704 Jan 6 13:56 1_3_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 13:58 1_6_1028987512.dbf-rw-r----- 1 oracle oinstall 16384 Jan 6 13:58 1_5_1028987512.dbf-rw-r----- 1 oracle oinstall 8192 Jan 6 13:59 1_7_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 13:59 1_8_1028987512.dbf-rw-r----- 1 oracle oinstall 1536 Jan 6 13:59 1_9_1028987512.dbf-rw-r----- 1 oracle oinstall 1536 Jan 6 13:59 1_10_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 13:59 1_11_1028987512.dbf-rw-r----- 1 oracle oinstall 1536 Jan 6 13:59 1_12_1028987512.dbf-rw-r----- 1 oracle oinstall 619520 Jan 6 14:06 1_13_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 14:06 1_14_1028987512.dbf-rw-r----- 1 oracle oinstall 3072 Jan 6 14:06 1_15_1028987512.dbf-rw-r----- 1 oracle oinstall 312320 Jan 6 14:11 1_18_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 14:11 1_17_1028987512.dbf-rw-r----- 1 oracle oinstall 1024 Jan 6 14:11 1_16_1028987512.dbfdrwxr-xr-x 2 oracle oinstall 4096 Jan 6 14:11 .SYS@PROD1> alter database open resetlogs;alter database open resetlogs*ERROR at line 1:ORA-01113: file 1 needs media recoveryORA-01110: data file 1: '/u01/app/oracle/oradata/PROD1/datafile/o1_mf_system_h16cz62l_.dbf'SYS@PROD1> recover database using backup controlfile;ORA-00279: change 1524660 generated at 01/06/2020 14:06:48 needed for thread 1ORA-00289: suggestion : /home/oracle/arch1/1_18_1028987512.dbfORA-00280: change 1524660 for thread 1 is in sequence #18Specify log: {<RET>=suggested | filename | AUTO | CANCEL}/u01/app/oracle/oradata/PROD1/onlinelog/o1_mf_3_gzcw6t13_.logLog applied.Media recovery complete.SYS@PROD1> alter database open resetlogs;Database altered.SYS@PROD1>

十二、闪回恢复数据库

闪回数据库是Oracle10g以后引入的一个还原数据库的一个新特性,该特性在11g中得到完善,但实际生产中此种方式并不常用, 在闪回之后Oracle数据库或者某个表空间或者表会回到指定的时间点或者scn,同样会丢失这期间的所有数据,在生产中这种不可逆的方式是不被允许的。虽然Oracle推荐使用闪回区并给定大于数据库数据量大小的空间但实际上闪回区一般情况下是关闭的或者给定的特别小,闪回技术使用最多的也仅限于闪回查询(受限于undo retention的时间)。

开启闪回区:

alter system set db_recovery_file_dest='+fra' scope=both sid='*';

1、闪回数据库

还原至scn:

flashback database to scn  991824;

创建普通还原点:

CREATE RESTORE POINT test_POINT;

FLASHBACK DATABASE TO RESTORE point test_POINT;

还原至时间点:

FLASHBACK DATABASE TO TIMESTAMP(TO_DATE('2018-01-17 08:26:00', 'YYYY-MM-DD HH24:MI:SS'));

for 12c

2、闪回表

flashback  table  ORIGINAL_SALARY  to timestamp to_date('2016-07-12 02:17:33', 'yyyy-mm-dd hh24:mi:ss');

flashback table  ORIGINAL_SALARY  to scn  991824;

FLASHBACK table  ORIGINAL_SALARY TO RESTORE point test_POINT;

3、闪回查询

select /*+ parallel(a 10)*/ * from test.tab_1 as of timestamp to_timestamp('2019-05-09 13:53:59.116842','YYYY-MM-DD HH24:MI:SSxFF');

select /*+ parallel(a 10)*/ * from test.tab_1 as of scn 432535432;

Oracle恢复手册相关推荐

  1. NBU对Oracle备份及恢复手册

    NBU对Oracle备份及恢复手册 本文档基于Redhat6.4操作系统,Oracle 10.2,NBU7.5版本,详细记录了笔者试验的全过程 详细解读 和小伙伴们一起来吐槽

  2. Oracle恢复一例--ORA-03113、ORA-24324,ORA-01041错误

    Oracle恢复一例--ORA-03113ORA-24324,ORA-01041错误 背景: 今天晚上上完OCM的课程后,有个OCP和高可用学员求助于麦老师.他的库是Windows 10.2.0.1的 ...

  3. Oracle使用手册(二)---流程控制

    Oracle使用手册(二)---流程控制 --流程控制 --1. if..then..end if  set serveroutput on  declare  i integer:=60; j in ...

  4. Oracle安装手册

    Oracle安装手册 整理:罗代均 luodaijun@vip.163.com 目录 1.Linux常用命令 2 2.安装Oracle 10gR2 3 3.Oracle中文支持问题 5 4.Oracl ...

  5. Dave Oracle 学习 手册 第一版 下载 说明

    2011年初的时候,花了大半个月的时间,把以前Blog上的资料重新分门别类的小整理了一下,当时还想整理的完整一点,可整理文档是一件很费时间的事,因为做技术要严谨,自己的一些小失误,或者错误的理解,同样 ...

  6. oracle内部原理结构图,Oracle恢复内部原理(基础数据结构)

    Oracle基础数据结构 系列文章:Oracle恢复内部原理 http://www.linuxidc.com/search.aspx?where=nkeykeyword=19824 2.1 控制文 O ...

  7. 重装oracle接管磁盘阵列,ibm v7000磁盘阵列oracle恢复

    ibm v7000磁盘阵列oracle恢复 浏览量: 0 次  来源:未知  发布日期:2019-11-19 23:07:18 南京某单位使用ibm v7000 运行oracle数据库,操作系统为So ...

  8. oracle恢复delete删除的数据

    工作学习中,难免会有失误的时候,特别是操作数据库,一不小心就给误删了.这里提供一种oracle恢复delete删除的数据的方法,利用闪回功能,恢复数据到删除时间点之前的状态. 1.开启行移动功能. a ...

  9. 赤兔oracle恢复软件 收费,赤兔Oracle恢复软件

    赤兔Oracle恢复软件可以有效地进行Oracle恢复数据,支持ASM,能够直接从ASM磁盘中导出数据,即使相关的磁盘组不能成功mount支持从ASM中直接抽取出数据文件和其他任意存储在ASM中的文件 ...

最新文章

  1. 常州大学 计算机与人工智能学院,第一届计算机视觉青年学者论坛(CVYSF)在常州大学举办...
  2. java.lang包—类Class应用之Java反射机制是什么,为什么,怎么用。
  3. 科普 | 微服务和软件技术栈
  4. 今天学习jquery 希望开个好头
  5. 休息一下,或者:如何使用Java 12制作出色的拼图游戏
  6. 目标检测——初始学习率设置的学习笔记
  7. Shell脚本编程之(三)执行方式差异(source, sh script, ./script)
  8. translclude
  9. linux 操作系统级别监控 free命令
  10. 怎样控制小程序tabbar图标大小_微信小程序tabBar的基本设置-微信小程序tabbar字体大小-微信小程序tabbar高度...
  11. 对话洪小文:微软为什么能够持续保持竞争力和创新力?
  12. 国内物联网平台初探(八):中移物联网开放平台OneNet
  13. 节日网页HTML代码 学生网页课程设计期末作业下载 清明节大学生网页设计制作成品下载 DW节日网页作业代码下载
  14. android迷宫图像生成,Android - 绘制一个迷宫,以平滑的角色移动的画布
  15. 用cocos实现的《我的世界》已经上线微信小游戏,分享一下主要技术
  16. 【Linux开发】Orange Pi上WiringPi的使用
  17. 160个CrackMe-第四个“ajj与黑头兄!”
  18. VC程序中Windows XP风格程序界面的实现
  19. JAVA语言规范 JAVA SE 8 - 类型、值和变量
  20. 微信小程序破解版环境搭建

热门文章

  1. swift之网络下载图片sdwebImage、Kingfisher、Nuke
  2. excel表格行列显示十字定位_Excel中十字交叉高亮显示的几种方法,再不会看错行了...
  3. 下载微信头像到本地服务器
  4. VIOSLAM 综述
  5. MPEG-2 最后一个美国专利已于2018 年 2月过期
  6. GPT 分区如何调整为 MBR 分区?
  7. 安装haroopad
  8. 电脑触摸板失灵怎么办(如何启动/禁用触摸板)
  9. Android Clean 架构
  10. 【jumpserver升级】docker pulling image报错dial tcp 104.18.124.25:443: i/o timeout