SMR & RMAN的基本操作zt

本文解释 SMR & RMAN的基本操作。由于RMAN具有极大的灵活性,这里先只涉及其基本功能。更多的信息请参见 《Oracle8 Server Backup & Recovery Guide》。更复杂的例子请察看 $ORACLE_HOME/rdbms/demo目录下的*.rcv脚本。[@more@]

Getting started with Server-Managed Recovery (SMR)and Recovery Manager (RMAN)
SMR( Server-Managed Recovery)和RMAN( Recovery Manager)入门
Introduction 介绍:
本文解释 SMR & RMAN的基本操作。由于RMAN具有极大的灵活性,这里先只涉及其基本功能。更多的信息请参见 《Oracle8 Server
Backup & Recovery Guide》。更复杂的例子请察看 $ORACLE_HOME/rdbms/demo目录下的*.rcv脚本。
为了清楚,我没有附带不必要的RMAN错误信息。通常发生这些错误的时候会看到这些错误!
Contents 内容:
1. What is RMAN & SMR?
2. Terminology
3. The recovery catalog
4. Starting RMAN
5. Register the target database
6. Adding existing backups to the recovery catalog
7. Backing up in noarchivelog mode
8. Backing up in archivelog mode
9. Incremental backups
10. Cumulative incremental backups
11. Recovery
12. Scripts
13. Parallelization
14. Corruption detection
15. Channels
16. Balancing throughput on devices
17. Reports
18. Hints, tips, & best practices
1. What is RMAN? 什么是RMAN?
RMAN可以用来备份和还原数据库文件、归档日志和控制文件。它也可以用来执行完全或不完全的数据库恢复。 注意RMAN不能用于备份初始化参数文件和口令文件。
RMAN启动数据库上的Oracle服务器进程来进行备份或还原。备份、还原、恢复是由这些进程驱动的,所以有了'server-managed
recovery'这个词。
注意:SMR也可以由OEM的Backup Manager GUI来控制。本文不讨论Backup Manager。
2. Terminology 词汇
2.1. Backup sets 备份集合
备份集合有下面的特性:
o. 包括一个或多个数据文件或归档日志
o. 以oracle专有的格式保存
o. 有一个完全的所有的备份片集合构成
o. 构成一个完全备份或增量备份
2.2. Backup pieces 备份片
一个备份集由若干个备份片组成。每个备份片是一个单独的输出文件。一个备份片的大小是有限制的;如果没有大小的限制,
备份集就只由一个备份片构成。备份片的大小不能大于你的文件系统所支持的文件长度的最大值。
2.3. Image copies 映像备份
映像备份是独立文件(数据文件、归档日志、控制文件)的备份。它很类似操作系统级的文件备份。它不是备份集或 备份片,也没有被压缩。
2.4. Full backup sets 全备份集合
全备份是一个或多个数据文件中使用过的数据块的的备份。没有使用过的数据块是不被备份的,也就是说,oracle 进行备份集合的压缩。
2.5. Incremental backup sets 增量备份集合
增量备份是指备份一个或多个数据文件的自从上一次同一级别的或更低级别的备份以来被修改过的数据块。 与完全备份相同,增量备份也进行压缩。
2.6. File multiplexing
Datablocks from multiple datafiles can be multiplexed in the same
backupset.
2.7. Recovery catalog resyncing 恢复目录
Resyncing the recovery catalog involves sunchronising the recovery catalog
with the target database controlfile. Certain operations perform this
implicitly. To resync manually, issue the 'resync catalog;' command from RMAN.
The catalog should be resynced frequently, especially if the target database
generates many archive logs. It should also be resynced after making any
structural changes to the target database.
Although the target database's controlfile is automatically updated
whenever new controlfile records are created (for example, creation of new
archived logs or new datafiles), if the target is not resync'd and a backup
controlfile is restored, the new records must be cataloged manually (catalog
archivelog logname>';).
3. The recovery catalog 恢复目录
From the Oracle8 Server Backup & Recovery Guide '..the recovery catalog is a
repository of information that is used and maintained by RMAN. RMAN uses the
information in the recovery catalog to determine how to execute requested backup
and restore actions..'.
The recovery catalog can be in a schema of an existing Oracle8 database.
However if RMAN is being used to backup multiple databases, it is probably
worth creating a dedicated recovery catalog database. THE RECOVERY CATALOG
DATABASE CANNOT BE USED TO CATALOG BACKUPS OF ITSELF.
The Oracle8 Server Backup & Recovery Guide p.6-3 lists typical space
requirements for the recovery catalog.
To set up the recovery catalog, firstly ensure that catalog and catproc have
been run, then execute the following:
SVRMGR> spool create_rman.log
SVRMGR> connect internal
SVRMGR> create user rman identified by rman
temporary tablespace temp
default tablespace rcvcat quota unlimited on rcvcat;
SVRMGR> grant recovery_catalog_owner to rman;
SVRMGR> connect rman/rman
SVRMGR> @?/rdbms/admin/catrman
Check create_rman.log for errors. The above commands assume that the TEMP and
RCVCAT tablespaces have been created.
Also ensure that catproc has been run on the target database as SYS (do
_not_ use SYSTEM); RMAN makes extensive use of RPCs.
It is very important that the recovery catalog database is backed up
regularly and frequently.
Note: Although you are not required to use a recovery catalog with RMAN, it
is recommended. Because most of the information in the recovery catalog is
available via the target database's controlfile, RMAN can use this information
for recovery purposes. For more information and limitations on using RMAN
without a recovery catalog, please see the Oracle8 Server Backup & Recovery
Guide pp.7-8, 7-8.
4. Starting RMAN 启动RMAN
RMAN has a command line interface, or can be run from Enterprise Manager.
For the purposes of this document, only the CLI will be covered.
For the purposes of the following examples, assume that
o. the target database is called "targdb" and has the same TNS alias
o. "targdba" has been granted SYSDBA privileges
o. the recovery catalog database is called "rcat" and has the same TNS alias
o. the schema containing the recovery catalog is "rman" (same password)
Before invoking RMAN, set the NLS_DATE_FORMAT and NLS_LANG environment
variables. Much of the RMAN LIST output is date/time related. It is often
necessary to have this information displayed as accurately as possible when
performing time-based recovery. Example NLS settings:
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
NLS_DATE_FORMAT=DD-MON-YYYY HH24:MI:SS
For RMAN to connect to the recovery catalog and the target database, the
recovery catalog database must be OPEN, while the target instance must be at
least STARTED. If not, RMAN will give an error. To perform backups with the
target database open, the target MUST be in archivelog mode.
4.1. Connecting to RMAN without a recovery catalog 连接不带恢复目录的RMAN
Set ORACLE_SID to be the target database, and issue the following:
% rman nocatalog
RMAN> connect target
or if the target database uses a password file,
RMAN> connect target targdba/@targdb
4.2. Connecting to RMAN with a recovery catalog 连接带恢复目录的RMAN
% rman rcvcat rman/rman@rcat
RMAN> connect target
or if the target database uses a password file,
% rman rcvcat rman/rman@rcat target targdba/@targdb
4.3. Using RMAN 使用RMAN
Once connected to the target database, you can specify RMAN commands
either interactively or by using stored scripts. An example of using
RMAN interactively would be:
RMAN> resync catalog;
An example of calling a stored script would be:
RMAN> execute script alloc_1_disk;
To create/replace a stored script:
RMAN> replace script alloc_1_disk {
2> allocate channel d1 type disk;
3> }
5. Register the target database 注册目标数据库
Database status:
Recovery catalog: open
Target: mounted or open
The target database must be registered with the recovery catalog before using
RMAN against the database for the first time:
RMAN> register database;
6. Adding existing backups to the recovery catalog 将已有的备份加到恢复目录中
Database status:
Recovery catalog: open
Target: mounted or open
If user-created backups existed under version 8.x prior to registering with
the target database, these can be added to the recovery catalog as follows:
RMAN> catalog datafilecopy '/supp/ .... /systargdb.dbf';
To view this file in the catalog, use the following command:
RMAN> list copy of database;
7. Backing up in noarchivelog mode 在被归档模式下备份
Database status:
Recovery catalog: open
Target: instance started or database mounted
Recovery catalog database is OPEN, target database is started (optionally
mounted). Because the target database is not in archivelog mode, it must not be
open when performing backups of datafiles. This would be equivalent of making
filesystem copies of datafiles without putting tablespaces into hot backup
mode. If the database is open and not in archivelog mode, RMAN will generate an
error when you attempt to perform a datafile backup
7.1. Example of how to back up a complete database 数据库完全备份的例子
RMAN> run {
2> # backup the complete database to disk
3> allocate channel dev1 type disk;
4> backup
5> full
6> tag full_db_sunday_night
7> format '/oracle/backups/db_t%t_s%s_p%p'
8> (database);
9> release channel dev1;
10> }
Line#
2: Comment line (anything after the '#' is a comment)
3&9: See section 15 - Channels
5: Full backup (default if full or incremental not specified)
6: Meaningful string (<=30 chars)
7: Filename to use for backup pieces, including substitution variables.
Oracle8 Backup & Recovery Guide p8-26 explains these variables
8: Indicates all files including controlfiles are to be backed up
To view this backup in the catalog, use the following command:
RMAN> list backupset of database;
7.2. Example of how to back up a tablespace 备份表空间的例子
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> tag tbs_users_read_only
5> format '/oracle/backups/tbs_users_t%t_s%s'
6> (tablespace users);
7> release channel dev1;
10> }
Line#
6: Specifying only the USERS tablespace for backup
To view this tablespace backup in the catalog, use the following command:
RMAN> list backupset of tablespace users;
If for example the USERS tablespace is going to be put READ ONLY after
being backed up, subsequent full database backups would not need to backup
this tablespace. To cater for this, specify the 'skip readonly'option in
subsequent backups.
Note that although this is a tablespace backup, the target database
does NOT have to be open, only mounted. This is because tablespace
information is stored in the controlfile in o8.
7.3. Example of how to backup individual datafiles 备份单独的数据文件的例子
RMAN> run {
2> allocate channel dev1 type 'SBT_TAPE';
3> backup
4> format '%d_%u'
5> (datafile '/oracle/dbs/sysbigdb.dbf');
6> release channel dev1;
7> }
Line#
2: Allocates a tape drive using the media manager layer (MML)
Note that no tag was specified and is therefore null.
To view this tablespace backup in the catalog, use the following command:
RMAN> list backupset of datafile 1;
7.4. Copying datafiles 备份数据文件
RMAN> run {
2> allocate channel dev1 type 'SBT_TAPE';
3> copy datafile '/oracle/dbs/temp.dbf' to '/oracle/backups/temp.dbf';
4> release channel dev1;
5> }
To view this file copy in the catalog, use the following command:
RMAN> list copy of datafile '/oracle/dbs/temp.dbf';
Copying a datafile is different to backing up a datafile. A datafile copy
is an image copy of the file. A backup of the file creates a backupset.
7.5. Backing up the controlfile 备份控制文件
RMAN> run {
2> allocate channel dev1 type 'SBT_TAPE';
3> backup
4> format 'cf_t%t_s%s_p%p'
5> tag cf_monday_night
6> (current controlfile);
7> release channel dev1;
8> }
Note that a database backup will automatically back up the controlfile.
8. Backing up in archivelog mode 在归档模式下备份
Database status:
Recovery catalog: open
Target: instance started, database mounted or open
The commands are identical to those in section 7 except that the target
database is in archivelog mode.
8.1. Backing up archived logs 备份归档日志
The following script backs up all archive logs:
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format '/oracle/backups/log_t%t_s%s_p%p'
5> (archivelog all);
6> release channel dev1;
7> }
The following script backs up archive logs from sequence# 90 to 100:
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format '/oracle/backups/log_t%t_s%s_p%p'
5> (archivelog from logseq=90 until logseq=100 thread 1);
6> release channel dev1;
7> }
The following script backs up all archive logs generated in the past
24 hours. Furthermore it actually deletes the logs after backing them up. If
the backup fails, logs will NOT be deleted:
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> format '/oracle/backups/log_t%t_s%s_p%p'
5> (archivelog from time 'sysdate-1' all delete input);
6> release channel dev1;
7> }
To view the archive logs in the catalog, use the following command:
RMAN> list backupset of archivelog all;
Note that RMAN will backup specified logs if it finds them. If it can't
find a log, it does not issue a warning.
8.2. Backing up the online logs 备份联机日志
Online logs CANNOT be backed up using RMAN; they must be archived first.
联机日志不能用RMAN来备份,必须先将其归档。
To do this, you can issue SQL commands from RMAN e.g.
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter system archive log current";
4> backup
5> format '/oracle/backups/log_t%t_s%s_p%p'
6> (archivelog from time 'sysdate-1' all delete input);
7> release channel dev1;
8> }
The above script might be run after performing a full 'database open'
backup. It would ensure that all redo to recover the database to a
consistent state would be backed up.
Note, you cannot tag archive log backupsets.
9. Incremental backups 增量备份
A level N incremental backup backs up blocks that have changed since the
most recent incremental backup at level N or less.
9.1. Level 0 - the basis of the incremental backup strategy 增量备份策略的基础
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> incremental level 0
5> filesperset 4
6> format '/oracle/backups/sunday_level0_%t'
7> (database);
8> release channel dev1;
9> }
Line#
4: Level 0 backup - backups of level > 0 can be applied to this
5: Specifies maximum files in the backupset
A list of the database backupsets will show the above backup. The 'type'
column is marked 'Incremental'; the 'LV' column shows '0'.
9.2. Example backup strategy using incremental backups
A typical incremental backup cycle would be as follows:
o. Sun night - level 0 backup performed
o. Mon night - level 2 backup performed
o. Tue night - level 2 backup performed
o. Wed night - level 2 backup performed
o. Thu night - level 1 backup performed
o. Fri night - level 2 backup performed
o. Sat night - level 2 backup performed
If the database suffered a failure on Sat morning and this resulted in
a restore operation, RMAN could recover to the point of failure by restoring
the backups from Sunday, Thursday, and Friday. This is because Thursdays
level 1 backup contains all changes since Sunday, and Friday's level 2
backup contains all changes since Thursday. Whether the database could be
completely recovered would depend on whether archive logging is enabled.
10. Cumulative incremental backups 累积的增量备份
A cumulative incremental backup backs up all blocks that have changed since
the the most recent incremental backup at level N-1 or less (contrast with
non-cumulative incremental backups that backup blocks that have changed since
the the most recent incremental backup at level N or less). This means that
more work is done in performing the backup (duplication of backup effort), but
time may be saved when restoring (potentially fewer backupsets to restore).
RMAN> run {
2> allocate channel dev01 type disk;
3> backup incremental level 1 cumulative database;
4> release channel dev01;
5> }
11. Recovery 恢复
As with backup, recovery is probably best explained with a few examples
11.1. Database open, datafile deleted 数据库打开时,文件被删除
Datafile has been deleted from a running database. There are two methods
of open database recovery: restore the datafile and recover either the
datafile, or the tablespace. The next two examples show both methods:
(a) Datafile recovery 数据文件恢复
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter tablespace users offline immediate";
4> restore datafile 4;
5> recover datafile 4;
6> sql "alter tablespace users online";
7> release channel dev1;
8> }

(b) Tablespace recovery 表空间恢复
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter tablespace users offline immediate";
4> restore tablespace users;
5> recover tablespace users;
6> sql "alter tablespace users online";
7> release channel dev1;
8> }
Note that if it is the system tablespace datafiles to be restored, the
database must be closed. It is not possible to offline the system
tablespace.
11.2. Complete restore (lost online redo) and rollforward - database closed
完全还原(丢失联机日志)并且回卷 - 数据库关闭
RMAN> run {
2> allocate channel dev1 type disk;
3> set until logseq=105 thread=1;
4> restore controlfile to '/oracle/dbs/ctrltargdb.ctl';
5> replicate controlfile from '/oracle/dbs/ctrltargdb.ctl';
6> restore database;
7> sql "alter database mount";
8> recover database;
9> sql "alter database open resetlogs";
10> release channel dev1;
11> }
Notes:
- The 'set until' command dictates at which log sequence recovery will
stop. It is critical that this command is issued BEFORE datafiles
are restored, otherwise RMAN will attempt to restore the most recent set
of datafiles, which could be ahead of the specified log
- The 'replicate controlfile' copies the restored controlfile to
the controlfiles referenced in init.ora
- Because the database is opened with resetlogs, it is necessary to
register the new incarnation of the database with the RESET DATABASE
command. As with v7, it is important to take a full backup of the
database immediately after a resetlogs
11.3. Restore of a subset of datafiles, complete recovery 还原数据文件的子集,完全恢复
RMAN> run {
2> allocate channel dev1 type disk;
3> sql "alter database mount";
4> restore datafile 2;
5> restore datafile 3;
6> restore archivelog all;
7> recover database;
8> sql "alter database open";
9> release channel dev1;
10> }
12. Scripts 脚本
It is very easy to create and replace stored scripts with RMAN. E.g.
RMAN> create script alloc_disk {
2> # Allocates one disk
3> allocate channel dev1 type disk;
4> setlimit channel dev1 kbytes 2097150 maxopenfiles 32 readrate 200;
5> }
RMAN> replace script rel_disk {
2> # releases disk
3> release channel dev1;
5> }
RMAN> replace script backup_db_full {
2> # Performs a complete backup
3> execute script alloc_disk;
4> backup
5> .....
6> execute script rel_disk;
7> }
The first 2 scripts allocate and deallocate channels respectively. The
alloc_disk script additionally specifies the maximum size of backup pieces
created on this channel (kbytes), the maximum number of input files that a
backup will have open (maxopenfiles), and the maximum number of buffers per
second which will be read from each of the input datafiles.
The 3rd script calls the previously stored scripts either side of
performing a backup.
Example of executing a stored script:
RMAN> run {
2> execute script backup_db_full;
3> }
Note that a stored scripts must be called from within a job command list
i.e. run { .... execute

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

转载于:http://blog.itpub.net/556989/viewspace-903251/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值