配置Oracle9i的归档模式

配置Oracle9i的归档模式
作者:浩瀚天涯  来源:不详   发布日期:2007-05-06  

1.归档日志模式和非归档日志模式的区别
非归档模式只能做冷备份,并且恢复时只能做完全备份.最近一次完全备份到系统出错期间的数据不能恢复.
归档模式可以做热备份,并且可以做增量备份,可以做部分恢复.
用ARCHIVE LOG LIST 可以查看期模式状态时归档模式还是非归档模式.

2.配置数据库的归档模式

改变非归档模式到归档模式:
1)SQL>SHUTDOWN NORMAL/IMMEDIATE;
2)SQL>START MOUNT;
3)SQL>ALTER DATABASE ARCHIVELOG;
4)SQL>ALTER DATABASE OPEN;

5)SQL>做一次完全备份,因为非归档日志模式下产生的备份日志对于归档模式已经不可用了.这一步非非常重要!
改变归档模式到非归档模式:
1)SQL>SHUTDOWN NORMAL/IMMEDIATE;
2)SQL>START MOUNT;
3)SQL>ALTER DATABASE NOARCHIVELOG;
4)SQL>ALTER DATABASE OPEN;


3.启用自动归档: LOG_ARCHIVE_START=TRUE
归档模式下,日志文件组不允许被覆盖(重写),当日志文件写满之后,如果没有进行手动归档,那么系统将挂起,知道归档完成为止.
这时只能读而不能写.
运行过程中关闭和重启归档日志进程
SQL>ARCHIVE LOG STOP
SQL>ARCHIVE LOG START

4.手动归档: LOG_ARCHIVE_START=FALSE
归档当前日志文件
SQL>ALTER SYSTEM ARCHIVE LOG CURRENT;
归档序号为052的日志文件
SQL>ALTER SYSTEM ARCHIVE LOG SEQUENCE 052;
归档所有日志文件
SQL>ALTER SYSTEM ARCHIVE LOG ALL;
改变归档日志目标
SQL>ALTER SYSTEM ARCHIVE LOG CURRENT TO \'&PATH\';

5.归档模式和非归档模式的转换

第4步的逆过程.

6.配置多个归档进程
Q:什么时候需要使用多个归档进程?
A:如果归档过程会消耗大量的时间,那么可以启动多个归档进程,这是个动态参数,可以用ALTER SYSTEM动态修改.
SQL>ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=10;
Oracle9i中最多可以指定10个归档进程
与归档进程有关的动态性能视图
v$bgprocess,v$archive_processes


7.配置归档目标,多归档目标,远程归档目标,归档日志格式
归档目标 LOG_ARCHIVE_DEST_n
本地归档目标:
SQL>LOG_ARCHIVE_DEST_1 = "LOCATION=D:\\ORACLE\\ARCHIVEDLOG";
远程归档目标:
SQL>LOG_ARCHIVE_DEST_2 = "SERVICE=STANDBY_DB1";
强制的归档目标,如果出错,600秒后重试:
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_4 = "LOCATION=E:\\ORACLE\\ARCHIVEDLOG MANDATORY REOPEN=600";
可选的归档目标,如果出错,放弃归档:
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_3 = "LOCATION=E:\\ORACLE\\ARCHIVEDLOG OPTIONAL";

归档目标状态:关闭归档目标和打开归档目标
关闭归档目标1
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1 = DEFER
打开归档目标2
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2 = ENABLE

归档日志格式
LOG_ARCHIVE_FORMAT

8.获取归档日志信息
V$ARCHVIED_LOG
V$ARCHVIE_DEST
V$LOG_HISTORY
V$DATABASE
V$ARCHIVE_PROCESSES

ARCHIVE LOG LIST;

















  

Home Articles Scripts Forums Blog Certification Misc About Printer Friendly
Oracle 8i | Oracle 9i | Oracle 10g | Oracle 11g | Miscellaneous | Oracle RAC | Oracle Apps | Linux

Home » Articles » 9i » Here
      

Oracle9i Recovery Manager (RMAN)
Recovery manager is a platform independent utility for coordinating your backup and restoration procedures across multiple servers. In my opinion it's value is limited if you only have on or two instances, but it comes into it's own where large numbers of instances on multiple platforms are used. The reporting features alone mean that you should never find yourself in a position where your data is in danger due to failed backups.

The functionality of RMAN is too diverse to be covered in this article so I shall focus on the basic backup and recovery functionality.

Create Recovery Catalog
Register Database
Full Backup
Restore & Recover The Whole Database
Restore & Recover A Subset Of The Database
Incomplete Recovery
Disaster Recovery
Lists And Reports
Create Recovery Catalog
First create a user to hold the recovery catalog:

CONNECT sys/password@w2k1 AS SYSDBA

-- Create tablepsace to hold repository
CREATE TABLESPACE "RMAN"
DATAFILE 'C:\ORACLE\ORADATA\W2K1\RMAN01.DBF' SIZE 6208K REUSE
AUTOEXTEND ON NEXT 64K MAXSIZE 32767M
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;

-- Create rman schema owner
CREATE USER rman IDENTIFIED BY rman
TEMPORARY TABLESPACE temp
DEFAULT TABLESPACE rman
QUOTA UNLIMITED ON rman;

GRANT connect, resource, recovery_catalog_owner TO rman;
Then create the recovery catalog:

C:>rman catalog=rman/rman@w2k1

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

connected to recovery catalog database
recovery catalog is not installed

RMAN> create catalog tablespace "RMAN";

recovery catalog created

RMAN> exit

Recovery Manager complete.

C:>
Register Database
Each database to be backed up by RMAN must be registered:

C:>rman catalog=rman/rman@w2k1 target=sys/password@w2k2

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

connected to target database: W2K2 (DBID=1371963417)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>
Existing user-created backups can be added to the catalog using:

RMAN> catalog datafilecopy 'C:\Oracle\Oradata\TSH1.dbf';
RMAN> catalog archivelog 'log1', 'log2', 'log3', ... 'logN';
Full Backup
First we configure several persistant parameters for this instance:

RMAN> configure retention policy to recovery window of 7 days;
RMAN> configure default device type to disk;
RMAN> configure controlfile autobackup on;
RMAN> configure channel device type disk format 'C:\Oracle\Admin\W2K2\Backup%d_DB_%u_%s_%p';
Next we perform a complete database backup using a single command:

RMAN> run {
2>   backup database plus archivelog;
3>   delete noprompt obsolete;
4> }
The recovery catalog should be resyncronized on a regular basis so that changes to the database structure and presence of new archive logs is recorded. Some commands perform partial and full resyncs implicitly, but if you are in doubt you can perform a full resync using the follwoing command:

RMAN> resync catalog;
Restore & Recover The Whole Database
If the controlfiles and online redo logs are still present a whole database recovery can be achieved by running the following script:

run {
  shutdown immediate; # use abort if this fails
  startup mount;
  restore database;
  recover database;
  alter database open;
}
This will result in all datafiles being restored then recovered. RMAN will apply archive logs as necessary until the recovery is complete. At that point the database is opened. If the tempfiles are still present you can issue a command like like the following for each of them:

sql "ALTER TABLESPACE temp ADD
     TEMPFILE ''C:\Oracle\oradata\W2K2\temp01.dbf''
     REUSE";
If the tempfiles are missing they must be recreated as follows:

sql "ALTER TABLESPACE temp ADD
     TEMPFILE ''C:\Oracle\oradata\W2K2\temp01.dbf''
     SIZE 100M
     AUTOEXTEND ON NEXT 64K";
Restore & Recover A Subset Of The Database
A subset of the database can be restored in a similar fashion:

run {
  sql 'ALTER TABLESPACE users OFFLINE IMMEDIATE';
  restore tablespace users;
  recover tablespace users;
  sql 'ALTER TABLESPACE users ONLINE';
}
Incomplete Recovery
As you would expect, RMAN allows incomplete recovery to a specified time, SCN or sequence number:

run {
  shutdown immediate;
  startup mount;
  set until time 'Nov 15 2000 09:00:00';
  # set until scn 1000;       # alternatively, you can specify SCN
  # set until sequence 9923;  # alternatively, you can specify log sequence number
  restore database;
  recover database;
  alter database open resetlogs;
}
The incomplete recovery requires the database to be opened using the RESETLOGS option.

Disaster Recovery
In a disaster situation where all files are lost you can only recover to the last SCN in the archived redo logs. Beyond this point the recovery would have to make reference to the online redo logs which are not present. Disaster recovery is therefore a type of incomplete recovery. To perform disaster recovery connect to RMAN:

C:>rman catalog=rman/rman@w2k1 target=sys/password@w2k2
Once in RMAN do the following:

startup nomount;
restore controlfile;
alter database mount;
From SQL*Plus as SYS get the last archived SCN using:

SQL> SELECT archivelog_change#-1 FROM v$database;

ARCHIVELOG_CHANGE#-1
--------------------
             1048438

1 row selected.

SQL>
Back in RMAN do the following:

run {
  set until scn 1048438;
  restore database;
  recover database;
  alter database open resetlogs;
}
If the "until scn" were not set the following type of error would be produced once a redo log was referenced:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/18/2003 09:33:19
RMAN-06045: media recovery requesting unknown log: thread 1 scn 1048439

With the database open all missing tempfiles must be replaced:

sql "ALTER TABLESPACE temp ADD
     TEMPFILE ''C:\Oracle\oradata\W2K2\temp01.dbf''
     SIZE 100M
     AUTOEXTEND ON NEXT 64K";
Once the database is fully recovered a new backup should be perfomed.

The recovered database will be registered in the catalog as a new incarnation. The current incarnation can be listed and altered using the following commands:

list incarnation;
reset database to incarnation x;
Lists And Reports
RMAN has extensive listing and reporting functionality allowing you to monitor you backups and maintain the recovery catalog. Here are a few useful commands:

# Show all backup details
list backup;

# Show items that beed 7 days worth of
# archivelogs to recover completely
report need backup days = 7 database; 


# Show/Delete items not needed for recovery
report obsolete;
delete obsolete;

# Show/Delete items not needed for point-in-time
# recovery within the last week
report obsolete recovery window of 7 days;
delete obsolete recovery window of 7 days;

# Show/Delete items with more than 2 newer copies available
report obsolete redundancy = 2 device type disk;
delete obsolete redundancy = 2 device type disk;

# Show datafiles that connot currently be recovered
report unrecoverable database;
report unrecoverable tablespace 'USERS';
It's worth spending some time looking at all the reporting capabilities whilst deciding whether you should switch from shell scripting to RMAN. It might just influence your decision.

For more information see:

Recovery Manager (RMAN) Enhancements In Oracle9i
RMAN Enhancements in Oracle Database 10g
Oracle8i Recovery Manager (RMAN)
Oracle9i Recovery Manager User's Guide
Hope this helps. Regards Tim...

Back to the Top.


20 comments, read/add them...



Home | Articles | Scripts | Forums | Blog | Certification | Misc | About

      Copyright & Disclaimer      



在这里没有讨论多么深入的RMAN技术,也没有告诉大家这样去编写备份脚本,这并不是我的初衷,我只想把我会的写出来,和大家一起学习,一起进步,谢谢。

    1、切换服务器归档模式,如果已经是归档模式可跳过此步:

    %sqlplus /nolog (启动sqlplus)

    SQL> conn / as sysdba (以DBA身份连接数据库)

    SQL> shutdown immediate; (立即关闭数据库)

    SQL> startup mount (启动实例并加载数据库,但不打开)

    SQL> alter database archivelog; (更改数据库为归档模式)

    SQL> alter database open; (打开数据库)

    SQL> alter system archive log start; (启用自动归档)

    SQL> exit (退出)

    2、连接:

    %rman target=rman/rman@mydb (启动恢复管理器)

    3、基本设置:

    RMAN> configure default device type to disk; (设置默认的备份设备为磁盘)

    RMAN> configure device type disk parallelism 2; (设置备份的并行级别,通道数)

    RMAN> configure channel 1 device type disk fromat '/backup1/backup_%U'; (设置备份的文件格式,只适用于磁盘设备)

    RMAN> configure channel 2 device type disk fromat '/backup2/backup_%U'; (设置备份的文件格式,只适用于磁盘设备)

    RMAN> configure controlfile autobackup on; (打开控制文件与服务器参数文件的自动备份)

    RMAN> configure controlfile autobackup format for device type disk to '/backup1/ctl_%F'; (设置控制文件与服务器参数文件自动备份的文件格式)

    4、查看所有设置:

    RMAN> show all

    5、查看数据库方案报表:

    RMAN> report schema;

    6、备份全库:

    RMAN> backup database plus archivelog delete input; (备份全库及控制文件、服务器参数文件与所有归档的重做日志,并删除旧的归档日志)

    7、备份表空间:

    RMAN> backup tablespace system plus archivelog delete input; (备份指定表空间及归档的重做日志,并删除旧的归档日志)

    8、备份归档日志:

    RMAN> backup archivelog all delete input;

    9、复制数据文件:

    RMAN> copy datafile 1 to '/oracle/dbs/system.copy';

    10、查看备份和文件复本:

    RMAN> list backup;

    11、验证备份:

    RMAN> validate backupset 3;

    12、从自动备份中恢复服务器参数文件:

    RMAN> shutdown immediate; (立即关闭数据库)

    RMAN> startup nomount; (启动实例)

    RMAN> restore spfile to pfile '/backup1/mydb.ora' from autobackup; (从自动备份中恢复服务器参数文件)

    13、从自动备份中恢复控制文件:

    RMAN> shutdown immediate; (立即关闭数据库)

    RMAN> startup nomount; (启动实例)

    RMAN> restore controlfile to '/backup1' from autobackup; (从自动备份中恢复控制文件)

13、恢复和复原全数据库:

    RMAN> shutdown immediate; (立即关闭数据库)

    RMAN> exit (退出)

    %mv /oracle/dbs/tbs_12.f /oracle/dbs/tbs_12.bak (将数据文件重命名)

    %mv /oracle/dbs/tbs_13.f /oracle/dbs/tbs_13.bak (将数据文件重命名)

    %mv /oracle/dbs/tbs_14.f /oracle/dbs/tbs_14.bak (将数据文件重命名)

    %mv /oracle/dbs/tbs_15.f /oracle/dbs/tbs_15.bak (将数据文件重命名)

    %rman target=rman/rman@mydb (启动恢复管理器)

    RMAN> startup pfile=/oracle/admin/mydb/pfile/initmydb.ora (指定初始化参数文件启动数据库)

    RMAN> restore database; (还原数据库)

    RMAN> recover database; (恢复数据库)

    RMAN> alter database open; (打开数据库)

    14、恢复和复原表空间:

    RMAN> sql 'alter tablespace users offline immediate'; (将表空间脱机)

    RMAN> exit (退出恢复管理器)

    %mv /oracle/dbs/users01.dbf /oracle/dbs/users01.bak (将表空间重命名)

    %rman target=rman/rman@mydb (启动恢复管理器)

    RMAN> restore tablespace users; (还原表空间)

    RMAN> recover tablespace users; (恢复表空间)

    RMAN> sql 'alter tablespace users online'; (将表空间联机)

    15、增量备份与恢复:

    第一天的增量基本备份:

    RMAN> backup incremental level=0 database plus archivelog delete input;

    第二天的增量差异备份:

    RMAN> backup incremental level=2 database plus archivelog delete input;

    第三天的增量差异备份:

    RMAN> backup incremental level=2 database plus archivelog delete input;

    第四天的增量差异备份:

    RMAN> backup incremental level=1 database plus archivelog delete input;

    第五天的增量差异备份:

    RMAN> backup incremental level=2 database plus archivelog delete input;

    第六天的增量差异备份:

    RMAN> backup incremental level=2 database plus archivelog delete input;

    第七天的增量差异备份:

    RMAN> backup incremental level=0 database plus archivelog delete input;

    增量恢复:

    RMAN> shutdown immediate;

    RMAN> exit

    %mv /oracle/dbs/tbs_12.f /oracle/dbs/tbs_12.bak

    %mv /oracle/dbs/tbs_13.f /oracle/dbs/tbs_13.bak

    %mv /oracle/dbs/tbs_14.f /oracle/dbs/tbs_14.bak

    %mv /oracle/dbs/tbs_15.f /oracle/dbs/tbs_15.bak

    %rman target=rman/rman@mydb

    RMAN> startup pfile=/oracle/admin/mydb/pfile/initmydb.ora

    RMAN> restore database;

    RMAN> recover database;

    RMAN> alter database open.(e129)on.htm

    simulator/doc/license_keys.htm

    simulator/doc/sdk.style.css

    simulator/doc/davehitzforeword.htm

    simulator/doc/faq.htm

    simulator/doc/troubleshooting.htm

    simulator/license.htm

    simulator/readme.htm

    simulator/runsim.sh

    simulator/setup.sh

    simulator/sim.tgz



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值