标签:rman 控制文件丢失
首先我们进行一次全库备份
RMAN> run { backup database format ‘/backup/full_%d_%T_%s‘ plus archivelog format ‘/backup/arch_%d_%T_%s‘ delete all input; } Starting backup at 2015/07/09 09:35:03 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=28 RECID=27 STAMP=884590414 channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:35:03 channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:35:04 piece handle=/backup/arch_DEVDB_20150709_115 tag=TAG20150709T093503 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) archived log file name=/backup/archivelog/1_28_884357806.dbf RECID=27 STAMP=884590414 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=1 RECID=28 STAMP=884597703 channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:35:05 channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:35:06 piece handle=/backup/arch_DEVDB_20150709_116 tag=TAG20150709T093503 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) archived log file name=/backup/archivelog/1_1_884591314.dbf RECID=28 STAMP=884597703 Finished backup at 2015/07/09 09:35:06 Starting backup at 2015/07/09 09:35:06 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/app/oracle/oradata/devdb/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/devdb/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/devdb/users01.dbf input datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbf channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:35:06 channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:36:41 piece handle=/backup/full_DEVDB_20150709_117 tag=TAG20150709T093506 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:36:42 channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:36:43 piece handle=/backup/full_DEVDB_20150709_118 tag=TAG20150709T093506 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2015/07/09 09:36:43 Starting backup at 2015/07/09 09:36:43 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=2 RECID=29 STAMP=884597804 channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:36:44 channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:36:45 piece handle=/backup/arch_DEVDB_20150709_119 tag=TAG20150709T093644 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) archived log file name=/backup/archivelog/1_2_884591314.dbf RECID=29 STAMP=884597804 Finished backup at 2015/07/09 09:36:45 RMAN>
2.对数据库中的表进行数据修改。
SQL> conn scott/tiger Connected. SQL> select count(*) from emp_new; COUNT(*) ---------- 229376 SQL> delete from emp_new where deptno=10; 49152 rows deleted. SQL> commit; Commit complete. SQL> select count(*) from emp_new; COUNT(*) ---------- 180224
3. 将数据库关闭。
SQL> conn / as sysdba Connected. SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL>
4. 删除控制文件
SQL> ! rm /u01/app/oracle/oradata/devdb/control01.ctl SQL> ! rm /u01/app/oracle/fast_recovery_area/devdb/control02.ctl
5. 使用rman恢复控制文件
RMAN> restore controlfile from ‘//backup/full_DEVDB_20150709_118‘; Starting restore at 2015/07/09 09:46:41 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 output file name=/u01/app/oracle/oradata/devdb/control01.ctl output file name=/u01/app/oracle/fast_recovery_area/devdb/control02.ctl Finished restore at 2015/07/09 09:46:43 RMAN>
6. 将数据库启动到mount状态
RMAN> alter database mount; database mounted released channel: ORA_DISK_1
7.还原并恢复数据库
RMAN> restore database; Starting restore at 2015/07/09 09:48:56 Starting implicit crosscheck backup at 2015/07/09 09:48:56 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=21 device type=DISK Crosschecked 3 objects Finished implicit crosscheck backup at 2015/07/09 09:48:56 Starting implicit crosscheck copy at 2015/07/09 09:48:56 using channel ORA_DISK_1 Finished implicit crosscheck copy at 2015/07/09 09:48:56 searching for all files in the recovery area cataloging files... no files cataloged using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/devdb/system01.dbf channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/devdb/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/devdb/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/devdb/users01.dbf channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/devdb/example01.dbf channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/devdb/idx01.dbf channel ORA_DISK_1: reading from backup piece /backup/full_DEVDB_20150709_117 channel ORA_DISK_1: piece handle=/backup/full_DEVDB_20150709_117 tag=TAG20150709T093506 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:01:15 Finished restore at 2015/07/09 09:50:12 RMAN> recover database; Starting recover at 2015/07/09 09:51:57 using channel ORA_DISK_1 datafile 6 not processed because file is read-only starting media recovery archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/oradata/devdb/redo02.log archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/oradata/devdb/redo03.log archived log file name=/u01/app/oracle/oradata/devdb/redo02.log thread=1 sequence=2 archived log file name=/u01/app/oracle/oradata/devdb/redo03.log thread=1 sequence=3 Oracle Error: ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below ORA-01190: control file or data file 6 is from before the last RESETLOGS ORA-01110: data file 6: ‘/u01/app/oracle/oradata/devdb/idx01.dbf‘ media recovery complete, elapsed time: 00:00:04 Finished recover at 2015/07/09 09:52:02
我们可以看到,恢复完成了。但是根据日志可以看出,resetlogs打开数据库时会报错的。
我们尝试打开看看
RMAN> alter database open resetlogs; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 07/09/2015 09:53:21 ORA-01190: control file or data file 6 is from before the last RESETLOGS ORA-01110: data file 6: ‘/u01/app/oracle/oradata/devdb/idx01.dbf‘
恢复数据库时,有这么一段信息
datafile 6 not processed because file is read-only
原因找打了,在做数据库备份时,datafile 6是只读的。我们备份完毕后,修改表emp_new中的数据时,将datafile 6改成了读写模式。在做恢复时,并没有去恢复datafile 6. 导致数据文件最终不一致。
所以可以得出结论一旦有表空间由只读变成读写模式后,一定要做一次全量备份
我们将datafile 6 offline。再次打开数据库。
SQL> alter database datafile 6 offline; Database altered. RMAN> alter database open resetlogs; database opened RMAN>
虽说我们是使用resetlogs打开的数据库,但是再做数据库恢复时,也应用了在线日志。那么数据就应该没有丢失。我们做一个检验
SQL> conn scott/tiger Connected. SQL> select count(*) from emp_new; COUNT(*) ---------- 180224 SQL>
但是我们仔细的想一想,其实是有问题的。我丢失的只是控制文件,不应该真的去恢复我的数据库。如果是手工管理的备份恢复,只需执行如下语句即可完成恢复
SQL> recover database using backup controlfile;
恢复的速度会快很多。为啥RMAN没有提供类似功能呢?
本文出自 “叮咚” 博客,请务必保留此出处http://lqding.blog.51cto.com/9123978/1680701
Oracle 学习之RMAN(十二)恢复实战--控制文件丢失
标签:rman 控制文件丢失
原文地址:http://lqding.blog.51cto.com/9123978/1680701