Oracle® Database Backup and Recovery User's Guide 11g Release 1 (11.1) Part Number B28270-03 |
|
|
View PDF |
This chapter is intended for new users who want to start using RMAN right away without first reading the more detailed chapters in this book. This chapter provides the briefest possible digest of the most important RMAN concepts and tasks and is not a substitute for the rest of the backup and recovery documentation set.
这节是为那些想立即使用RMAN而且还没太细读本书的读者写的。这节为RMAN的一些最重要的概念和任务进行了分组,但是这并不能代替后面所讲的备份恢复的内容。
This chapter contains the following topics:
这节包括以下几个方面:
Overview of the RMAN Environment
Starting RMAN and Connecting to Database
Showing the Default RMAN Configuration
Backing Up a Database
Reporting on RMAN Operations
Maintaining RMAN Backups
Diagnosing and Repairing Failures with Data Recovery Advisor
Rewinding a Database with Flashback Database
Restoring and Recovering Database Files
Recovery Manager (RMAN) is an Oracle Database client that performs backup and recovery tasks on your databases and automates administration of your backup strategies. It greatly simplifies backing up, restoring, and recovering database files.
RMAN(Recovery Manager) 是在你的数据库上执行备份恢复的一个oracle数据库客户端。并且能自动化管理你的备份策略。它把备份、恢复和复盖数据库文件做的非常简单。
The RMAN environment consists of the utilities and databases that play a role in backing up your data. At a minimum, the environment for RMAN must include the following components:
RMAN的环境由各种工具和数据库组成,在备份数据的时候扮演了重要的角色。最少,RMAN环境必须包括以下组件:
A target database
目标数据库
An Oracle database to which RMAN is connected with the TARGET
keyword. A target database is a database on which RMAN is performing backup and recovery operations. RMAN always maintains metadata about its operations on a database in the control file of the database. The RMAN metadata is known as the RMAN repository.
这是一个RMAN用TARGET
关键字连接的数据库。目标数据库是RMAN执行备份恢复操作的对象,RMAN在数据库的控制文件中保留着它对一个数据库进行操作的原数据。RMAN的原数据就是 RMAN repository。
The RMAN client
RMAN客户端
An Oracle Database executable that interprets commands, directs server sessions to execute those commands, and records its activity in the target database control file. The RMAN executable is automatically installed with the database and is typically located in the same directory as the other database executables. For example, the RMAN client on Linux is located in $ORACLE_HOME/bin
.
oracle数据库的可执行文件负责解释命令并让服务器的session在目标数据库执行那些命令,并把执行活动记录到目标数据库的控制文件中。RMAN的可执行文件是在安装数据库的时候自动安装的,一般和其它可执行文件放在同一个文件夹中,例如在LINUX操作系统中RMAN客户端可执行文件放在$ORACLE_HOME/bin
中。
Some environments use the following optional components:
一些环境会用到下面一些可选组件:
A flash recovery area
flash recovery area
A disk location in which the database can store and manage files related to backup and recovery. You set the flash recovery area location and size with the DB_RECOVERY_FILE_DEST
and DB_RECOVERY_FILE_DEST_SIZE
initialization parameters.
这是数据库存放和管理有关备份恢复文件的一块磁盘区域。可以用DB_RECOVERY_FILE_DEST
和DB_RECOVERY_FILE_DEST_SIZE
两个初始化参数设置flash recovery area的位置和大小。
A media manager
media manager
An application required for RMAN to interface with sequential media devices such as tape libraries. A media manager controls these devices during backup and recovery, managing the loading, labeling, and unloading of media. Media management devices are sometimes called SBT (system backup to tape) devices.
有时应用需要RMAN可以和磁带这样的连续的介质设备进行互操作。media manager可以控制在备份恢复、加载到磁带和在磁带上打标签、从磁带上删除等操作。介质管理设备有时叫做SBT(system backup to tape)设备。
A recovery catalog
recovery catalog
A separate database schema used to record RMAN activity against one or more target databases. A recovery catalog preserves RMAN repository metadata if the control file is lost, making it much easier to restore and recover following the loss of the control file. The database may overwrite older records in the control file, but RMAN maintains records forever in the catalog unless deleted by the user.
This chapter explains how to use RMAN in the most basic configuration, which is without a recovery catalog or media manager.
这节主要说明在最基本的配置下如何使用RMAN,没有使用recovery catalog和media manager的情况。
See Also:
Chapter 3, "Recovery Manager Architecture" for a more detailed overview of the RMAN environmentThe RMAN client is started by issuing the rman
command at the command prompt of your operating system. After being started, RMAN displays a prompt for your commands as shown in the following example:
在操作系统的命令行执行rman
命令就可以启动RMAN客户端。启动后RMAN的命令提示行如下:
% rman RMAN>
RMAN connections to a database are specified and authenticated in the same way as SQL*Plus connections to a database. The only difference is that RMAN connections to a target or auxiliary database require the SYSDBA
privilege. The AS SYSDBA
keywords are implied and cannot be explicitly specified. See Oracle Database Administrator's Guide to learn about database connection options when using SQL*Plus.
用RMAN连接数据库及数据库认证与用SQL*Plus连接数据库一样。唯一不同的是RMAN连接到目标数据库或者辅助数据库需要SYSDBA
权限。AS SYSDBA
关键词是隐式的,不能显式写明。想知道更多的用SQL*Plus连接数据库的选项请参见Oracle Database Administrator's Guide。
Caution:
Good security practice requires that passwords should not be entered in plain text on the command line. You should enter passwords in RMAN only when requested by an RMAN prompt. See Oracle Database Security Guide to learn about password protection.小心:
要保持不在命令行把密码用明文写出这个好的习惯,应该在RMAN提示你输入密码的地方输入密码。参见 Oracle Database Security Guide了解更多关于密码保护的问题。You can connect to a database with command-line options or by using the CONNECT TARGET
command. The following example starts RMAN and then connects to a target database through Oracle Net (note that AS SYSDBA
is not specified because it is implied). RMAN prompts for a password.
可以用CONNECT TARGET
命令或者用命令行选项连接到数据库上。下面的例子是启动RMAN然后通过Oracle Net 连接到一个目标数据库上(注意因为AS SYSDBA
关键字是隐式的,所以它不需要显式指出)。
% rman
RMAN> CONNECT TARGET SYS@prod
target database Password: password
connected to target database: PROD (DBID=39525561)
The following variation starts RMAN and then connects to a target database by using operating system authentication:
下面是用操作系统认证连接数据库:
% rman RMAN> CONNECT TARGET / connected to target database: PROD (DBID=39525561)
To quit the RMAN client, enter EXIT
at the RMAN prompt:
要退出RMAN,在RMAN提示行输入EXIT
。
RMAN> EXIT
Syntax of Common RMAN Command-line Options
RMAN [ TARGET connectStringSpec | { CATALOG connectStringSpec } | LOG ['] filename ['] [ APPEND ] . . . ]... connectStringSpec::= ['] [userid] [/ [password]] [@net_service_name] [']
The following example appends the output from an RMAN session to a text file at /tmp/msglog.log
下面的例子是说,把当前操作的日志接到/tmp/msglog.log
文件后面。这个日志文件是 RMAN session生成的。
% rman TARGET / LOG /tmp/msglog.log APPEND
See Also:
Chapter 4, "Starting and Interacting with the RMAN Client" to learn more about starting and using the RMAN client参见:
关于启动和运用RMAN的客户端的更多信息参见 Chapter 4, "Starting and Interacting with the RMAN Client"。The RMAN backup and recovery environment is preconfigured for each target database. The configuration is persistent and applies to all subsequent operations on this target database, even if you exit and restart RMAN.
对每个目标数据库来说RMAN的备份恢复环境都要预先配置。在目标数据库上做的后续操作该配置都将永久有效,即使你退出或者重启RMAN。
RMAN configured settings can specify backup devices, configure a connection to a backup device (known as a channel), policies affecting backup strategy, and others. The default configuration is adequate for most purposes.
RMAN配置可以指定备份设备、配置到备份设备的连接(又叫做channel)、影响备份策略的方法等等。其实默认设置就可以应付大部分情况了。
To show the current configuration for a database:
Start RMAN and connect to a target database.
启动RMAN并且连接到目标数据库。
Run the SHOW ALL
command.
运行SHOW ALL
命令。
For example, enter the command at the RMAN prompt as follows:
例如在RMAN提示行像下面输入命令:
RMAN> SHOW ALL;
The output lists the CONFIGURE
commands to re-create this configuration.
结果列出了重新配置的CONFIGURE
命令。
See Also:
Chapter 5, "Configuring the RMAN Environment," and Chapter 6, "Configuring the RMAN Environment: Advanced Topics," to learn how to configure the RMAN environment参见:
更多配置RMAN环境的方法请参见 Chapter 5 "Configuring the RMAN Environment"和 Chapter 6 "Configuring the RMAN Environment: Advanced Topics"。Use the BACKUP
command to back up files. RMAN backs up data to the configured default device for the type of backup requested. By default, RMAN creates backups on disk. If a flash recovery area is enabled, and if you do not specify the FORMAT
parameter (see Table 2-1), then RMAN creates backups in the recovery area and automatically gives them unique names.
用BACKUP
命令备份文件。RMAN以需要的备份类型把数据备份在设置的默认设备上。默认情况下,RMAN在磁盘上创建备份。如果闪回区设置为可用,并且你又没指定FORMAT
参数(参见Table 2-1),那么RMAN在闪回区创建备份文件,并给备份起一个独一无二的名字。
By default, RMAN creates backup sets rather than image copies. A backup set consists of one or more backup pieces, which are physical files written in a format that only RMAN can access. A multiplexed backup set contains the blocks from multiple input files. RMAN can write backup sets to disk or tape.
在默认情况下,RMAN创建的是备份集而不是镜像备份。一个备份集(backup set)由一个或多个备份文件组成。这些备份文件是一个物理文件用RMAN可以访问的格式创建。一个多重备份集(multiplexed backup set)包含了多个文件的数据库块。RMAN既可以把备份集创建在磁盘上也可以创建到磁带上。
If you specify BACKUP
AS
COPY
, then RMAN copies each file as an image copy, which is a bit-for-bit copy of a database file created on disk. Image copies are identical to copies created with operating system commands like cp
on Linux or COPY
on Windows, but are recorded in the RMAN repository and so are usable by RMAN. You can use RMAN to make image copies while the database is open.
如果你指定了BACKUP
AS
COPY
,那么RMAN把每一个文件备份成镜像备份(image copy)。镜像备份是把磁盘上的数据库文件按bit位复制成备份文件。镜像备份和在操作系统上用复制命令复制文件是一样的,像Linux系统的cp命令,windows系统的copy命令,但是用镜像备份命令可以记录到RMAN的库中,使RMAN命令也可以使用这些文件。在数据库是开启的状态就可以用RMAN来创建镜像备份。
See Also:
Chapter 7, "RMAN Backup Concepts," to learn concepts relating to RMAN backups
与RMAN有关的概念参见Chapter 7, "RMAN Backup Concepts"。
Chapter 8, "Backing Up the Database," to learn how to back up database files with RMAN
想了解更多的如何用RMAN备份数据库文件参见Chapter 8, "Backing Up the Database,"。
Oracle Database Backup and Recovery Reference for BACKUP
command syntax and semantics
了解更多的BACKUP
命令的语法及意思参见Oracle Database Backup and Recovery Reference。
If a database runs in ARCHIVELOG
mode, then you can back up the database while it is open. The backup is called an inconsistent backup because redo is required during recovery to bring the database to a consistent state. As long as you have the archived redo logs needed to recover the backup, open database backups are as effective a means of data protection as consistent backups.
如果数据库运行在归档模式下,那么你可以在数据库开启的状态下备份数据库。这种备份叫做不一致备份(inconsistent backup),因为如果把数据库恢复到一致的状态需要重做日志。只要你有恢复所需的归档重做日志,开启数据库进行备份和一致性备份同样是一种有效的数据保护的方法。
To back up the database and archived redo logs while the database is open:
在数据库开启的状态下备份数据库和归档重做日志:
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Run the BACKUP DATABASE
command.
执行BACKUP DATABASE
命令。
For example, enter the following command at the RMAN prompt to back up the database and all archived redo log files to the default backup device:
例如,在RMAN提示行输入以下的命令,在默认的备份设备上备份数据库和所有的归档重做日志文件。
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
If a database runs in NOARCHIVELOG
mode, then the only valid database backup is a consistent backup. For the backup to be consistent, the database must be mounted after a consistent shutdown. No recovery is required after restoring the backup.
如果数据库运行在非归档模式下,那么一致性备份是唯一的合法的数据库备份。由于要进行一致性备份,所以数据库必须在正常情况下(数据一致)关闭,然后启动到加载(mount)状态。在进行数据库恢复的时候不需要闪回区的文件了。
To make a consistent database backup:
创建一致性备份:
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Shut down the database consistently and then mount it.
在数据库正常的情况(数据一致)下关闭,并启动到加载(mount)状态。
For example, enter the following commands to guarantee that the database is in a consistent state for a backup:
例如,输入下面的命令来保证数据库数据的一致性,然后进行备份:
RMAN> SHUTDOWN IMMEDIATE; RMAN> STARTUP FORCE DBA; RMAN> SHUTDOWN IMMEDIATE; RMAN> STARTUP MOUNT;
Run the BACKUP DATABASE
command.
执行BACKUP DATABASE
命令。
For example, enter the following command at the RMAN prompt to back up the database to the default backup device:
例如,在RMAN提示行输入下面的命令,在默认备份设备上备份数据库:
RMAN> BACKUP DATABASE;
The following variation of the command creates image copy backups of all datafiles in the database:
下面的命令创建了所有数据文件的镜像备份:
RMAN> BACKUP AS COPY DATABASE;
Open the database and resume normal operations.
开启数据库恢复正常的操作。
The following command opens the database:
用下面的命令开启数据库。
RMAN> ALTER DATABASE OPEN;
The BACKUP
command includes a host of options, parameters, and clauses that control backup output. The following table lists some typical backup options.BACKUP
命令有许多选项、参数和子句来控制备份的日志输出,下表列出一些一般性的备份选项。
Table 2-1 Common Backup Options
Option | Description | Example |
---|---|---|
|
Specifies a location and name for backup pieces and copies. You must use substitution variables to generate unique filenames. The most common substitution variable is |
BACKUP FORMAT 'AL_%d/%t/%s/%p' ARCHIVELOG LIKE '%arc_dest%'; |
|
Specifies a user-defined string as a label for the backup. If you do not specify a tag , then RMAN assigns a default tag with the date and time. Note that tags are always stored in the RMAN repository in uppercase. |
BACKUP TAG 'weekly_full_db_bkup' DATABASE MAXSETSIZE 10M; |
See Also:
"Specifying Backup Output Options"If you specify BACKUP
INCREMENTAL
, then RMAN creates an incremental backup of a database. Incremental backups capture block-level changes to a database made after a previous incremental backup. Incremental backups are generally smaller and faster to make than full database backups. Recovery with incremental backups is faster than using redo logs alone.
如果你指定了BACKUP
INCREMENTAL
,那么 RMAN会创建一个数据库的增量备份(incremental backup)。当前一次增量备份完成后,后一次的增量备份能捕获到与前一次数据块级的改变。增量备份一般比全数据库备份要快,而且生成的文件也小。从增量备份中恢复比只用重做日志要快。
The starting point for an incremental backup strategy is a level 0 incremental backup, which backs up all blocks in the database. An incremental backup at level 0 is identical in content to a full backup, but unlike a full backup the level 0 backup is considered a part of the incremental backup strategy.
0级增量备份(level 0 incremental backup)是增量备份策略的起始点。它备份数据库中所有的数据块。0级备份在内容上和数据库的全备份(full backup)是一样的,不同的是0级备份是增量备份策略的一部分。
A level 1 incremental backup contains only blocks changed after a previous incremental backup. If no level 0 backup exists in either the current or parent database incarnation when you run a level 1 backup, then RMAN makes a level 0 backup automatically.
1级备份只备份与上一次增量备份不同的数据块。如果0级备份既不在当前数据库中也不在父数据库的ncarnation中,这时,你运行1级备份的话,RMAN会自动进行0级备份。
Note:
You cannot make incremental backups when aNOARCHIVELOG
database is open, although you can make incremental backups when the database is mounted after a consistent shutdown.
注意:
在非归档模式下,不能在数据库开启的情况下进行增量备份,你可以在数据库正常停止后,再启动到mount状态进行增量备份。A level 1 backup can be a cumulative incremental backup, which includes all blocks changed since the most recent level 0 backup, or a differential incremental backup, which includes only blocks changed since the most recent incremental backup. Incremental backups are differential by default.
1级备份可以是累积型增量备份(cumulative incremental backup)——包含从0级备份以来所有的数据块的改变。也可以进行差异型增量备份(differential incremental backup)——仅包含上一次增量备份以来的所有数据块的改变。增量备份默认情况是进行差异型增量备份。
When restoring incremental backups, RMAN uses the level 0 backup as the starting point, then updates changed blocks based on level 1 backups where possible to avoid reapplying changes from redo one at a time. Recovering with incremental backups requires no additional effort on your part. If incremental backups are available, then RMAN uses them during recovery.
当从增量备份恢复的时候,RMAN用0级备份做为起始点,恢复改变的数据块依靠1级备份,这样避免了在同一时间从重做日志恢复两次。用增量备份进行数据恢复你这边不用做什么事情,如果增量备份可以用,RMAN在恢复的时候就自动用了。
To make incremental backups of the database:
创建增量备份
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Run the BACKUP INCREMENTAL
command.
执行BACKUP INCREMENTAL
命令。
The following example creates a level 0 incremental backup to serve as a base for an incremental backup strategy:
下面的例子是创建0级备份为增量备份做基础:
BACKUP INCREMENTAL LEVEL 0 DATABASE;
The following example creates a level 1 cumulative incremental backup:
下面的例子创建一个1级的累积型增量备份:
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
The following example creates a level 1 differential incremental backup:
下面的例子创建一个1级的差异型增量备份:
BACKUP INCREMENTAL LEVEL 1 DATABASE;
See Also:
"Incremental Backups" for a more detailed conceptual overview of incremental backups and "Making and Updating Incremental Backups"参见:
更多增量备份的详细的概念信息请参见"Incremental Backups"和"Making and Updating Incremental Backups"。The RMAN incrementally updated backup feature is an efficient incremental backup routine. Changes from level 1 backups roll forward an image copy level 0 incremental backup, so that it includes all changes as of the SCN at which the level 1 incremental backup was created. Recovery of the updated level 0 incremental backup is faster because all changes from the level 1 incremental backup have already been applied.
The BACKUP FOR RECOVER OF COPY
command specifies that an incremental backup should contain all changes since the SCN of a specified datafile copy (level 0 incremental backup) of your database. The following table explains which options to use with FOR RECOVER OF COPY
to implement an incrementally updated backup strategy.
每一次数据库的备份都会对应一个数据文件的SCN,BACKUP FOR RECOVER OF COPY
命令指定了增量备份包含了从某一SCN指定的数据文件中所有的改变信息。下面的表格解释了哪个选项与FOR RECOVER OF COPY
命令一起使用来实现增量升级备份策略。
Table 2-2 FOR RECOVER OF COPY Options
BACKUP Option | Description | Example |
---|---|---|
|
Use the |
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'incr_update' DATABASE; |
|
Identifies the datafile copies to use as the basis for this incremental backup. |
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY DATAFILECOPY FORMAT '/disk2/df1.cpy' DATABASE; |
To implement an incrementally updated backup strategy:
实现增量升级备份策略
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Run the RECOVER COPY
and BACKUP INCREMENTAL
commands.
执行RECOVER COPY
和BACKUP INCREMENTAL
命令。
The following script, run on a regular basis, is all that is required to implement a strategy based on incrementally updated backups.
下面的脚本是非常基本的实现了基于增量升级备份的策略。
RECOVER COPY OF DATABASE WITH TAG 'incr_update'; BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'incr_update' DATABASE;
See Also:
"Incrementally Updating Backups"You can use the VALIDATE
command to confirm that all database files exist, are in their correct location, and are free of physical corruption. The CHECK LOGICAL
option also checks for logical block corruption.
可以用VALIDATE
命令来确认数据库文件是否还存在——一方面是看它们是否在正确的路径上,另一方面是看它们是不是正常的文件。CHECK LOGICAL
命令也会检查这些文件在逻辑上是否正常。
To validate database files:
验证数据库文件:
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Run the VALIDATE
command for the desired files.
执行VALIDATE
命令验证需要的文件。
For example, enter the following commands to validate all database files and archived redo log files for physical and logical corruption:
例如,用下面的命令验证所有数据库文件和归档日志文件是否正常(物理及逻辑上)。
BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL;
You can also use the VALIDATE
command to individual data blocks, as shown in the following example:
你也可以用VALIDATE
命令针对个别的数据块,如下所示:
VALIDATE DATAFILE 4 BLOCK 10 TO 13;
You can also validate backup sets, as shown in the following example:
你也可以验证备份集,如下所示:
VALIDATE BACKUPSET 3;
You specify backup sets by primary key, which is shown in the output of the LIST BACKUP
command.
可以用主键指定备份集,这个主键可以用LIST BACKUP
命令的输入显示出来。
See Also:
Chapter 15, "Validating Database Files and Backups"RMAN supports the use of command files to manage recurring tasks such as weekly backups. A command file is a client-side text file containing RMAN commands, exactly as you enter them at the RMAN prompt. You can use any file extension.The RUN
command provides a degree of flow-of-control in your scripts.
RMAN支持用命令文件来管理重复性的任务如每周备份一次等。命令文件(command file)是客户端编辑的文本文件,RUN
命令的编辑方法就像你在RMAN提示行中输入的一样,可以用任意的文件扩展名,命令在你的脚本中提供控制流。
To create and run a command file:
创建并运行命令文件:
Use a text editor to create a command file.
用文本编辑器创建一个命令文件
For example, create a command file with the following contents:
例如,用下面的内容创建一个命令文件:
# my_command_file.txt CONNECT TARGET / BACKUP DATABASE PLUS ARCHIVELOG; LIST BACKUP; EXIT;
Start RMAN and then execute the contents of a command file by running the @
command at the RMAN prompt:
启动RMAN然后在RMAN提示行运行@
命令来执行命令文件中的内容。
% rman RMAN> @/my_dir/my_command_file.txt # runs specified command file
You can also launch RMAN with a command file to run, as shown here:
你也可以在启动RMAN的时候执行命令文件,如下:
% rman @/my_dir/my_command_file.txt
See Also:
"Using Command Files with RMAN" to learn more about command files, and "Using Substitution Variables in Command Files" to learn how to use substitution variables in command files and pass parameters at runtime参见:
1 了解更多关于命令文件的信息参见"Using Command Files with RMAN",了解如何在命令文件中使用变量替换和传递参数,参见"Using Substitution Variables in Command Files"。The RMAN LIST
and REPORT
commands generate reports on backup activities based on the RMAN repository. Use the SHOW ALL
command to display the current RMAN configuration.
RMAN的LIST
和REPORT
命令基于RMAN自己的存储库对备份活动生成记录。用SHOW ALL
命令显示当前的RMAN配置。
Run the LIST
BACKUP
and LIST
COPY
commands to display information about backups and datafile copies listed in the repository. For backups, you can control the format of LIST
output with the options in the following tables.
运行LIST
BACKUP
和LIST
COPY
命令显示出在RMAN库中列出的备份和数据文件备份的信息。对于备份来说,你可以用下表中的选项控制LIST
命令输出的格式。
Table 2-3 LIST Options for Backups
Option | Example | Explanation |
---|---|---|
|
|
Organizes the output by backup set. This is the default mode of presentation. |
|
|
Lists the backups according to which file was backed up. |
|
|
Displays summary output. By default, the output is |
For both backups and copies you have the following additional options.
对于备份和复制来说,都有以下额外的选项。
Table 2-4 Additional LIST Options
Option | Example | Explanation |
---|---|---|
|
|
Lists backups that are recorded in the RMAN repository but that were not present at the expected location on disk or tape during the last |
|
|
Lists datafile backups or copies that have status |
To list backups and copies:
列出备份和复制
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库
Run the LIST
command at the RMAN prompt.
在RMAN提示行运行LIST
命令。
You can display specific objects, as in the following examples:
如下面的例子,可以显示出指定的对象:
LIST BACKUP OF DATABASE; LIST COPY OF DATAFILE 1, 2; LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 10; LIST BACKUPSET OF DATAFILE 1;
See Also:
"Listing Backups and Recovery-Related Objects" to learn more about theLIST
command
The REPORT
command performs more complex analysis than LIST
. Some of the main options are shown in the following table.REPORT
命令比LIST
命令执行更多复杂的分析。下表是主要的一些选项。
Table 2-5 REPORT Options
Option | Example | Explanation |
---|---|---|
|
|
Shows which files need backing up under current retention policy. Use optional |
|
|
Lists backups that are obsolete under the configured backup retention policy. Use the optional |
|
|
Reports the tablespaces and datafiles in the database at the current time (default) or a different time. |
|
|
Lists all datafiles for which an unrecoverable operation has been performed against an object in the datafile since the last backup of the datafile. |
To generate reports of database files and backups:
生成数据文件及备份的报告
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Run the REPORT
command at the RMAN prompt.
在RMAN提示行执行REPORT
命令。
The following example reports backups that are obsolete according to the currently configured backup retention policy:
下面的例子列出了在当前配置的备份策略中过期的备份:
REPORT OBSOLETE;
The following example reports the datafiles and tempfiles in the database:
下面的例子是报告在此数据库中的数据文件及临时文件:
REPORT SCHEMA;
See Also:
"Reporting on Backups and Database Schema" to learn how to use theREPORT
command for RMAN reporting
RMAN repository metadata is always stored in the control file of the target database. The RMAN maintenance commands use this metadata when managing backups.
RMAN库的原数据库保存在目标数据库中的控制文件中。管理备份的时候RMAN maintenance commands会用到原数据。
The CROSSCHECK
command synchronizes the logical records of RMAN backups and copies with the files on storage media. If a backup is on disk, then CROSSCHECK
determines whether the header of the file is valid. If a backup is on tape, then RMAN queries the RMAN repository for the names and locations of the backup pieces. It is a good idea to crosscheck backups and copies before deleting them.CROSSCHECK
命令同步RMAN备份和存储介质上副本的逻辑记录。如果备份在磁盘上,那么CROSSCHECK
命令检测文件头是否合法。如果备份在磁带上那么RMAN会到RMAN库中查找备份文件的名字和存储位置。在删除备份及副本之前用crosscheck 命令检测一下是个不错的选择。
To crosscheck all backups and copies on disk:
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Run the CROSSCHECK
command, as shown in the following example:
如下例子执行CROSSCHECK
命令:
CROSSCHECK BACKUP; CROSSCHECK COPY;
See Also:
"Crosschecking the RMAN Repository" to learn how to crosscheck RMAN backupsThe DELETE
command removes RMAN backups and copies from disk and tape, updates the status of the files to DELETED
in the control file repository, and removes the records from the recovery catalog (if you use a catalog). If you run RMAN interactively, and if you do not specify the NOPROMPT
option, then DELETE
displays a list of files and prompts for confirmation before deleting any file in the list.DELETE
命令从磁盘上和磁带上删除RMAN的备份和复制、在控制文件库中把文件的状态更新为DELETED
、如果你有catalog的话也会从catalog里面把记录删掉。如果你以互动式运行RMAN并且没有指定NOPROMPT
选项,DELETE
命令显示出文件清单,并且在删除文件之前会让你确认是否删除。
The DELETE OBSOLETE
command is particular useful because RMAN deletes backups and datafile copies recorded in the RMAN repository that are obsolete, that is, no longer needed. You can use options on the DELETE
command to specify what is obsolete or use the configured backup retention policy.
命令特别有用,因为RMAN会删除记录在RMAN库中过期的备份和数据文件的复制。你可以用DELETE
命令的选项来指定哪些是过期的文件,或者用配置好的备份策略。
To delete obsolete backups and copies:
删除过期备份和复制:
Start RMAN and connect to a target database.
启动RMAN并且连接到目标数据库。
Run the DELETE OBSOLETE
command, as shown in the following example:
如下使用DELETE OBSOLETE
命令:
DELETE OBSOLETE;
See Also:
"Deleting RMAN Backups and Archived Redo Logs" to learn how to use theDELETE
command
The simplest way to diagnose and repair database problems is to use the Data Recovery Advisor. This Oracle Database tool provides an infrastructure for diagnosing persistent data failures, presenting repair options to the user, and automatically executing repairs.
最简单的方法来诊断和修复数据库的问题是用数据恢复指导(Data Recovery Advisor)。这个oracle数据库工具提供了一个诊断数据永久性故障、给用户提供修复选项和自动执行修复的一个平台。
See Also:
"Overview of Data Recovery Advisor"A failure is a persistent data corruption detected by the Health Monitor. Examples include physical and logical data block corruptions and missing datafiles. Each failure has a failure priority and failure status. The priority can be CRITICAL
, HIGH
, or LOW
. The status can be OPEN
or CLOSED
.
故障(failure)是永久的数据冲突由健康监控探测到。例如,物理和逻辑的数据块冲突及数据文件丢失。每个故障都有故障的优先级(failure priority)和故障状态(failure status)。优先级可能是CRITICAL
、HIGH
、LOW
。状态可能是OPEN
、CLOSED
。
You can run the LIST
FAILURE
command to show all known failures. If failures exist, then run the ADVISE FAILURE
command in the same session to determine manual and automated repair options. The following example illustrates these two commands (sample output included).
可以运行LIST
FAILURE
命令显示出所有的已知故障。如果故障存在,则在同一个会话中执行ADVISE FAILURE
命令,决定自动或人工修复的选项。下面的例子详细说明了这两个命令(命令的输出也给出了)。
Example 2-1 LIST FAILURE and ADVISE FAILURE
RMAN> LIST FAILURE; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary ---------- -------- --------- ------------- ------- 142 HIGH OPEN 23-APR-07 One or more non-system datafiles are missing 101 HIGH OPEN 23-APR-07 Datafile 1: '/disk1/oradata/prod/system01.dbf' contains one or more corrupt blocks RMAN> ADVISE FAILURE; List of Database Failures ========================= Failure ID Priority Status Time Detected Summary ---------- -------- --------- ------------- ------- 142 HIGH OPEN 23-APR-07 One or more non-system datafiles are missing 101 HIGH OPEN 23-APR-07 Datafile 1: '/disk1/oradata/prod/system01.dbf' contains one or more corrupt blocks analyzing automatic repair options; this may take some time using channel ORA_DISK_1 analyzing automatic repair options complete Mandatory Manual Actions ======================== no manual actions available Optional Manual Actions ======================= 1. If file /disk1/oradata/prod/users01.dbf was unintentionally renamed or moved, restore it Automated Repair Options ======================== Option Repair Description ------ ------------------ 1 Restore and recover datafile 28; Perform block media recovery of block 56416 in file 1 Strategy: The repair includes complete media recovery with no data loss Repair script: /disk1/oracle/log/diag/rdbms/prod/prod/hm/reco_660500184.hm
The ADVISE FAILURE
output shows both manual and automated repair options. First try to fix the problem manually. If you cannot fix the problem manually, then review the automated repair section.ADVISE FAILURE
命令的输出显示了手动和自动修复的选择。首先试着手动修复。如果你不会手动修复,则查看自动修复部分。
An automated repair option describes a server-managed repair for one or more failures. Repairs are consolidated when possible so that a single repair can fix multiple failures. The repair option indicates which repair will be performed and whether data will be lost by performing the repair.
自动修复选项(repair option)说的是服务器端管理的修复一个或多个故障。如果可能的话,修复是合并式的,一个简单的修复也许可以修复多个故障。修复选项也会指出将会进行哪种修复,并且此修复是否会造成数据丢失。
In Example 2-1, the output indicates the filename of a repair script containing RMAN commands. If you do not want to use Data Recovery Advisor to repair the failure automatically, then you can use the script as the basis of your own recovery strategy.
在例子中,命令的输出指出了包含RMAN命令的修复脚本的文件名。如果你不想用数据恢复指导来自动修复故障,那么你可以用基于你的备份策略的脚本来修复。
See Also:
"Listing Failures" and "Determining Repair Options"After running LIST FAILURE
and ADVISE FAILURE
in an RMAN session, you can run REPAIR FAILURE
to execute a repair option. If you execute REPAIR FAILURE
with no other command options, then RMAN uses the first repair option of the most recent ADVISE FAILURE
command in the current session. Alternatively, specify the repair option number obtained from the most recent ADVISE FAILURE
command. Example 2-2 illustrates how to repair the failures identified in Example 2-1.
在同一个RMAN session中执行了LIST FAILURE
和ADVISE FAILURE
命令后,你可以执行REPAIR FAILURE
命令来执行修复。如果你只执行了命令并没有跟其它命令选项,那么RMAN会用在此会话中最近一次的ADVISE FAILURE
命令显示出来的第一个选项进行修复。或者也可以指定相应的修复选项序号,从最近一次执行ADVISE FAILURE
命令中获得。Example 2-2详细说明了如何修复Example 2-1中的故障。
Example 2-2 REPAIR FAILURE
RMAN> REPAIR FAILURE;
By default, REPAIR FAILURE
prompts for confirmation before it begins executing. After executing a repair, Data Recovery Advisor reevaluates all existing failures on the possibility that they may also have been fixed. Data Recovery Advisor always verifies that failures are still relevant and automatically closes fixed failures. If a repair fails to complete because of an error, then the error triggers a new assessment and re-evaluation of existing failures and repairs.
默认情况下,REPAIR FAILURE
命令会生成让你确认的提示。执行完修复之后,数据恢复向导会在已经存在的故障中重新分析哪些故障已经被修复了。数据恢复向导会验证故障之间的关联,如果故障被修复了,会关闭这些故障。如果修复因为错误失败了,那么这个错误会触发一轮新的对已经存在的故障的分析。
See Also:
"Repairing Failures"You can use the Oracle Flashback Database to rewind the whole database to a past time. Unlike media recovery, you do not need to restore datafiles to return the database to a past state.
可以用oracle的闪回数据库(Oracle Flashback Database)方法把整个数据库恢复到过去的某个时间。不像介质恢复,不需要通过恢复数据文件把数据库恢复到以前的一个状态。
To use the RMAN FLASHBACK DATABASE
command, your database must have been previously configured to generate flashback logs. This configuration task is described in "Configuring Oracle Flashback Database and Restore Points". Flashback Database works by rewinding changes to the datafiles that exist at the moment that you run the command. You cannot use the command to repair media failures or missing datafiles.
用RMAN的FLASHBACK DATABASE
命令,你的数据库需要配置能够生成闪回日志(flashback logs)。这个配置参见"Configuring Oracle Flashback Database and Restore Points"。闪回数据库方法是这样工作的,你在运行这个命令的时候,只能恢复你现有的数据文件的变化。你不能用这个命令恢复介质故障或者丢失的数据文件。
The database must be mounted when you issue FLASHBACK DATABASE
. Note that if you have previously created a restore point, then you can flash back to this restore point if it falls within the flashback database window.
你声明用FLASHBACK DATABASE
命令的时候,数据库一定要是mount状态。注意,如果你创建一个恢复点(restore point),如果在闪回数据库窗口(flashback database window)失败的话,你可以闪回到这个恢复点。
To rewind a database with Flashback Database:
用闪回数据库的方法恢复数据库:
Start RMAN and connect to a target database.
启动RMAN并连接到目标数据库。
Ensure that the database is in a mounted state.
确认数据库在mount状态。
The following commands shut down and then mount the database:
下面的命令使数据库关闭并把数据库启动到mount状态:
SHUTDOWN IMMEDIATE; STARTUP MOUNT;
Run the FLASHBACK DATABASE
command.
运行FLASHBACK DATABASE
命令。
The following examples illustrate different forms of the command:
下面的例子详细说明了这个命令的几种不同的形式:
FLASHBACK DATABASE TO SCN 861150; FLASHBACK DATABASE TO RESTORE POINT BEFORE_CHANGES; FLASHBACK DATABASE TO TIME "TO_DATE('06/20/07','MM/DD/YY')";
After performing the Flashback Database, open the database read-only in SQL*Plus and run some queries to verify the database contents.
执行完闪回数据库之后,在SQL*Plus中把数据库启动到只读状态,执行一些查询操作,验证数据库内容。
Open the database read-only as follows:
把数据库启动到只读状态如下:
SQL "ALTER DATABASE OPEN READ ONLY";
If satisfied with the results, then issue the following sequence of commands to shut down and then open the database:
如果对结果满意,那么按顺序执行下面的命令关闭和启动数据库。
SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER DATABASE OPEN RESETLOGS;
See Also:
"Rewinding a Database with Flashback Database"Use the RESTORE
and RECOVER
commands for RMAN restore and recovery of physical database files. Restoring datafiles is retrieving them from backups as needed for a recovery operation. Media recovery is the application of changes from redo logs and incremental backups to a restored datafile to bring the datafile forward to a desired SCN or point in time.
用RESTORE
和RECOVER
命令恢复物理的数据文件。重新获得数据文件是林备份中获得数据文件,这是数据恢复必要的一步。介质恢复就是从重做日志和增量备份中重新获得数据文件,把数据文件恢复到需要的SCN版本或者过去的某一时间。
See Also:
Chapter 17, "Performing Complete Database Recovery"If you need to recover the database because a media failure damages database files, then you should first ensure that you have the necessary backups. You can use the RESTORE ... PREVIEW
command to report, but not restore, the backups that RMAN could use to restore to the specified time. RMAN queries the metadata and does not actually read the backup files. The database can be open when you run this command.
如果因为介质故障损坏了数据文件需要恢复数据库,那么第一你应该确认有可用的备份。你可以用RESTORE ... PREVIEW
命令来看看RMAN能够用来恢复到指定时间的备份,但是这时还没有进行恢复。RMAN只是查询了原数据,实际上并没有读取备份文件。执行这个命令的时候数据库可以是开启状态。
To preview a database restore and recovery:
Start RMAN and connect to the target database.
启动并连接到目标数据库。
Optionally, list the current tablespaces and datafiles, as shown in the following command:
可以像下面这样列出当前的表空间和数据文件:
RMAN> REPORT SCHEMA;
Run the RESTORE DATABASE
command with the PREVIEW
option.
运行RESTORE DATABASE PREVIEW
命令
The following command specifies SUMMARY
so that the backup metadata is not displayed in verbose mode (sample output included):
下面的命令指定了SUMMARY
,因此备份原数据没有详细显示出来
RMAN> RESTORE DATABASE PREVIEW SUMMARY; Starting restore at 21-MAY-07 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=80 device type=DISK List of Backups =============== Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag ------- -- -- - ----------- --------------- ------- ------- ---------- --- 11 B F A DISK 18-MAY-07 1 2 NO TAG20070518T181114 13 B F A DISK 18-MAY-07 1 2 NO TAG20070518T181114 using channel ORA_DISK_1 List of Archived Log Copies for database with db_unique_name PROD ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 47 1 18 A 18-MAY-07 Name: /disk1/oracle/dbs/db1r_60ffa882_1_18_0622902157.arc Media recovery start SCN is 586534 Recovery must be done beyond SCN 587194 to clear datafile fuzziness validation succeeded for backup piece Finished restore at 21-MAY-07
Use the RESTORE
DATABASE
and RECOVER
DATABASE
commands to recover the whole database. You must have previously made backups of all needed files. This scenario assumes that you can restore all datafiles to their original locations. If the original locations are inaccessible, then use the SET NEWNAME
command as described in "Restoring Datafiles to a Nondefault Location".
用RESTORE
DATABASE
和RECOVER
DATABASE
命令来恢复整个数据库。你必须把需要的文件都提前做了备份。这是假定你要把所有的数据文件恢复到它们的原始位置上。如果原始位置不可访问了,那么用SET NEWNAME
命令详见"Restoring Datafiles to a Nondefault Location"。
To recover the whole database:
Prepare for recovery as explained in "Preparing to Restore and Recover Database Files".
恢复前的准备参见"Preparing to Restore and Recover Database Files"。
Place the database in a mounted state.
把数据库切换到mount状态。
The following example terminates the database instance (if it is started) and mounts the database:
下面的例子终止数据库实例(如果是启动的状态)并且把数据库启动到mount状态。
RMAN> STARTUP FORCE MOUNT;
Restore the database.
重新获得数据库。
The following example uses the preconfigured disk channel to restore the database:
下面的例子是用预先配置好的磁盘信道重新获得数据库:
RMAN> RESTORE DATABASE;
Recover the database, as shown in the following example:
恢复数据库如下:
RMAN> RECOVER DATABASE;
Open the database, as shown in the following example:
把数据库开启:
RMAN> ALTER DATABASE OPEN;
Use the RESTORE
TABLESPACE
and RECOVER
TABLESPACE
commands on individual tablespaces when the database is open. In this case, must take the tablespace that needs recovery offline, restore and then recover the tablespace, and bring the recovered tablespace online.
在数据库开启的时候用RESTORE
TABLESPACE
和 RECOVER
TABLESPACE
命令作用于单独的表空间上。在这种情况下,必须把这个需要恢复的表空间下线,重新获得,然后恢复表空间,最后让表空间上线。
If you cannot restore a datafile to a new location, then use the RMAN SET NEWNAME
command within a RUN
command to specify the new filename. Afterward, use a SWITCH DATAFILE ALL
command, which is equivalent to using the SQL statement ALTER DATABASE RENAME FILE
, to update the control file to reflect the new names for all datafiles for which a SET NEWNAME
has been issued in the RUN
command.
如果不能在一个新的路径重新获得数据文件,那么用RMAN的SET NEWNAME
和RUN
命令来指定一个新的文件名。然后,用SWITCH DATAFILE ALL
命令把刚才用SET NEWNAME
和RUN
命令操作的数据文件的新文件名更新到控制文件中,等效于用sql语句的ALTER DATABASE RENAME FILE。
Unlike in user-managed media recovery, you should not place an online tablespace in backup mode. Unlike user-managed tools, RMAN does not require extra logging or backup mode because it knows the format of data blocks.
和用户自管理介质恢复不一样,你不需要把一个在线表空间置于备份模式(backup mode)。与用户自管理工具不一样,RMAN不需要额外的登录或者备份模式,因为RMAN知道数据块的格式。
To recover an individual tablespace when the database is open:
Prepare for recovery as explained in "Preparing to Restore and Recover Database Files".
恢复前的准备参见"Preparing to Restore and Recover Database Files"。
Take the tablespace to be recovered offline:
把要恢复的表空间下线:
The following example takes the users
tablespace offline:
下面的例子使用户表空间下线:
RMAN> SQL 'ALTER TABLESPACE users OFFLINE';
Restore and recover the tablespace.
重新获得及恢复表空间。
The following RUN
command, which you execute at the RMAN prompt, sets a new name for the datafile in the users
tablespace:
下面的RUN
命令在RMAN的提示行执行,为用户的表空间的数据文件起了一个新名字:
RUN { SET NEWNAME FOR DATAFILE '/disk1/oradata/prod/users01.dbf' TO '/disk2/users01.dbf'; RESTORE TABLESPACE users; SWITCH DATAFILE ALL; # update control file with new filenames RECOVER TABLESPACE users; }
Bring the tablespace online, as shown in the following example:
如下使表空间上线:
RMAN> SQL 'ALTER TABLESPACE users ONLINE';
You can also use RESTORE DATAFILE
and RECOVER DATAFILE
for recovery at the datafile level.
你也可以在数据文件级别用RESTORE DATAFILE
和RECOVER DATAFILE
命令恢复。
See Also:
"Performing Complete Recovery of a Tablespace"
"Online Backups and Backup Mode"
RMAN can recover individual corrupted datafile blocks. When RMAN performs a complete scan of a file for a backup, any corrupted blocks are listed in V$DATABASE_BLOCK_CORRUPTION
. Corruption is usually reported in alert logs, trace files, or results of SQL queries.
RMAN可以恢复个别冲突的数据文件块。当RMAN执行备份或文件扫描后,任何冲突的数据块都会列到V$DATABASE_BLOCK_CORRUPTION
视图内。冲突会写在警告日志中,跟踪文件或者sql语句的查询结果中。
To recover data blocks:
Obtain the block numbers of the corrupted blocks if you do not already have this information.
获得冲突的数据块号。
The easiest way to locate trace files and the alert log is to connect SQL*Plus to the target database and execute the following query:
最近的方法定位跟踪文件和警告日志是用SQL*Plus连接到目标数据库中,然后执行下面的查询:
SQL> SELECT NAME, VALUE 2 FROM V$DIAG_INFO;
Start RMAN and connect to the target database.
启动RMAN并连接到目标数据库。
Run the RECOVER
command to repair the blocks.
执行RECOVER
命令修复数据块。
The following RMAN command recovers all corrupted blocks:
下面的RMAN命令恢复所有冲突的数据块:
RMAN> RECOVER CORRUPTION LIST;
You can also recover individual blocks, as shown in the following example:
你也可以像下面这样恢复单独的数据块:
RMAN> RECOVER DATAFILE 1 BLOCK 233, 235 DATAFILE 2 BLOCK 100 TO 200;
See Also:
Chapter 18, "Performing Block Media Recovery"