(一)Determining the DBID of the Database
在使用autobackup恢复SPFILE及controlfile时需要指定DBID
In situations requiring the recovery of your server parameter file or control file from autobackup, you must know the DBID.
DBID记录在控制文件中,一定要把数据库的DBID记在小本本上,否则数据库无法mount时是看不到DBID的
Be sure to record the DBID along with other basic information about your database. If you do not have a record of the DBID of your database, then you can find it in the following places without opening your database:
DBID会在RMAN连接时显示或是通过SQL查询select dbid from v$database;也会记录在alert.log及各种trc等日志;另外控制文件的自动备份名中包含DBID
The piece name of the autobackup must use the %F substitution variable, so the autobackup piece name includes the string c-IIIIIIIIII-YYYYMMDD-QQ, where IIIIIIIIII stands for the DBID, YYYYMMDD is a time stamp in the Gregorian calendar of the day the backup is generated, and QQ is the sequence in hexadecimal.
(二)Identifying the Database Files to Restore or Recover
2.1 Identifying a Lost Control File
如果控制文件复本可用则直接复制即可不需要RESTORE
Loss of some but not all copies of your control file does not require you to restore a control file from backup. If at least one control file remains intact, then you can either copy an intact copy of the control file over the damaged or missing control file, or update the initialization parameter file so that it does not refer to the damaged or missing control file. After the CONTROL_FILES parameter references only present, intact copies of the control file, you can restart your database.
使用备份的控制文件恢复需要OPEN RESETLOGS
If you restore the control file from backup, then you must perform media recovery of the whole database and then open it with the OPEN RESETLOGS option, even if no data files must be restored.
2.2 Identifying Data Files Requiring Media Recovery
确定哪些数据文件缺失最简单的办法是执行VALIDATE DATABASE,但也可通过SQL查询
- 通过VALIDATE DATABASE查看文件缺失,之后通过REPORT SCHEMA查看相应文件位置
RMAN> VALIDATE DATABASE;
RMAN> REPORT SCHEMA;
- 通过以下SQL查询数据文件缺失,较VALIDATE缺点是不会检查是否有坏块
SELECT FILE#, STATUS, ERROR, RECOVER, TABLESPACE_NAME, NAME
FROM V$DATAFILE_HEADER
WHERE RECOVER = 'YES' OR (RECOVER IS NULL AND ERROR IS NOT NULL);
Note: RECOVER indicates whether a file needs media recovery, and ERROR indicates whether there was an error reading and validating the data file header.
If ERROR is not NULL, then the data file header cannot be read and validated. Check for a temporary hardware or operating system problem causing the error. If there is no such problem, then you must restore the file or switch to a copy.
If the ERROR column is NULL and the RECOVER column is YES, then the file requires media recovery (and may also require a restore from backup).
Because V$DATAFILE_HEADER only reads the header block of each data file, it does not detect all problems that require the data file to be restored. For example, this view cannot tell whether a data file contains corrupt data blocks.
还可以通过V$RECOVER_FILE来查询
Optionally, query V$RECOVER_FILE to list data files requiring recovery by data file number with their status and error information. For example, execute the following query:
SELECT FILE#, ERROR, ONLINE_STATUS, CHANGE#, TIME FROM V$RECOVER_FILE;
You cannot use V$RECOVER_FILE with a control file restored from backup or a control file that was re-created after the time of the media failure affecting the data files. A restored or re-created control file does not contain the information needed to update V$RECOVER_FILE accurately.
To find data file and tablespace names, you can also perform joins using the data file number and the V$DATAFILE and V$TABLESPACE views, as shown in the following example.
SELECT r.FILE# AS df#, d.NAME AS df_name, t.NAME AS tbsp_name,
d.STATUS, r.ERROR, r.CHANGE#, r.TIME
FROM V$RECOVER_FILE r, V$DATAFILE d, V$TABLESPACE t
WHERE t.TS# = d.TS#
AND d.FILE# = r.FILE#;
The ERROR column identifies the problem for each file requiring recovery.
(三)Restoring Archived Redo Logs Needed for Recovery
RMAN在执行recover时自动restore相关归档
RMAN restores archived redo log files from backup automatically as needed to perform recovery.
By default, RMAN restores archived redo logs with names constructed using the LOG_ARCHIVE_FORMAT and the highest LOG_ARCHIVE_DEST_n parameters of the target database. These parameters are combined in a platform-specific fashion to form the name of the restored archived log.
如果归档还原到闪回恢复区,在应用后自己删除;反之需要手动删除
If RMAN restores archived redo logs to the fast recovery area during a recovery, then it automatically deletes the restored logs after applying them to the data files. Otherwise, you can use the DELETE ARCHIVELOG command to delete restored archived redo logs from disk when they are no longer needed for recovery:
RECOVER DATABASE DELETE ARCHIVELOG;
Restoring Archived Redo Logs to a New Location
使用SET ARCHIVELOG DESTINATION指定自动还原归档日志位置
You can override the default location for restored archived redo logs with the SET ARCHIVELOG DESTINATION command. During recovery, RMAN knows where to find the newly restored archived logs; it does not require them to be in the location specified in the initialization parameter file.
RUN
{ SET ARCHIVELOG DESTINATION TO '/oracle/temp_restore';
RESTORE DATABASE;
RECOVER DATABASE; # restores and recovers logs automatically}
This example restores 300 archived redo logs from backup, distributing them across the directories /fs1/tmp, /fs2/tmp, and /fs3/tmp:
RUN
{ SET ARCHIVELOG DESTINATION TO '/fs1/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 1 UNTIL SEQUENCE 100;
SET ARCHIVELOG DESTINATION TO '/fs2/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 101 UNTIL SEQUENCE 200;
SET ARCHIVELOG DESTINATION TO '/fs3/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 201 UNTIL SEQUENCE 300;
... }
(四)Previewing Backups Used in Restore Operations预览还原需要的备份
可以在任何RESOTRE操作加PREVIEW来查看使用到的备份以及RESTORE后恢复的起始SCN
You can apply RESTORE ... PREVIEW to any RESTORE operation to create a detailed list of every backup to be used in the requested RESTORE operation, and the necessary target SCN for recovery after the RESTORE operation is complete.
This command accesses the RMAN repository to query the backup metadata, but does not actually read the backup files to ensure that they can be restored.
RESTORE.. PREVIEW不会对备份进行校验,可能替代使用RESOTERE .. VALIDATE HEADER,它不仅可以显示还原需要的备份还会对备份文件头进行校验
As an alternative to RESTORE ... PREVIEW, you can use the RESTORE ... VALIDATE HEADER command. In addition to listing the files needed for restore and recovery, the RESTORE ... VALIDATE HEADER command validates the backup file headers to determine whether the files on disk or in the media management catalog correspond to the metadata in the RMAN repository.
通过这两个命令可以查看所需要备份是否可用以及在不想用某个备份时用CHANGE命令改变备份状态以避免使用
When planning your restore and recovery operation, use RESTORE ... PREVIEW or RESTORE ... VALIDATE HEADER to ensure that all required backups are available or to identify situations in which you may want to direct RMAN to use or avoid specific backups. If needed, use the CHANGE command to set the backup status of any temporarily unavailable backups to UNAVAILABLE.
RESTORE DATABASE PREVIEW;
RESTORE ARCHIVELOG FROM TIME 'SYSDATE-7' PREVIEW;
RESTORE DATABASE PREVIEW SUMMARY;
(五)Validating Backups Before Restoring Them
PRIVIEW并不核查备份到底是否可用,可以使用RMAN进行VALIDATE测试
- RESTORE ... VALIDATE tests whether RMAN can restore a specific object from a backup. RMAN chooses which backups to use.
- VALIDATE BACKUPSET tests the validity of a backup set that you specify.