1查看那个文件需要恢复
SELECT FILE#, ERROR, ONLINE_STATUS, CHANGE#, TIME FROM V$RECOVER_FILE;2
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# ;
要是想要完全的恢复而不是基于时间点的恢复,那么可以只恢复需要recovery的数据文件。
恢复数据文件
Determine which datafiles to recover by using the techniques described in "Determining Which Datafiles Require Recovery".
If the database is open, then take the tablespaces containing the inaccessible datafiles offline. For example, enter:
ALTER TABLESPACE users OFFLINE IMMEDIATE;Copy backups of the damaged datafiles to their default location using operating system commands. For example, to restore
users01.dbf
you might issue:% cp /disk2/backup/users01.dbf $ORACLE_HOME/oradata/trgt/users01.dbfRecover the affected tablespace. For example, enter:
RECOVER TABLESPACE usersBring the recovered tablespace online. For example, enter:
ALTER TABLESPACE users ONLINE;
恢复归档日志
To determine which archived redo log files are needed, query
V$ARCHIVED_LOG
andV$RECOVERY_LOG
.V$ARCHIVED_LOG
lists filenames for all archived logs.V$RECOVERY_LOG
lists only the archived redo logs that the database needs to perform media recovery. It also includes the probable names of the files, usingLOG_ARCHIVE_FORMAT
.
Note:
V$RECOVERY_LOG
is only populated when media recovery is required for a datafile. Hence, this view is not useful in the case of a planned recovery, such as recovery from a user error.If a datafile requires recovery, but no backup of the datafile exists, then you need all redo generated starting from the time when the datafile was added to the database.
If space is available, then restore the required archived redo log files to the location specified by
LOG_ARCHIVE_DEST_1
. The database locates the correct log automatically when required during media recovery. For example, enter:% cp /disk2/arch/* $ORACLE_HOME/oradata/trgt/archIf sufficient space is not available at the location indicated by the archiving destination initialization parameter, restore some or all of the required archived redo log files to an alternate location. Specify the location before or during media recovery using the
LOGSOURCE
parameter of theSET
statement in SQL*Plus or theRECOVER
...
FROM
parameter of theALTER
DATABASE
statement in SQL. For example, enter:SET LOGSOURCE /tmp # set location using SET statement DATABASE RECOVER FROM '/tmp'; # set location in RECOVER statementAfter an archived log is applied, and after making sure that a copy of each archived log group still exists in offline storage, delete the restored copy of the archived redo log file to free disk space. For example:
% rm /tmp/*.dbf
控制文件丢失,重建控制文件的情况
Table 18-1 Scenarios When Control Files Are Lost
Status of Online Logs | Status of Datafiles | Restore Procedure |
---|---|---|
Available | Current | If the online logs contain redo necessary for recovery, then restore a backup control file and apply the logs during recovery. You must specify the filename of the online logs containing the changes in order to open the database. After recovery, open RESETLOGS . |
Unavailable | Current | If the online logs contain redo necessary for recovery, then re-create the control file. Because the online redo logs are inaccessible, open RESETLOGS (when the online logs are accessible it is not necessary to OPEN RESETLOGS after recovery with a created control file). |
Available | Backup | Restore a backup control file, perform complete recovery, and then open RESETLOGS . |
Unavailable | Backup | Restore a backup control file, perform incomplete recovery, and then open RESETLOGS . |
在恢复的时候自动应用日志方法
1在使用recover命令之前,使用set autorecovery on
2在recover命令中使用automatic选项。
覆盖归档日志文件位置
In some cases, you may want to override the current setting for the archiving destination parameter as a source for redo log files.
To recover archived logs in a nondefault location with SET LOGSOURCE:
Using an operating system utility, copy the archived redo logs to an alternative location. For example, enter:
% cp $ORACLE_HOME/oradata/trgt/arch/* /tmpSpecify the alternative location within SQL*Plus for the recovery operation. Use the
LOGSOURCE
parameter of theSET
statement or theRECOVER
...
FROM
clause of theALTER
DATABASE
statement. For example, start SQL*Plus and run:SET LOGSOURCE "/tmp"Recover the offline tablespace. For example, to recover the offline tablespace
users
do the following:RECOVER AUTOMATIC TABLESPACE usersAlternatively, you can avoid running
SET
LOGSOURCE
and simply run:RECOVER AUTOMATIC TABLESPACE users FROM "/tmp"