Recover_Database


首先,recover是sqlplus命令

RECOVER

Syntax

RECOVER {general | managed | BEGIN BACKUP | END BACKUP}

where the general clause has the following syntax:

[AUTOMATIC] [FROM location]{ {full_database_recovery | partial_database_recovery | LOGFILE filename}
[ {TEST | ALLOW integer CORRUPTION | parallel_clause } [TEST | ALLOW integer CORRUPTION | parallel_clause ]...]| CONTINUE [DEFAULT] | CANCEL}

where the full_database_recovery clause has the following syntax:

[STANDBY] DATABASE [ {UNTIL {CANCEL | TIME date | CHANGE integer} | USING BACKUP CONTROLFILE}
[UNTIL {CANCEL | TIME date | CHANGE integer} | USING BACKUP CONTROLFILE]...]

where the partial_database_recovery clause has the following syntax:

{TABLESPACE tablespace [, tablespace]... | DATAFILE {filename | filenumber} [, filename | filenumber]... |
STANDBY {TABLESPACE tablespace [, tablespace]... | DATAFILE {filename | filenumber} [, filename | filenumber]...}
UNTIL [CONSISTENT WITH] CONTROLFILE }

where the parallel clause has the following syntax:

{ NOPARALLEL | PARALLEL [ integer ] }


/* Terms */

AUTOMATIC

Automatically generates the name of the next archived redo log file needed to continue the recovery operation. Oracle Database uses the LOG_ARCHIVE_DEST (or LOG_ARCHIVE_DEST_ 1) and LOG_ARCHIVE_FORMAT parameters (or their defaults) to generate the target redo log filename. If the file is found, the redo contained in that file is applied. If the file is not found, SQL*Plus prompts you for a filename, displaying a generated filename as a suggestion.

If you do not specify either AUTOMATIC or LOGFILE, SQL*Plus prompts you for a filename, suggesting the generated filename. You can either accept the generated filename or replace it with a fully qualified filename. You can save time by using the LOGFILE clause to specify the filename if you know the archived filename differs from the filename Oracle Database would generate.

FROM location

Specifies the location from which the archived redo log file group is read. The value of location must be a fully specified file location. If you omit this parameter, SQL*Plus assumes the archived redo log file group is in the location specified by the initialization parameter LOG_ARCHIVE_DEST or LOG_ARCHIVE_DEST_1. Do not specify FROM if you have set a file with SET LOGSOURCE.

DATABASE

Recovers the entire database.

UNTIL CANCEL

Specifies an incomplete, cancel-based recovery. Recovery proceeds by prompting you with suggested filenames of archived redo log files, and recovery completes when you specify CANCEL instead of a filename.

/* 指定不完全恢复,恢复到你input CANCEL为止, 一个一个让你确认redo的名字,直到你敲了cancel */

UNTIL TIME

Specifies an incomplete, time-based recovery. Use single quotes, and the following format:

'YYYY-MM-DD:HH24:MI:SS'

UNTIL CHANGE

Specifies an incomplete, change-based recovery. integer is the number of the System Change Number (SCN) following the last change you wish to recover. For example, if you want to restore your database up to the transaction with an SCN of 9, you would specify UNTIL CHANGE 10.

/* 想恢复到9,要until change 10 ,recover until < 10 ... */

USING BACKUP CONTROLFILE

Specifies that a backup of the control file be used instead of the current control file.

TABLESPACE

Recovers a particular tablespace. tablespace is the name of a tablespace in the current database. You may recover up to 16 tablespaces in one statement.

DATAFILE

Recovers a particular datafile. You can specify any number of datafiles.

/*******************************************************************************************************/

Recovery 有 Media Recovery 和 Crash Recovery

Datafile media recovery is the most basic form of user-initiated data recovery. It can be used to recover from a lost or damaged current datafile, SPFILE or control file. It can also recover changes that were recorded in the redo logs but not in the datafiles for a tablespace that went offline without the OFFLINE NORMAL option. Datafile media recovery can be performed whether you use Recovery Manager or user-managed backup and recovery. (For user-managed backup and recovery, it is in fact the main option available.)

The need to restore a datafile from backup is not detected automatically. The first step in performing media recovery is to manually restore the datafile by copying it from a backup. Once a datafile has been restored from backup, however, the database does automatically detect that this datafile is out of date and must undergo media recovery.

/*  介质恢复是用户发起的 ,
 current datafile, SPFILE or control file 坏了丢了都可以适用
 redo的信息可以重新覆盖到非正常离线的文件上
 Rman和sqlplus命令,sql语句都可以支持
 
 不会自动帮你找备份的文件
 首先你必须自己从备份cp一个回来
 然后就能自动检测需不需要介质恢复
*/
Several situations force you to perform media recovery:

You restore a backup of a datafile.

You restore a backup control file (even if all datafiles are current).

A datafile is taken offline (either by you or automatically by the database) without the OFFLINE NORMAL option.

For a datafile to be available for media recovery, one of two things must be true:

The database that the datafile belongs to must not be open;

or

The specific datafile needing recovery must be offline, if the database is open.

A datafile that needs media recovery cannot be brought online until media recovery has been completed. A database cannot be opened if any of the online datafiles needs media recovery.

/*  以下情况,迫使你要执行介质恢复:
  旧的备份覆盖了当前文件
  一个文件被不正常的离线了
 想做介质恢复,必须:
  数据库没有打开  或者
  数据库是打开的, 文件是离线的
*/
The crash recovery process is a special form of recovery, which happens the first time an Oracle database instance
is started after a crash (or SHUTDOWN ABORT). In crash recovery, the goal is to bring the datafiles to a
transaction-consistent state, preserving all committed changes up to the point when the instance failed.

/*  崩溃恢复是一种特殊形式的恢复
 在实例崩了之后的第一次打开库的时候被发起
 目标是把数据库拉到一个事务级别一致性的状态
 保证崩了之前的所有提交都有效
*/

However, there are a number of important differences between the two:

Media recovery must be explicitly invoked by a user. The database will not run media recovery on its own.

Media recovery applies needed changes to datafiles that have been restored from backup, not to online datafiles left over after a crash.

Media recovery must use archived logs as well as the online logs, to find changes reaching back to the time of the datafile backup.

/*  虽然都是为了保证数据完整性,两者的区别还是很多的
 
 介质恢复必须显式的由用户发起 ,不会自动运行介质恢复
 介质恢复只是负责把旧的补齐成和当前差不多,如果坏了之前还是crash的,不管崩了那一下的损失
 崩溃恢复用online redo, 介质恢复除了用online redo还要用archived logs
 ( 非归档模式是可以做介质恢复的,但是窗口很小,
   归档模式也是要用online redo的,而且当一个seq#既有redo又有archive的时候,会优先redo)
 crash recovery 永远不会使用archived logs
*/

 

 

/* ARCHIVELOG 模式下的完全恢复 */

 假定数据库故障没有损害当前每个联机重做日志组中的所有成员和未备份的任何归
档的重做日志,那么我们可以在ARCHIVELOG 模式下恢复故障点的数据库备份。如果
丢失了归档的重做日志或联机重做日志,就需要执行某些形式的时间点恢复,后面将讨
论时间点恢复问题。此外,如果丢失了当前控制文件的所有副本,就需要恢复控制文件
并执行不完全恢复。

 执行下面的步骤可以在ARCHIVELOG 模式下从数据库的一个备份中执行数据库的
完全恢复:

 (1)  从备份中还原所有数据库数据文件。
 (2)  还原所有备份的归档的重做日志。
 (3)  加载数据库(使用startup mount 命令)。
 (4)  恢复数据库(使用recover database 命令)。
 (5) Oracle 提示您应用归档的重做日志中的重做。在提示符下只需要简单地输入
AUTO ,Oracle 会自动应用所有重做日志。
 (6)  一旦应用了所有重做日志,就可以打开恢复的数据库( 使用alter database open
命令) 。

/* ARCHIVELOG 模式下的表空间恢复和数据文件恢复 */

 在数据库加载或数据库打开时可以执行表空间恢复和数据文件恢复。按照下面的步
骤可以在Oracle 数据库打开时执行一个表空间恢复:

 (1)  使表空间脱机(使用alter tablespace offline命令)。
 (2)  还原与要恢复的表空间相关联的所有数据文件。
 (3)  联机恢复表空间(使用recover tablespace 命令)。
 (4)  一旦完成了恢复,使表空间联机(使用alter tablespace online 命令)。

 正如可以恢复表空间一样,还可以恢复指定的数据文件。这样做的优点是可以保持
表空间联机。在恢复进程期间仅仅是驻留在脱机数据文件中的数据不可用,数据库的其
他部分在恢复期间都是可用的。数据文件恢复的基本步骤为:

 (1)  使数据文件脱机(使用alter database datafile 'file_name ' offline 命令)。
 (2)  还原所有要恢复的数据文件。
 (3)  联机恢复表空间(使用recover datafile 命令)。
 (4)  一旦完成了恢复,就使数据文件联机(使用alter database datafile 'file_name' online
命令)。

/* ARCHIVELOG 模式下的时间点恢复 */

 ARCHIVELOG 模式的另一个优点是可以将数据库恢复到指定时间点,而不是恢复
到发生故障时的状态。在创建克隆数据库时(可能出于测试和报告的原因而创建克隆数据
库),或者在主要的应用程序错误和用户错误情况中,经常会用到上述功能。我们既可以
将数据库恢复到指定时间点,也可以恢复到指定数据库SCN 的状态。

 如果要恢复某个时间点的表空间,则需要恢复相同时间点的整个数据库(除非执行表
空间的时间点恢复,这是另一种恢复方式)。例如,假设您有一个账户管理数据库,大部
分数据位于ACCT 表空间中,并且您打算恢复两天前的数据库。因为其余的表空间(例如
SYSTEM 、TEMP 和RBS 表空间)仍然与当前时间点一致,所以您不能只是还原ACCT
表空间并将其恢复到两天前的时间点,否则由于数据库的不一致,数据库将打开失败。

 执行下面的步骤可以恢复某一时间点的数据库:

 (1)  从一个备份中恢复所有数据库数据文件,这个备份在要恢复数据库的时间点之
前结束。
 (2)  使用recover database until time '01-01-2010 21:00:00'命令并且应用所需的重做日
志,恢复指定时间点的数据库。
 (3)  一旦完成恢复,就使用alter database open resetlogs 命令打开数据库。

 也可以执行下面的步骤,选择使用SCN 号恢复数据库:

 (1)  从一个备份中恢复所有数据库数据文件,这个备份在要恢复数据库的时间点之
前结束。
 (2)  使用recover database until change '221122' 命令并且应用所需的重做日志,恢复指
定系统更改号(SCN) 的数据库。
 (3)  一旦完成恢复,则打开数据库。

 进一步来说,可以应用数据库的更改并在应用指定的归档的重做日志之后手动取
消进程:

 (1)  从一个备份中恢复所有数据库数据文件,这个备份在要恢复数据库的时间点之
前结束。
 (2)  使用recover database until cancel 命令并且应用所需的重做日志,恢复指定时间
点的数据库。当应用了最后一个归档的重做日志后,可以简单地执行cancel 命令来结束
重做日志应用。
 (3)  一旦完成恢复,则打开数据库。

执行时间点恢复( 或者有关这一问题的任何恢复) 时一定要牢记数据库的一致性概
念。如果要恢复给定时间点的数据库,就必须使用在这个时间点之前结束的备份来恢复
数据库,还必须利用所有归档的重做日志(可能还需要剩余的联机重做日志)来完成恢复。

 

/***********************************************************************************/

1  recover database using backup controlfile
2  recover database until cancel
3  recover database using backup controlfile until cancel;
4  recover database until cancel using backup controlfile;

recover database的四条语句区别:

1. recover database using backup controlfile

 如果丢失当前控制文件,用冷备份的控制文件恢复的时候,用来告诉oracle,不要以controlfile中的scn作为恢复的终点;
 
2. recover database until cancel
 
如果丢失current/active redo的时候,手动指定终点。
 
3. recover database using backup controlfile until cancel;
 
 如果丢失当前controlfile并且current/active redo都丢失,会先去自动应用归档日志,可以实现最大的恢复;
 
4. recover database until cancel using backup controlfile;
 
如果丢失当前controlfile并且current/active redo都丢失,以旧的redo中的scn为恢复终点。因为没有应用归档日志,所有会丢失数据。
要理解recover database using backup controlfile,先理解 recover database,也就是说,不加using backup controlfile的情况。
在普通的recover database 或者 recover tablespace, recover datafile时, Oracle会以当前controlfile所纪录的SCN为准,利用archive log和 redo log的redo entry, 把相关的datafile 的 block恢复到“当前controlfile所纪录的SCN”
而某些情况下,Oracle需要把数据恢复到比当前controlfile所纪录的SCN还要靠后的位置(比如说,control file是backup controlfile , 或者 controlfile是根据trace create的。),这时候,就需要用using backup controlfile.   恢复就不会受“当前controlfile所记录的SCN”的限制。这时候的限制就来自于你的语句(until time , until scn),或者可用的archive log(until cancel) ...
结果如下:
如果控制文件丢失,restore备份的控制文件后,则必须使用using backup controlfile选项。而until cancel则是不完全恢复,即current/active redo丢失,或者从restore数据库后某个归档文件缺失,则终止。

结论:
1、适用于restore旧的控制文件,且归档日志和cuurrent/active redo都没有丢失情况。如果一切归档日志和在线日志完好,可以不丢失数据。类似于recover database
2、当前控制文件未丢失(不需要restore旧的控制文件),此时有归档日志或者current/active log有丢失情况下,则终止。最大可能恢复数据

可以得出结果,如果有旧的数据库备份,在归档日志和在线日志全部保存完好的情况下,使用recover database或recover database using backup controlfile。则不丢失数据
如果存在备份数据文件restore后,归档日志或者在线日志(active、current)丢失情况下,则可以恢复到丢失的前一个归档日志

until cancel就是不完全恢复
需要alter database open resetlogs
数据库打开后需要理解做一个全库备份

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28859270/viewspace-1061158/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28859270/viewspace-1061158/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值