- 浏览: 382911 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
lhbthanks:
楼主写的很多,也很实用,要是再增加一些描述就会更好了。
oracle 用户 从一个表空间 另一个表空间 -
wuhuajun:
private int _connectionMax = 51 ...
resin jboss 最大连接数设置 -
shixiaomu:
自己丁丁丁一下 学了忘忘了再学。。主要是应用场景太少
python -
shixiaomu:
我自己有了方案了java+rabbitmq_server-2. ...
hadoop hive zookeeper 还不够 -
shixiaomu:
看到这个帖子 羞愧极了 ,原来 我 09 年就想学 pytho ...
python
配置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
作者:浩瀚天涯 来源:不详 发布日期: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
发表评论
-
数据库的原理-侧重索引
2014-06-25 16:32 817统计信息和过滤因子 分布统计信息 (信息分布不均衡.存在重复数 ... -
redis并发统计
2012-11-20 18:24 1252统计并发. 是从1970年1月1日(UTC/GMT的午夜)开始 ... -
linux Page cache和buffer cache 正解
2012-11-13 16:17 1053Page cache和buffer cache一直以来是两个比 ... -
Redis被bgsave和bgrewriteaof阻塞的解决方法(转)
2012-08-02 11:26 792Redis 是一个性能非常高效的内存 Key-Value 存储 ... -
热点账户得问题
2010-08-10 13:44 1432热点账户得问题 -
执行查询cpu100%
2010-04-23 18:31 919联表是笛卡尔积还是左关联或者有关联? 不要看你查出来多少 ... -
oracle dbLink
2010-02-05 11:35 1039俩台不同的数据库服务器,从一台数据库服务器的一个用户读取另一台 ... -
oracle job 定时器 脚本
2009-09-02 11:55 1850declare JOB_ILEARN_ONLINE numb ... -
oracle 动态sql
2009-06-25 13:47 996用decode取代where条件的动态sql select ... -
oracle trigger 表名 列名
2009-06-04 11:39 1039select 'create or replace trigg ... -
oracle 数据库 触发器 trigger 语法
2009-06-04 09:23 6112关键字: oracle 数据库 触发器 trigger 语法 ... -
oracle proc
2009-04-29 18:22 1147CREATE OR REPLACE PROCEDURE use ... -
标准 oracle 存储过程 模板
2009-04-23 11:03 1379--创建存储过程 CREATE OR REPLACE PROC ... -
hql 日期 减法
2009-02-17 10:26 1298错误:select t from user t where t ... -
linux 安装 oracle 常见问题
2009-02-15 13:30 12881. 安装前的hosts文件 l cat /etc/ ... -
oracle 用户 从一个表空间 另一个表空间
2009-02-03 23:37 7699--------------重要--------------- ... -
oracle密码文件
2009-02-03 23:31 966很多时候需要对ORACLE密码文件进行重建,ORACLE对密码 ... -
oracle的冷热备份大全
2009-02-01 13:38 1204Oracle备份与恢复案例 By Piner 一. 理 ... -
linux oracle 的定时恢复和备份
2009-01-20 12:37 27561.exp导出 #!/bin/sh ORACLE_HO ...
相关推荐
在归档模式下,Oracle使用ARCH进程自动复制日志,归档日志文件的命名和存储位置可由管理员配置。 要将数据库设置为自动归档模式,需修改参数文件,开启归档功能,指定归档日志的位置和格式,然后重启并装载数据库,...
### Oracle 9i/10g 数据库管理详细知识点 #### 一、Oracle 9i/10g 概述 - **Oracle 9i** 和 **Oracle 10g** 是Oracle公司推出的两个重要的数据库管理系统版本。这些版本在企业级数据库管理领域具有重要意义。 - *...
10. **备份与恢复**:Oracle 9I提供了多种备份和恢复策略,如RMAN(恢复管理器)、在线日志备份和归档日志模式,确保了数据的可靠性和灾难恢复能力。 综上所述,Oracle 9I客户端压缩包包含了运行和管理Oracle数据库...
在Oracle9i中,理解归档模式和非归档模式的区别也非常重要。归档模式下,每次事务提交都会生成一个新的归档日志,这使得能够进行时间点恢复。非归档模式则没有这种能力,但通常在系统性能和简单恢复之间作出权衡。 ...
"第8章 Oracle9i数据库的恢复.ppt"将讨论数据库的备份和恢复策略,包括使用RMAN(恢复管理器)进行备份,理解归档日志模式,以及在数据丢失或系统故障时如何恢复数据。 "第7章 Oracle9i数据库的安全性.ppt"会介绍...
4. **备份与恢复**:Oracle9i提供了多种备份策略,包括完整备份、增量备份和归档日志模式。手册会详细介绍RMAN(Recovery Manager)的使用,它是Oracle数据库备份和恢复的主要工具。 5. **安全控制**:Oracle9i强化...
《双机之Oracle9i安装手册》...总之,《双机之Oracle9i安装手册》提供了详尽的步骤指导,对于在Windows2000/2003双机环境下安装和配置Oracle9i数据库具有极高的参考价值,有助于IT管理员实现高效、稳定的数据库部署。
2. 安装与配置:Oracle 9i的安装过程包括软件安装、硬件需求分析、网络配置和实例创建。熟悉这些步骤能确保数据库系统的稳定运行。 3. 数据库实例与内存结构:Oracle数据库由多个内存区域和后台进程组成,如SGA...
第三部分可能涉及故障排除和高级特性,比如归档模式、闪回技术、数据库复制、RAC(Real Application Clusters)集群数据库的设置与管理,以及数据仓库和OLAP(在线分析处理)应用。这部分内容对于应对复杂的数据库...
### Oracle9i 数据库性能优化知识点详解 #### 一、Oracle9i 数据库性能优化概述 Oracle9i 是 Oracle 公司推出的一款功能强大的关系型数据库管理系统(RDBMS)。随着业务规模的增长和技术的发展,Oracle9i 的性能优化...
8. 高可用性:Oracle 9i支持各种高可用性解决方案,如归档日志模式、闪回技术、数据库复制等。手册会详细介绍这些技术的工作原理和配置步骤。 9. 网络配置:手册会涉及Oracle Net Services的配置,包括TNS...
此外,还会涉及数据文件、控制文件、重做日志文件和归档模式的概念,这些都是数据库正常运行的关键元素。 数据库管理是DBA的核心任务,手册会深入讲解数据的备份与恢复策略。这包括使用RMAN(恢复管理器)进行物理...
9. **数据库备份与恢复**:掌握Oracle的备份策略,包括冷备份、热备份、增量备份和归档日志模式。理解如何在数据丢失时使用备份进行恢复。 10. **数据库性能监控**:通过使用Oracle的性能分析工具如SQL*Plus、企业...
如果是归档模式,还需恢复日志。 2. 关闭:同样用sqlplus登录,执行shutdown命令。有立即、交易完成、正常和休眠四种关闭模式,根据实际情况选择。 四、数据管理 1. 表空间管理:创建和管理表空间,用于存储数据库...
8. **数据库实例管理**:介绍实例启动、关闭和监控,以及如何进行数据库的归档和无归档模式操作。 9. **故障诊断和恢复**:学习如何识别和解决数据库常见问题,使用alert log和trace文件进行故障排查。 10. **网络...
2. **Oracle9i安装与配置**:讲解如何在不同操作系统上安装Oracle9i,包括硬件需求、软件安装步骤、网络配置和初始化参数设置。 3. **SQL基础**:教授SQL语言的基本语法,如SELECT语句、DML(数据操纵语言)操作、...
Oracle9i DataGuard支持多种高级架构,如物理备用数据库(Physical Standby)、逻辑备用数据库(Logical Standby)和远端归档(Remote Archiving)。这些架构提供了不同的数据保护级别和功能,可以根据实际需求进行...
1. **归档模式**:数据库必须处于归档模式才能启用归档日志。在此模式下,填满的日志组会被归档,而不是被覆盖。 2. **归档日志**:当一个日志组被填满时,如果数据库处于归档模式,则该日志组会被复制或归档到一个...
- **使用归档日志模式**:支持不完全恢复操作,提高灵活性。 综上所述,Oracle 9i 数据库的高级实例调优涉及多个方面,从架构理解到具体工具的应用都需要深入掌握。通过对上述知识点的学习和实践,可以有效地提升...
2. 归档日志模式:在归档日志模式下,Oracle9i会记录所有事务修改的历史,从而支持完全恢复。 3. 数据泵(Data Pump):Oracle9i的数据泵工具用于快速导入和导出数据,同时支持在不同数据库间迁移数据。 四、Oracle...