标签:rman全库恢复
场景一、数据库机器崩溃,需要使用备份在其他机器上还原数据库。
首先假设我们做了一个全库的备份。
RMAN> backup database include current controlfile plus archivelog delete all input; Starting backup at 2015/07/09 06:47:15 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=26 RECID=25 STAMP=884584809 input archived log thread=1 sequence=27 RECID=26 STAMP=884587635 channel ORA_DISK_1: starting piece 1 at 2015/07/09 06:47:15 channel ORA_DISK_1: finished piece 1 at 2015/07/09 06:47:16 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064715_bsvb3mor_.bkp tag=TAG20150709T064715 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_26_884357806.dbf RECID=25 STAMP=884584809 archived log file name=/backup/archivelog/1_27_884357806.dbf RECID=26 STAMP=884587635 Finished backup at 2015/07/09 06:47:16 Starting backup at 2015/07/09 06:47:16 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 06:47:17 channel ORA_DISK_1: finished piece 1 at 2015/07/09 06:49:02 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp tag=TAG20150709T064716 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45 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 06:49:03 channel ORA_DISK_1: finished piece 1 at 2015/07/09 06:49:04 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T064716_bsvb6zjt_.bkp tag=TAG20150709T064716 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2015/07/09 06:49:04 Starting backup at 2015/07/09 06:49:04 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=884587744 channel ORA_DISK_1: starting piece 1 at 2015/07/09 06:49:05 channel ORA_DISK_1: finished piece 1 at 2015/07/09 06:49:06 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064904_bsvb713d_.bkp tag=TAG20150709T064904 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=884587744 Finished backup at 2015/07/09 06:49:06
2. 将数据库文件全部删除,包括数据文件、控制文件、日志文件(在线及归档)。
SELECT ‘rm -f ‘ || name FROM (SELECT name FROM v$datafile UNION ALL SELECT name FROM v$controlfile UNION ALL SELECT name FROM v$tempfile UNION ALL SELECT MEMBER FROM v$logfile UNION ALL SELECT VALUE FROM v$parameter WHERE name = ‘spfile‘);
使用sql生成的rm命令,将文件全部删除。并且将库关闭。
3.我们现在手里只有备份文件,要想使用RMAN恢复数据库,必须先把spfile和控制文件恢复出来。
RMAN> restore spfile to ‘/u01/app/oracle/product/11.2.0/db_1/dbs/spfiledevdb.ora‘ from ‘/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp‘; Starting restore at 2015/07/09 07:03:58 using target database control file instead of recovery catalog RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 07/09/2015 07:03:58 RMAN-12010: automatic channel allocation initialization failed RMAN-06403: could not obtain a fully authorized session ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux-x86_64 Error: 2: No such file or directory
实例没有启动时,是无法使用RMAN进行工作的。可是我们的spfile已经丢失了,实例启动不了。那怎么办呢?当然RMAN肯定考虑到了这种情况的发生,在没有参数文件时,使用RMAN启动实例,RMAN会帮我们启动一个临时的实例来用。
RMAN> startup nomount startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file ‘/u01/app/oracle/product/11.2.0/db_1/dbs/initdevdb.ora‘ starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global Area 158662656 bytes Fixed Size 2226456 bytes Variable Size 92276456 bytes Database Buffers 58720256 bytes Redo Buffers 5439488 bytes RMAN>
我们再次尝试恢复spfile
RMAN> restore spfile to ‘/u01/app/oracle/product/11.2.0/db_1/dbs/spfiledevdb.ora‘ from ‘/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp‘; Starting restore at 2015/07/09 07:15:57 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=17 device type=DISK channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 07/09/2015 07:15:59 ORA-19687: SPFILE not found in backup set RMAN> restore spfile to ‘/u01/app/oracle/product/11.2.0/db_1/dbs/spfiledevdb.ora‘ from ‘/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T064716_bsvb6zjt_.bkp‘; Starting restore at 2015/07/09 07:16:32 using channel ORA_DISK_1 channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T064716_bsvb6zjt_.bkp channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 2015/07/09 07:16:33
现在,我们就可以用恢复出来的spfile启动实例,然后去恢复控制文件。
RMAN> shutdown immediate Oracle instance shut down RMAN> startup nomount connected to target database (not started) Oracle instance started Total System Global Area 839282688 bytes Fixed Size 2233000 bytes Variable Size 553651544 bytes Database Buffers 281018368 bytes Redo Buffers 2379776 bytes RMAN> restore controlfile from ‘/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T064716_bsvb6zjt_.bkp‘; Starting restore at 2015/07/09 07:19:24 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:01 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 07:19:25
控制文件一旦有了,就什么都不怕了。所有的备份信息都能看到啦。
将实例mount
RMAN> alter database mount; database mounted released channel: ORA_DISK_1 RMAN> Recovery Manager complete. 11gdg-> rman target / Recovery Manager: Release 11.2.0.3.0 - Production on Thu Jul 9 07:25:56 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: DEVDB (DBID=789087786, not open) RMAN> list backup; using target database control file instead of recovery catalog List of Backup Sets =================== BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ------------------- 71 41.55M DISK 00:00:01 2015/07/09 06:47:16 BP Key: 73 Status: AVAILABLE Compressed: NO Tag: TAG20150709T064715 Piece Name: /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064715_bsvb3mor_.bkp List of Archived Logs in backup set 71 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ------------------- ---------- --------- 1 26 1236243 2015/07/08 21:00:16 1257660 2015/07/09 06:00:08 1 27 1257660 2015/07/09 06:00:08 1258926 2015/07/09 06:47:15 BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 72 Full 1.11G DISK 00:01:43 2015/07/09 06:49:00 BP Key: 74 Status: AVAILABLE Compressed: NO Tag: TAG20150709T064716 Piece Name: /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp List of Datafiles in backup set 72 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ------------------- ---- 1 Full 1258934 2015/07/09 06:47:17 /u01/app/oracle/oradata/devdb/system01.dbf 2 Full 1258934 2015/07/09 06:47:17 /u01/app/oracle/oradata/devdb/sysaux01.dbf 3 Full 1258934 2015/07/09 06:47:17 /u01/app/oracle/oradata/devdb/undotbs01.dbf 4 Full 1258934 2015/07/09 06:47:17 /u01/app/oracle/oradata/devdb/users01.dbf 5 Full 1258934 2015/07/09 06:47:17 /u01/app/oracle/oradata/devdb/example01.dbf 6 Full 1253618 2015/07/09 03:39:14 /u01/app/oracle/oradata/devdb/idx01.dbf
4. 现在我们就能还原恢复数据库啦。
RMAN> restore database; Starting restore at 2015/07/09 07:29:43 Starting implicit crosscheck backup at 2015/07/09 07:29:43 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=1 device type=DISK Crosschecked 2 objects Finished implicit crosscheck backup at 2015/07/09 07:29:44 Starting implicit crosscheck copy at 2015/07/09 07:29:44 using channel ORA_DISK_1 Finished implicit crosscheck copy at 2015/07/09 07:29:44 searching for all files in the recovery area cataloging files... cataloging done List of Cataloged Files ======================= File Name: /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064904_bsvb713d_.bkp File Name: /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T064716_bsvb6zjt_.bkp 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 /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T064716_bsvb3ob4_.bkp tag=TAG20150709T064716 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:01:25 Finished restore at 2015/07/09 07:31:10
5. 恢复数据库
RMAN> recover database; Starting recover at 2015/07/09 07:33:33 using channel ORA_DISK_1 datafile 6 not processed because file is read-only starting media recovery channel ORA_DISK_1: starting archived log restore to default destination channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=28 channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064904_bsvb713d_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064904_bsvb713d_.bkp tag=TAG20150709T064904 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 archived log file name=/backup/archivelog/1_28_884357806.dbf thread=1 sequence=28 unable to find archived log archived log thread=1 sequence=29 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 07/09/2015 07:33:36 RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 29 and starting SCN of 1258979
RMAN告诉我们找不到sequence=29的日志文件。我们查看一下备份的归档日志。
RMAN> list backup of archivelog all; List of Backup Sets =================== BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ------------------- 71 41.55M DISK 00:00:01 2015/07/09 06:47:16 BP Key: 73 Status: AVAILABLE Compressed: NO Tag: TAG20150709T064715 Piece Name: /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064715_bsvb3mor_.bkp List of Archived Logs in backup set 71 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ------------------- ---------- --------- 1 26 1236243 2015/07/08 21:00:16 1257660 2015/07/09 06:00:08 1 27 1257660 2015/07/09 06:00:08 1258926 2015/07/09 06:47:15 BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ------------------- 73 3.00K DISK 00:00:00 2015/07/09 06:49:05 BP Key: 75 Status: AVAILABLE Compressed: NO Tag: TAG20150709T064904 Piece Name: /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_annnn_TAG20150709T064904_bsvb713d_.bkp List of Archived Logs in backup set 73 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ------------------- ---------- --------- 1 28 1258926 2015/07/09 06:47:15 1258979 2015/07/09 06:49:04
我们的日志确实只备份到了sequence=28. 我们其实要实现一个不完全恢复。
RMAN> run{ 2> set until sequence 29; 3> recover database; 4> } executing command: SET until clause Starting recover at 2015/07/09 07:47:25 using channel ORA_DISK_1 datafile 6 not processed because file is read-only starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 2015/07/09 07:47:26
6.打开数据库
RMAN> alter database open resetlogs; database opened RMAN>
本文出自 “叮咚” 博客,请务必保留此出处http://lqding.blog.51cto.com/9123978/1680681
标签:rman全库恢复
原文地址:http://lqding.blog.51cto.com/9123978/1680681