Oracle RMAN 的 show,list,crosscheck,delete命令整理
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘C:ORACLE..SNCFTEST.ORA’; #default
1.configure retention policy to redundancy 1:
是用来决定那些备份不再需要了,它一共有三种可选项,分别是
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE RETENTION POLICY TO REDUNDANCY 5;
CONFIGURE RETENTION POLICY TO NONE;
第一种recover window是保持所有足够的备份,可以将数据库系统恢复到最近七天内的任意时刻。任何超过最近七天的数据库备份将被标记为obsolete。
后面的%F是存储格式
================
RMAN中常用configure命令2007-06-21 15:37
1 显示当前的配置信息
===========================
1.01 RMAN> show all;
1.02 查询RMAN设置中非默认值:
SQL> select name,value from v$rman_configure;
2. 常用的configure选项
===========================
2.01 保存策略 (retention policy)
configure retention policy to recovery window of 3 days;
configure retention policy to redundancy 3;
configure retention policy clear;
2.02 备份优化 backup optimization
configure backup optimization on;
configure backup optimization off;
configure backup optimization clear;
2.03 默认设备 default device type
configure default device type to disk;
configure default device type to stb;
configure default device type clear;
2.04 控制文件 controlfile
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/cfs01/backup/conf/conf_%F';
configure controlfile autobackup clear;
configrue controlfile autobackup format for device type disk clear;
configrue snapshot controlfile name to '/cfs01/backup/snapcf/scontrofile.snp';
configrue snapshot controlfile name clear;
2.05 并行数(通道数) device type disk|stb pallelism n;
configure device type disk|stb parallelism 2;
configure device type disk|stb clear;
configure channel device type disk format 'e/:rmanback_%U';
configure channel device type disk maxpiecesize 100m
configure channel device type disk rate 1200K
configure channel 1 device type disk format 'e/:rmanback_%U';
configure channel 2 device type disk format 'e/:rmanback_%U';
configure channel 1 device type disk maxpiecesize 100m
2.06 生成备份副本 datafile|archivelog backup copies
configure datafile backup copies for device type disk|stb to 3;
configure archivelog backup copies for device type disk|stb to 3;
configure datafile|archivelog backup copies for device type disk|stb clear
BACKUP DEVICE TYPE DISK DATABASE
FORMAT '/disk1/backup/%U', '/disk2/backup/%U', '/disk3/backup/%U';
2.07 排除选项 exclude
configure exclude for tablespace 'users';
configrue exclude clear;
2.08 备份集大小 maxsetsize
configure maxsetsize to 1G|1000M|1000000K|unlimited;
configure maxsetsize clear;
2.09 其它选项 auxiliary
CONFIGURE AUXNAME FOR DATAFILE 1 TO '/oracle/auxfiles/aux_1.f';
CONFIGURE AUXNAME FOR DATAFILE 2 TO '/oracle/auxfiles/aux_2.f';
CONFIGURE AUXNAME FOR DATAFILE 3 TO '/oracle/auxfiles/aux_3.f';
CONFIGURE AUXNAME FOR DATAFILE 4 TO '/oracle/auxfiles/aux_4.f';
-
CONFIGURE AUXNAME FOR DATAFILE 1 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 2 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 3 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 4 CLEAR;
Rman的format格式中的%
%c 备份片的拷贝数
%d 数据库名称
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,YYYYMMDD为
日期,QQ是一个1-256的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)
一周内把所有的命令测试后记录如下(2010.08.24):
RMAN组件
1、目标数据库
2、服务器进程
3、通道
4、RMAN资料库
ORACLE总是将RMAN元数据放到目标数据库的控制文件中,如果配置了恢复目录,则RMAN元数据会被放到恢复目录中。
5、恢复目录
在RMAN元数据存放天数达到初始化参数control_file_record_keep_time的值之后,其元数据可能会被覆盖,从而导致之前的备份不能使用。
6、介质管理层
7、RMAN包
包dbms_backup_restore用于执行备份、转储和恢复操作。backup、copy、restore、recover
包dbms_revcat用于维护恢复目录。resync catalog、catalog
包dbms_rcvman用于查询恢复目录和目标数据库控制文件。list、report
RMAN特点
1、备份数据库、表空间、数据文件、控制文件、归档日志和SPFILE。目标库必须处于MOUNT状态或OPEN状态。
2、存储频繁执行的备份和恢复操作。放到脚本中执行
3、跳过未用块。
4、执行增量块级备份
5、指定备份限制
6、在备份时检测损坏块。用DBVERIFY工具进行检查
7、自动使用并行化特征提高备份和恢复性能。分配多个CPU、多个通道。
RMAN命令
1、独立命令
RMAN>shutdown immediate
RMAN>startup
RMAN>backup format 'd:ackup\%d_%s.bak' tablespace users;
2、作业命令
RMAN>run { backup format 'd:ackup$d_%s.bak' tablespace users; }
3、运行SQL命令
RMAN>sql 'alter system switch logfile' ;
4、运行存储脚本
RMAN>run { execute script s1;}
5、运行操作系统命令
RMAN>run { host "dir d:ackup"; }
6、运行RMAN命令
c: man target sys/oracle@TEST nocatalog @c:ak_users.cmd log a.log
bak_users.cmd示例:
backup format 'd:ackup\%d_%s.bak tablespace users;
sql 'alter system archive log current' ;
配置RMAN环境(略)
建立备份集
1、完全数据库备份集
1)、一致性备份(适用于NOARCHIVELOG和ARCHIVELOG模式)
c: man target sys/oracle@TEST nocatalog
RMAN>shutdown immediate
RMAN>startup mout
RMAN>backup database; 如果备份到别的目录backup database format ='d:ackup\%d_%s.dbf' ;
RMAN>sql 'alter system archive log current ' ;
2)、非一致性备份(在OPEN状态)
RMAN>backup database; 如果备份到别的目录backup database format ='d:ackup\%d_%s.dbf' ;
RMAN>sql 'alter system archive log current ' ;
3)、免除表空间
RMAN>configure exclude for tablespace user03;
RMAN>backup database; 如果备份到别的目录backup database format ='d:ackup\%d_%s.dbf' ;
RMAN>sql 'alter system archive log current ' ;
2、表空间备份集
RMAN>backup tablespace users format='d:ackup\%N_%f_%s.dbf' ;
3、数据文件备份集
RMAN>backup datafile 5 format='d:ackup\%N_%f_%s.dbf' ;
4、控制文件备份集
RMAN>backup current controlfile format='d:ackup\%d_%s.ctl' ;
5、SPFILE备份集
RMAN>backup spfile format='c:\%d_%s.par';
6、归档日志备份集(过去一天所生成的归档日志)
RMAN>backup format='c:\%d_%s.arc' archivelog from time='sysdate-1' until time='sysdate';
7、并行化备份集
RMAN>configure device type disk parallelism 3 ;
RMAN>backup database format='c:\%d_%s.dbf';
RMAN>configure device type disk clear;
8、建立多重备份
RMAN>backup copied 3 tablespace users format='c:1\%N_%s.dbf','c:2\%N_%s.dbf','c:3\%N_%s.dbf' ;
9、备份备份集
RMAN>backup backupset 32 format='c:\%d_%s.bak';
10、建立多个备份片
RMAN>configure channel device type sbt maxpiecesize 4G;
RMAN>backup device type sbt format '%d_%s_%p.dbf' database;
11、建立压缩备份集
RMAN>backup as compressed backupset tablespace users format='c:\%d_%s.dbf';
12、备份数据文件和归档日志
RMAN>backup format 'c:\%d_%s.bak' tablespace users plus archivelog ;
13、指定备份集标记
RMAN>backup format='c:\%d_%s.bak' tablespace users tag='users' ;
建立映像副本
1、建立数据文件映像副本
RMAN>backup as copy format='c:df_5.dbf' datafile 5; 或者
RMAN>copy datafile 5 to 'c:df_5.dbf' ;
2、建立控制文件映像副本
RMAN>backup as copy format='c:demo.ctl' current controlfile; 或者
RMAN>copy current controlfile to 'c:demo.ctl';
3、建立归档日志映像副本
RMAN>backup as copy format='c:arc10.log' archivelog sequence 10; 或者
RMAN>copy archivelog 'c:demoarchivearc00020_012345.001' to 'c:arc20.log';
4、并行化建立映像副本
RMAN>configure device type disk parallelism 3;
RMAN>backup as copy format ='c:df_%f.dbf' datafile 5,6,7 ;
RMAN>configure device type disk clear;
5、指定映像副本标记
RMAN>backup as copy format='c:df_%f.dbf' datafile 5 tag=df_5; 或者
RMAN>copy datafile 5 to 'c:df_%f.dbf' tag=df_5;
建立增量备份和累积备份
增量备份可以减少备份时间,累积备份可以减少恢复时间。
增量备份示例:周日 LEVEL 0 ,周一、周二、周四、、周五、周六 LEVEL 2 ,周三 LEVEL 1
RMAN>backup incremental level 0 format='c:ackup\%d_%s.dbf' tablespace users; 周日
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周一
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周二
RMAN>backup incremental level 1 format='c:ackup\%d_%s.dbf' tablespace users; 周三
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周四
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周五
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周六
RMAN完全恢复
1、恢复数据库
1)、所有数据文件被删除
c: man target sys/oracel@test nocatalog
RMAN>startup force mount
RMAN> run {
restore databse ;
recover database;
sql 'alter database open' ;
}
2)、数据文件所在磁盘出现硬件故障
RMAN> run {
startup force mount;
set newname for datafile 1 to 'c:demosystem01.dbf';
set newname for datafile 2 to 'c:demodundotbs01.dbf';
set newname for datafile 3 to 'c:demosysaux01.dbf';
set newname for datafile 4 to 'c:demousers01.dbf';
set newname for datafile 5 to 'c:demoexample01.dbf';
set newname for datafile 6 to 'c:demo est0.dbf';
restore database;
switch datafile all;
recover database;
sql 'alter database open ';
}
2、恢复SYSTEM表空间的数据文件
1)、SYSTEM表空间的数据文件被误删除
RMAN>run {
startup force mount;
restore datafile 1;
recover datafile 1;
sql 'alter database open' ;
}
2)、SYSTEM表空间数据文件所在的磁盘出现故障
RMAN> run {
startup force mount;
set newname for datafile 1 to 'c:demosystem01.dbf';
restore datafile 1;
switch datafile 1;
recover datafile 1;
sql 'alter database open';
}
3、在OPEN状态下恢复关闭后意外丢失数据文件
1)、数据文件被删除
RMAN>run {
startup force mount;
sql 'alter database datafile 4 offline';
sql 'alter database open ';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
2)、数据文件所在的磁盘出现损坏
RMAN>run {
startup force mount;
sql 'alter database datafile 4 offline';
sql 'alter database open ';
set newname for datafile 4 to 'c:demouser01.dbf';
restore datafile 4;
switch datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
4、在OPEN状态下恢复打开时意外丢失的数据文件
1)、数据文件被误删除
RMAN>run {
sql 'alter database datafile 4 offline';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
2)、数据文件所在磁盘出现故障
RMAN>run {
sql 'alter database datafile 4 offline';
set newname for datafile 4 to 'c:demouser01.dbf';
restore datafile 4;
switch datafile 4 ;
recover datafile 4;
sql 'alter database datafile 4 online';
}
5、在OPEN状态下恢复未备份的数据文件(创造新数据文件后没有进行过备份)
1)、数据文件被误
RMAN>run {
startup force mount;
sql 'alter database datafile 7 offline ';
sql 'alter database open';
restore datafile 7;
recover datafile 7;
sql 'alter database datafile 7 online';
}
2)、数据文件所在磁盘出现故障
RMAN>run {
startup force mount;
sql 'alter database datafile 7 offline ';
sql 'alter database open';
set newname for datafile 7 to 'c:demouser04.dbf';
restore datafile 7;
switch datafile 7;
recover datafile 7;
sql 'alter database datafile 7 online';
}
6、恢复表空间
1)、表空间被删除
RMAN>run {
sql 'alter tablespace users offline for recover';
restore tablespace users;
recover tablespace users;
sql 'alter tablespace users online';
}
2)、表空间的数据文件所在磁盘出现故障
RMAN>run {
sql 'alter tablespace users offline for recover';
set newname for datafile 4 to 'c:demouser01.dbf';
restore tablespace users;
switch tablespace users;
recover tablespace users;
sql 'alter tablespace users online';
}
7、数据块介质恢复
RMAN>blockrecover device type disk datafile 5 block 20,21,100 ;
RMAN不完全恢复
1、基本时间恢复
c:set nls_date_format=yyyy-dd-mm hh24:mi:ss
c: man target sys/oracle@test nocatalog
RMAN>run {
startup force mount;
set until time='2010-08-22 12:00:08';
restore database;
recover database;
sql 'alter database open resetlogs;
}
2、基于SCN恢复
RMAN>run {
startup force mount;
set until scn=123456;
restore database;
recover database;
sql 'alter database open resetlogs';
}
3、基于日志序列号恢复
RMAN>run {
startup force mount;
set until seqence=10;
restore database;
recover database;
sql 'alter database open resetlogs';
}
4、基于备份控制文件恢复
c:set nls_date_format=yyyy-dd-mm hh24:mi:ss
c: man target sys/oracle@test nocatalog
RMAN>startup force nomount;
RMAN>set dbid=1113606269;
RMAN>restore controlfile from autobackup maxseq 6;
RMAN>alter database mount;
RMAN>run {
set until time='2010-08-22 12:00:08';
restore database;
recover database;
sql 'alter database open resetlogs;
}
当执行了上述4种不完全恢复之后,建议删除早期的所有备份,并重新备份数据库
RMAN>run {
delete noprompt backup;
delete noprompt copy;
backup database format='c:ackup\%d_%s.bak';
sql 'alter system archive log current';
}
RMAN维护命令
REPORT
1、报告目标数据库的物理结构
RMAN>report schema;
2、报告需要备份的数据文件
1)、报告需要转储的增量备份超出特定个数的数据文件
RMAN> report need backup incremental 3;
2)、报告特定天数未备份的数据文件
RMAN>report need backup days 3 tablespace users ;
3)、报告低于特定备份次数的数据文件
RMAN> report need backup redundancy 2 database ;
4)、报告在恢复时间窗口内未备份的数据文件
RMAN> report need backup recovery window of 3 days ;
3、报告陈旧备份
RMAN>report obsolete redundancy 2;
4、报告不可恢复的数据文件
RMAN>report unrecoverable;
LIST
1、列出数据文件备份集
RMAN>list backup of database ;
RMAN>list backup of tablespace users;
RMAN>list backup of datafile 4;
2、列出控制文件备份集
RMAN>list backup of controlfile ;
3、列出归档日志备份集
RMAN>list backup of archivelog all;
4、列出SPFILE备份集
RMAN>list backup of spfile ;
5、列出数据文件映像副本
RMAN>list copy of database;
RMAN>list copy of tablespace users;
RMAN>list copy of datafile 4;
6、列出控制文件映像副本
RMAN>list copy of controlfile;
7、列出归档日志映像副本
RMAN>list copy of archivelog all;
8、列出数据库副本
RMAN>list incarnation of database ;
注意,每次用RESETLOGS选项打开数据库之后都会生成一个新的数据库副本。
9、列出备份集文件的信息
RMAN>list backupset 100;
CROSSCHECK
1、核对所有备份集
RMAN>crosscheck backup;
2、核对所有数据文件的备份集
RMAN>crosscheck backup of database ;
3、核对特定表空间的备
RMAN>crosscheck backup of tablespace system;
4、核对特定数据文件的备份集
RMAN>crosscheck backup of datafile 1;
5、核对控制文件的备份集
RMAN>crosscheck backup of controlfile ;
6、核对SPFILE的备份集
RMAN> crosscheck backup of spfile;
7、核对归档日志的备份集
RMAN> crosscheck backup of archivelog sequence 40;
8、核对所有映像副本
RMAN> crosscheck copy ;
9、核对所有数据文件的映像副本
RMAN> crosscheck copy of database;
10、核对特定表空间的映像副本
RMAN> crosscheck copy of tablespace users;
11、核对特定数据文件的映像副本
RMAN> crosscheck copy of datafile 1;
12、核对控制文件的映像副本
RMAN> crosscheck copy of controlfile;
13、核对归档日志的映像副本
RMAN> crosscheck copy of archivelog sequence 44;
DELETE
1、删除陈旧备份
delete obsolete; #提示
delete noprompt obsolete; #不提示
2、删除EXPIRED备份集
delete noprompt expired backup;
3、删除EXPIRED副本
delete noprompt expired copy ;
4、删除特定备份集
delete noprompt backupset 19;
5、删除特定备份片
delete noprompt backuppiece 'c: estdemo1.bak';
6、删除所有备份集
delete noprompt backup ; 或者
delete noprompt backupset;
7、删除特定映像副本
delete noprompt datafilecopy 'c: estdemo.bak'; 删除数据文件
delete noprompt controlfilecopy 'c: estcontrolfile_bak.ctl'; 删除控制文件
delete noprompt archivelog 'c: estarc.bak'; 删除归档日志
8、删除所有映像副本
delete noprompt copy;
9、在备份后删除输入对象
backup archivelog all delete input ;
backup backupset 22 format='c: est\%u.bak' delete input ;
CHANGE
1、改变备份集状态
change backupset 22 unavailable;
2、改变映像副本状态
change datafilecopy 'c:demo.bak' unavailable ;
change controlfilecopy 'c:demo.bak' unavailable ;
change archivelog 'c:demo.bak' unavailable ;
3、建立长期备份
change backupset 100 keep forver logs; 使备份集100永久保留
change backupset 100 keep until time 'sysdate+60' logs; 使备份集100保留60天
change backupset 156 nokeep ; 免除备份集100的保留期限
CATALOG
1、注册副本
catalog datafilecopy 'c:user01.bak';
2、注册备份片
catalog backuppiece 'c:demo_10.dbf' ;
3、注册特定目录的所有备份文件
catalog start with 'c:ak';
4、注销备份记录
change datafilecopy 'c:user01.bak' uncatalog;
change controlfilecopy 'c:demo.ctl' uncatalog;
change backuppiece 'c:demo_10.bak' uncatalog;
恢复目录管理
建立恢复目录
1、建立恢复目录表空间
SQL> create tablespace rman_ts
2 datafile 'D:oracleproduct10.1.0db_1 rain man.dbf'
3 size 15m ;
表空间已创建。
2、建立恢复目录所有者
SQL> create user rman identified by rman
2 default tablespace rman_ts;
用户已创建。
3、授予恢复目录所有者角色
SQL> grant connect,resource,recovery_catalog_owner to rman;
授权成功。
4、建立恢复目录
c: man catalog rman/rman@train
RMAN>create catalog;
5、注册目标数据库
RMAN>connect target sys/oracle@train
RMAN>register database;
RMAN>report schema;
使用存储脚本
1、建立存储脚本
C:>rman catalog rman/rman@train target sys/dddddd@train
RMAN>create script bak_database {
backup format='c: emp\%d_%s.bak'
database include current controlfile
plus archivelog;
sql 'alter system archive log current' ;
}
2、运行脚本
(1)、在RMAN提示符下运行存储脚本
RMAN>run { execute script bak_database; }
(2)、在命令行运行存储脚本
c: man catalog rman/rman@train target sys/dddddd@train script bak_database
3、显示存储脚本内容
RMAN>print script bak_database;
4、替换存储脚本
RMAN>replace script bak_database {
backup database format='c: emp\%d_%s.bak';
}
5、删除存储脚本
RMAN>delete script bak_database;
6、列出所有存储脚本
RMAN>list script names;
维护恢复目录
1、重新同步恢复目录
RMAN> resync catalog;
2、注销目标数据库
RMAN>unregister database;
当注销了目标数据库之后,会丢失早于controlfile_record_keep_time设置时间的RMAN资料库记录。
3、升级恢复目录
C:>rman catalog rman/rman@train target sys/dddddd@train
RMAN> upgrade catalog;
RMAN> upgrade catalog;
4、删除恢复目录
C:>rman catalog rman/rman@train target sys/dddddd@train
RMAN> drop catalog ;
RMAN> drop catalog ;
5、恢复数据库到早期数据库副本
Oracle RMAN 的 show,list,crosscheck,delete命令整理
1、SHOW命令:
显示rman配置: RMAN> show all;
显示rman配置: RMAN> show all;
2、REPORT命令:
2.1、RMAN> report schema 报告目标数据库的物理结构;
2.2、RMAN>report need backup days=3; 报告最近3天没有被备份的数据文件;
2.3、RMAN> report need backup days 3 tablespace users; 在USERS表空间上3天未备份的数据文件;
2.4、RMAN> report need backup incremental 3; 报告恢复数据文件需要的增量备份个数超过3次的数据文件;
2.5、RMAN> report need backup redundancy 2 database; 报告备份文件低于2份的所有数据文件;
RMAN>report need backup redundancy=2;
2.6、RMAN> report need backup recovery window of 6 days; 报告文件报表的恢复需要超过6天的归档日志的数据文件;
2.7、RMAN> report unrecoverable; 报告数据库所有不可恢复的数据文件;
2.8、RMAN> report obsolete redunndancy 2; 报告备份次数超过2次的陈旧备份;
2.9、RMAN>report obsolete; 报告多余的备份;
2.1、RMAN> report schema 报告目标数据库的物理结构;
2.2、RMAN>report need backup days=3; 报告最近3天没有被备份的数据文件;
2.3、RMAN> report need backup days 3 tablespace users; 在USERS表空间上3天未备份的数据文件;
2.4、RMAN> report need backup incremental 3; 报告恢复数据文件需要的增量备份个数超过3次的数据文件;
2.5、RMAN> report need backup redundancy 2 database; 报告备份文件低于2份的所有数据文件;
RMAN>report need backup redundancy=2;
2.6、RMAN> report need backup recovery window of 6 days; 报告文件报表的恢复需要超过6天的归档日志的数据文件;
2.7、RMAN> report unrecoverable; 报告数据库所有不可恢复的数据文件;
2.8、RMAN> report obsolete redunndancy 2; 报告备份次数超过2次的陈旧备份;
2.9、RMAN>report obsolete; 报告多余的备份;
3、LIST命令:列出备份信息
3.1、列出数据文件备份集
RMAN> list backup 列出详细备份;
RMAN> list expired backup; 列出过期备份;
RMAN> list backup of database; 列出所有数据文件的备份集;
RMAN> list backup of tablespace user01; 列出特定表空间的所有数据文件备份集;
3.2、RMAN> list backup of controlfile 列出控制文件备份集;
3.3、RMAN> list backup of archivelog all 列出归档日志备份集详细信息;
RMAN>list archivelog all; 列出归档日志备份集简要信息
3.4、RMAN> list backup of spfile 列出SPFILE备份集;
3.5、RMAN> list copy of datafile 5 列出数据文件映像副本;
3.6、RMAN> list copy of controlfile 列出控制文件映像副本;
3.7、RMAN> list copy of archivelog all 列出归档日志映像副本;
3.8、RMAN> list incarnation of database 列出对应物/列出数据库副本;
3.9、RMAN> list backup summary; 概述可用的备份;
B表示backup
F表示FULL
A表示archive log
0 1表示incremental backup
S说明备份状态(A AVAILABLE X EXPIRED )
3.1、列出数据文件备份集
RMAN> list backup 列出详细备份;
RMAN> list expired backup; 列出过期备份;
RMAN> list backup of database; 列出所有数据文件的备份集;
RMAN> list backup of tablespace user01; 列出特定表空间的所有数据文件备份集;
3.2、RMAN> list backup of controlfile 列出控制文件备份集;
3.3、RMAN> list backup of archivelog all 列出归档日志备份集详细信息;
RMAN>list archivelog all; 列出归档日志备份集简要信息
3.4、RMAN> list backup of spfile 列出SPFILE备份集;
3.5、RMAN> list copy of datafile 5 列出数据文件映像副本;
3.6、RMAN> list copy of controlfile 列出控制文件映像副本;
3.7、RMAN> list copy of archivelog all 列出归档日志映像副本;
3.8、RMAN> list incarnation of database 列出对应物/列出数据库副本;
3.9、RMAN> list backup summary; 概述可用的备份;
B表示backup
F表示FULL
A表示archive log
0 1表示incremental backup
S说明备份状态(A AVAILABLE X EXPIRED )
3.10、RMAN>list backup by file 按备份类型列出备份;
按照数据文件备份,归档日志备份,控制文件备份,服务器参数文件备份 列出
按照数据文件备份,归档日志备份,控制文件备份,服务器参数文件备份 列出
4、CROSSCHECK命令:校验备份信息
4.1、 RMAN> crosscheck backup 核对所有备份集;
4.2、 RMAN> crosscheck backup of database 核对所有数据文件的备份集;
4.3、 RMAN> crosscheck backup of tablespace users 核对特定表空间的备份集;
4.4、 RMAN> crosscheck backup of datafile 4 核对特定数据文件的备份集;
4.5、 RMAN> crosscheck backup of controlfile 核对控制文件的备份集;
4.6、 RMAN> crosscheck backup of spfile 核对SPFILE的备份集;
4.7、 RMAN> crosscheck backup of archivelog sequence 3 核对归档日志的备份集;
4.8、 RMAN> crosscheck copy 核对所有映像副本;
4.9、 RMAN> crosscheck copy of database 核对所有数据文件的映像副本;
4.10、RMAN> crosscheck copy of tablespace users 核对特定表空间的映像副本;
4.11、RMAN> crosscheck copy of datafile 6 核对特定数据文件的映像副本;
4.12、RMAN> crosscheck copy of archivelog sequence 4 核对归档日志的映像副本;
4.13、RMAN> crosscheck copy of controlfile 核对控制文件的映像副本;
4.14、RMAN> crosscheck backup tag='SAT_BACKUP';
4.15、RMAN> crosscheck backup completed after 'sysdate - 2'
4.16、RMAN> crosscheck backup completed between 'sysdate - 5' and 'sysdate -2 '
4.17、RMAN> crosscheck backup device type sBT;
4.18、RMAN> crosscheck archivelog all;
4.19、RMAN> crosscheck archivelog like '%ARC00012.001'
4.20、RMAN> crosscheck archivelog from sequence 12;
4.21、RMAN> crosscheck archivelog until sequence 522;
4.1、 RMAN> crosscheck backup 核对所有备份集;
4.2、 RMAN> crosscheck backup of database 核对所有数据文件的备份集;
4.3、 RMAN> crosscheck backup of tablespace users 核对特定表空间的备份集;
4.4、 RMAN> crosscheck backup of datafile 4 核对特定数据文件的备份集;
4.5、 RMAN> crosscheck backup of controlfile 核对控制文件的备份集;
4.6、 RMAN> crosscheck backup of spfile 核对SPFILE的备份集;
4.7、 RMAN> crosscheck backup of archivelog sequence 3 核对归档日志的备份集;
4.8、 RMAN> crosscheck copy 核对所有映像副本;
4.9、 RMAN> crosscheck copy of database 核对所有数据文件的映像副本;
4.10、RMAN> crosscheck copy of tablespace users 核对特定表空间的映像副本;
4.11、RMAN> crosscheck copy of datafile 6 核对特定数据文件的映像副本;
4.12、RMAN> crosscheck copy of archivelog sequence 4 核对归档日志的映像副本;
4.13、RMAN> crosscheck copy of controlfile 核对控制文件的映像副本;
4.14、RMAN> crosscheck backup tag='SAT_BACKUP';
4.15、RMAN> crosscheck backup completed after 'sysdate - 2'
4.16、RMAN> crosscheck backup completed between 'sysdate - 5' and 'sysdate -2 '
4.17、RMAN> crosscheck backup device type sBT;
4.18、RMAN> crosscheck archivelog all;
4.19、RMAN> crosscheck archivelog like '%ARC00012.001'
4.20、RMAN> crosscheck archivelog from sequence 12;
4.21、RMAN> crosscheck archivelog until sequence 522;
5、DELETE:删除备份
5.1、RMAN> delete obsolete; 删除陈旧备份;
5.2、RMAN> delete expired backup; 删除EXPIRED备份
5.3、RMAN> delete expired copy; 删除EXPIRED副本;
5.4、RMAN> delete backupset 19; 删除特定备份集;
5.5、RMAN> delete backuppiece ''d:backupDEMO_19.bak'' 删除特定备份片;
5.6、RMAN> delete backup 删除所有备份集;
5.7、RMAN> delete datafilecopy ''d:backupDEMO_19.bak'' 删除特定映像副本;
5.8、RMAN> delete copy 删除所有映像副本;
5.9、RMAN> backup archivelog all delete input;在备份后删除输入对象;
RMAN> backup backupset 22 format = ''d:backup%u.bak'' delete input
在备份后删除输入对象;
5.1、RMAN> delete obsolete; 删除陈旧备份;
5.2、RMAN> delete expired backup; 删除EXPIRED备份
5.3、RMAN> delete expired copy; 删除EXPIRED副本;
5.4、RMAN> delete backupset 19; 删除特定备份集;
5.5、RMAN> delete backuppiece ''d:backupDEMO_19.bak'' 删除特定备份片;
5.6、RMAN> delete backup 删除所有备份集;
5.7、RMAN> delete datafilecopy ''d:backupDEMO_19.bak'' 删除特定映像副本;
5.8、RMAN> delete copy 删除所有映像副本;
5.9、RMAN> backup archivelog all delete input;在备份后删除输入对象;
RMAN> backup backupset 22 format = ''d:backup%u.bak'' delete input
在备份后删除输入对象;
5.10、RMAN> delete backupset id; 删除备份集
一致性备份是在SQL>startup mount 下的备份;
非一致性的备份是在open状态下的备份;
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL>
SQL> startup mount
ORACLE 例程已经启动。
非一致性的备份是在open状态下的备份;
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL>
SQL> startup mount
ORACLE 例程已经启动。
Total System Global Area 285212672 bytes
Fixed Size 1248552 bytes
Variable Size 75498200 bytes
Database Buffers 201326592 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
SQL>
Fixed Size 1248552 bytes
Variable Size 75498200 bytes
Database Buffers 201326592 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
SQL>
$ more rman_backup.rcv
allocate channel for maintenance type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt expired backup;
release channel;
sql 'alter system checkpoint';
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/nddb/1/rman/%F';
run{
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
backup
skip inaccessible
filesperset 1
format '/backup/nddb/1/rman/orcl_db_%s_%p_%t.bk'
(database);
sql 'alter system archive log current';
backup format '/backup/nddb/1/rman/orcl_arc_%s_%p_%t.arc' (archivelog all delete input);
release channel t1;
release channel t2;
release channel t3;
allocate channel d1 type disk;
copy current controlfile to '/backup/nddb/1/rman/control.ctl';
release channel d1;
}
allocate channel for maintenance type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt expired backup;
release channel;
sql 'alter system checkpoint';
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/nddb/1/rman/%F';
run{
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
backup
skip inaccessible
filesperset 1
format '/backup/nddb/1/rman/orcl_db_%s_%p_%t.bk'
(database);
sql 'alter system archive log current';
backup format '/backup/nddb/1/rman/orcl_arc_%s_%p_%t.arc' (archivelog all delete input);
release channel t1;
release channel t2;
release channel t3;
allocate channel d1 type disk;
copy current controlfile to '/backup/nddb/1/rman/control.ctl';
release channel d1;
}
$
$ more rman_target.sh
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.
export PATH
if [ -s "$MAIL" ] # This is at Shell startup. In normal
then echo "$MAILMSG" # operation, the Shell checks
fi # periodically.
export ORACLE_SID=icdc
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/OraHome_1
export AIXTHREAD_SCOPE=S
#export NLS_LANG=American_America.us7ascii
export NLS_LANG=American_america.zhs16gbk
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export TEMP=/tmp
export TMPDIR=/tmp
export LIBPATH=/oracle/OraHome_1/lib:/oracle/OraHome_1/lib32
export PATH=$ORACLE_HOME/bin:$PATH
umask 022
set -o vi
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.
export PATH
if [ -s "$MAIL" ] # This is at Shell startup. In normal
then echo "$MAILMSG" # operation, the Shell checks
fi # periodically.
export ORACLE_SID=icdc
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/OraHome_1
export AIXTHREAD_SCOPE=S
#export NLS_LANG=American_America.us7ascii
export NLS_LANG=American_america.zhs16gbk
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export TEMP=/tmp
export TMPDIR=/tmp
export LIBPATH=/oracle/OraHome_1/lib:/oracle/OraHome_1/lib32
export PATH=$ORACLE_HOME/bin:$PATH
umask 022
set -o vi
dir=/backup/nddb/1
logfile=rman_backup.log
dt=$(date +"%Y%m%d")
dt=$(date +"%Y%m%d")
echo "############################${dt}############################" >>${dir}/${logfile}
echo "Now remove old rman backup" >>${dir}/${logfile}
cd ${dir}
cd ${dir}
rm -rf rman
mkdir rman
chown -R oracle:dba rman
echo "rman backup begins at $(date +"%H:%M:%S")" >>${dir}/${logfile}
chown -R oracle:dba rman
echo "rman backup begins at $(date +"%H:%M:%S")" >>${dir}/${logfile}
rman target / cmdfile=${dir}/rman_backup.rcv log=${dir}/rman/rman.log
cat rman/rman.log >>${dir}/${logfile}
echo "rman backup ends at $(date +"%H:%M:%S")" >>${dir}/${logfile}
cat rman/rman.log >>${dir}/${logfile}
echo "rman backup ends at $(date +"%H:%M:%S")" >>${dir}/${logfile}
$
在Oracle 10g中的配置情况
使用RMAN>show all;
可以显示出RMAN 配置参数为:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
使用RMAN>show all;
可以显示出RMAN 配置参数为:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘C:ORACLE..SNCFTEST.ORA’; #default
1.configure retention policy to redundancy 1:
是用来决定那些备份不再需要了,它一共有三种可选项,分别是
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE RETENTION POLICY TO REDUNDANCY 5;
CONFIGURE RETENTION POLICY TO NONE;
第一种recover window是保持所有足够的备份,可以将数据库系统恢复到最近七天内的任意时刻。任何超过最近七天的数据库备份将被标记为obsolete。
第二种redundancy 是为了保持可以恢复的最新的5份数据库备份,任何超过最新5份的备份都将被标记为redundancy。它的默认值是1份。
第三种不需要保持策略,clear将恢复回默认的保持策略。
一般最安全的方法是采用第二种保持策略。
2.CONFIGURE BACKUP OPTIMIZATION OFF
默认值为关闭,如果打开,rman将对备份的数据文件及归档等文件进行一种优化的算法。
3.Configure default device type to disk:
是指定所有I/O操作的设备类型是硬盘或者磁带,默认值是硬盘
磁带的设置是CONFIGURE DEFAULT DEVICE TYPE TO SBT;
默认值为关闭,如果打开,rman将对备份的数据文件及归档等文件进行一种优化的算法。
3.Configure default device type to disk:
是指定所有I/O操作的设备类型是硬盘或者磁带,默认值是硬盘
磁带的设置是CONFIGURE DEFAULT DEVICE TYPE TO SBT;
4.CONFIGURE CONTROLFILE AUTOBACKUP OFF
强制数据库在备份文件或者执行改变数据库结构的命令之后将控制文件自动备份,默认值为关闭。这样可以避免控制文件和catalog丢失后,控制文件仍然可以恢复。
强制数据库在备份文件或者执行改变数据库结构的命令之后将控制文件自动备份,默认值为关闭。这样可以避免控制文件和catalog丢失后,控制文件仍然可以恢复。
5.CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'
是配置控制文件的备份路径和备份格式
是配置控制文件的备份路径和备份格式
6.CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
是配置数据库设备类型的并行度。
是配置数据库设备类型的并行度。
7.CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
是配置数据库的每次备份的copy数量,oracle的每一次备份都可以有多份完全相同的拷贝。
是配置数据库的每次备份的copy数量,oracle的每一次备份都可以有多份完全相同的拷贝。
8.CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1
是设置数据库的归档日志的存放设备类型
是设置数据库的归档日志的存放设备类型
9.CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'C:ORACLE… SNCFTEST.ORA'
是配置控制文件的快照文件的存放路径和文件名,这个快照文件是在备份期间产生的,用于控制文件的读一致性。
是配置控制文件的快照文件的存放路径和文件名,这个快照文件是在备份期间产生的,用于控制文件的读一致性。
10.CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT 'C:...%d_DB_%u_%s_%p';
是配置备份文件的备份路径和备份格式
是配置备份文件的备份路径和备份格式
CONFIGURE CHANNEL DISK CLEAR; 用于清除上面的信道配置
CONFIGURE EXCLUDE FOR TABLESPACE <tablespace> [CLEAR]; 此命令用于将指定的表空间不备份到备份集中, 此命令对只读表空间是非常有用的。
1.将备份文件存储到指定路径,如 e:ackupb
configure channel device type disk format 'e:ackupb\%d_db_%u';
后面的%d_db_%u是存储格式
2.我们也可以单独指定control file 存储在另一个路径:如 e:ackupcontrol
configure controlfile autobackup format for device type disk to 'e:ackupcontrol\%F';
1.将备份文件存储到指定路径,如 e:ackupb
configure channel device type disk format 'e:ackupb\%d_db_%u';
后面的%d_db_%u是存储格式
2.我们也可以单独指定control file 存储在另一个路径:如 e:ackupcontrol
configure controlfile autobackup format for device type disk to 'e:ackupcontrol\%F';
后面的%F是存储格式
================
RMAN中常用configure命令2007-06-21 15:37
1 显示当前的配置信息
===========================
1.01 RMAN> show all;
1.02 查询RMAN设置中非默认值:
SQL> select name,value from v$rman_configure;
2. 常用的configure选项
===========================
2.01 保存策略 (retention policy)
configure retention policy to recovery window of 3 days;
configure retention policy to redundancy 3;
configure retention policy clear;
2.02 备份优化 backup optimization
configure backup optimization on;
configure backup optimization off;
configure backup optimization clear;
2.03 默认设备 default device type
configure default device type to disk;
configure default device type to stb;
configure default device type clear;
2.04 控制文件 controlfile
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/cfs01/backup/conf/conf_%F';
configure controlfile autobackup clear;
configrue controlfile autobackup format for device type disk clear;
configrue snapshot controlfile name to '/cfs01/backup/snapcf/scontrofile.snp';
configrue snapshot controlfile name clear;
2.05 并行数(通道数) device type disk|stb pallelism n;
configure device type disk|stb parallelism 2;
configure device type disk|stb clear;
configure channel device type disk format 'e/:rmanback_%U';
configure channel device type disk maxpiecesize 100m
configure channel device type disk rate 1200K
configure channel 1 device type disk format 'e/:rmanback_%U';
configure channel 2 device type disk format 'e/:rmanback_%U';
configure channel 1 device type disk maxpiecesize 100m
2.06 生成备份副本 datafile|archivelog backup copies
configure datafile backup copies for device type disk|stb to 3;
configure archivelog backup copies for device type disk|stb to 3;
configure datafile|archivelog backup copies for device type disk|stb clear
BACKUP DEVICE TYPE DISK DATABASE
FORMAT '/disk1/backup/%U', '/disk2/backup/%U', '/disk3/backup/%U';
2.07 排除选项 exclude
configure exclude for tablespace 'users';
configrue exclude clear;
2.08 备份集大小 maxsetsize
configure maxsetsize to 1G|1000M|1000000K|unlimited;
configure maxsetsize clear;
2.09 其它选项 auxiliary
CONFIGURE AUXNAME FOR DATAFILE 1 TO '/oracle/auxfiles/aux_1.f';
CONFIGURE AUXNAME FOR DATAFILE 2 TO '/oracle/auxfiles/aux_2.f';
CONFIGURE AUXNAME FOR DATAFILE 3 TO '/oracle/auxfiles/aux_3.f';
CONFIGURE AUXNAME FOR DATAFILE 4 TO '/oracle/auxfiles/aux_4.f';
-
CONFIGURE AUXNAME FOR DATAFILE 1 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 2 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 3 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 4 CLEAR;
Rman的format格式中的%
%c 备份片的拷贝数
%d 数据库名称
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,YYYYMMDD为
日期,QQ是一个1-256的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)
一周内把所有的命令测试后记录如下(2010.08.24):
RMAN组件
1、目标数据库
2、服务器进程
3、通道
4、RMAN资料库
ORACLE总是将RMAN元数据放到目标数据库的控制文件中,如果配置了恢复目录,则RMAN元数据会被放到恢复目录中。
5、恢复目录
在RMAN元数据存放天数达到初始化参数control_file_record_keep_time的值之后,其元数据可能会被覆盖,从而导致之前的备份不能使用。
6、介质管理层
7、RMAN包
包dbms_backup_restore用于执行备份、转储和恢复操作。backup、copy、restore、recover
包dbms_revcat用于维护恢复目录。resync catalog、catalog
包dbms_rcvman用于查询恢复目录和目标数据库控制文件。list、report
RMAN特点
1、备份数据库、表空间、数据文件、控制文件、归档日志和SPFILE。目标库必须处于MOUNT状态或OPEN状态。
2、存储频繁执行的备份和恢复操作。放到脚本中执行
3、跳过未用块。
4、执行增量块级备份
5、指定备份限制
6、在备份时检测损坏块。用DBVERIFY工具进行检查
7、自动使用并行化特征提高备份和恢复性能。分配多个CPU、多个通道。
RMAN命令
1、独立命令
RMAN>shutdown immediate
RMAN>startup
RMAN>backup format 'd:ackup\%d_%s.bak' tablespace users;
2、作业命令
RMAN>run { backup format 'd:ackup$d_%s.bak' tablespace users; }
3、运行SQL命令
RMAN>sql 'alter system switch logfile' ;
4、运行存储脚本
RMAN>run { execute script s1;}
5、运行操作系统命令
RMAN>run { host "dir d:ackup"; }
6、运行RMAN命令
c: man target sys/oracle@TEST nocatalog @c:ak_users.cmd log a.log
bak_users.cmd示例:
backup format 'd:ackup\%d_%s.bak tablespace users;
sql 'alter system archive log current' ;
配置RMAN环境(略)
建立备份集
1、完全数据库备份集
1)、一致性备份(适用于NOARCHIVELOG和ARCHIVELOG模式)
c: man target sys/oracle@TEST nocatalog
RMAN>shutdown immediate
RMAN>startup mout
RMAN>backup database; 如果备份到别的目录backup database format ='d:ackup\%d_%s.dbf' ;
RMAN>sql 'alter system archive log current ' ;
2)、非一致性备份(在OPEN状态)
RMAN>backup database; 如果备份到别的目录backup database format ='d:ackup\%d_%s.dbf' ;
RMAN>sql 'alter system archive log current ' ;
3)、免除表空间
RMAN>configure exclude for tablespace user03;
RMAN>backup database; 如果备份到别的目录backup database format ='d:ackup\%d_%s.dbf' ;
RMAN>sql 'alter system archive log current ' ;
2、表空间备份集
RMAN>backup tablespace users format='d:ackup\%N_%f_%s.dbf' ;
3、数据文件备份集
RMAN>backup datafile 5 format='d:ackup\%N_%f_%s.dbf' ;
4、控制文件备份集
RMAN>backup current controlfile format='d:ackup\%d_%s.ctl' ;
5、SPFILE备份集
RMAN>backup spfile format='c:\%d_%s.par';
6、归档日志备份集(过去一天所生成的归档日志)
RMAN>backup format='c:\%d_%s.arc' archivelog from time='sysdate-1' until time='sysdate';
7、并行化备份集
RMAN>configure device type disk parallelism 3 ;
RMAN>backup database format='c:\%d_%s.dbf';
RMAN>configure device type disk clear;
8、建立多重备份
RMAN>backup copied 3 tablespace users format='c:1\%N_%s.dbf','c:2\%N_%s.dbf','c:3\%N_%s.dbf' ;
9、备份备份集
RMAN>backup backupset 32 format='c:\%d_%s.bak';
10、建立多个备份片
RMAN>configure channel device type sbt maxpiecesize 4G;
RMAN>backup device type sbt format '%d_%s_%p.dbf' database;
11、建立压缩备份集
RMAN>backup as compressed backupset tablespace users format='c:\%d_%s.dbf';
12、备份数据文件和归档日志
RMAN>backup format 'c:\%d_%s.bak' tablespace users plus archivelog ;
13、指定备份集标记
RMAN>backup format='c:\%d_%s.bak' tablespace users tag='users' ;
建立映像副本
1、建立数据文件映像副本
RMAN>backup as copy format='c:df_5.dbf' datafile 5; 或者
RMAN>copy datafile 5 to 'c:df_5.dbf' ;
2、建立控制文件映像副本
RMAN>backup as copy format='c:demo.ctl' current controlfile; 或者
RMAN>copy current controlfile to 'c:demo.ctl';
3、建立归档日志映像副本
RMAN>backup as copy format='c:arc10.log' archivelog sequence 10; 或者
RMAN>copy archivelog 'c:demoarchivearc00020_012345.001' to 'c:arc20.log';
4、并行化建立映像副本
RMAN>configure device type disk parallelism 3;
RMAN>backup as copy format ='c:df_%f.dbf' datafile 5,6,7 ;
RMAN>configure device type disk clear;
5、指定映像副本标记
RMAN>backup as copy format='c:df_%f.dbf' datafile 5 tag=df_5; 或者
RMAN>copy datafile 5 to 'c:df_%f.dbf' tag=df_5;
建立增量备份和累积备份
增量备份可以减少备份时间,累积备份可以减少恢复时间。
增量备份示例:周日 LEVEL 0 ,周一、周二、周四、、周五、周六 LEVEL 2 ,周三 LEVEL 1
RMAN>backup incremental level 0 format='c:ackup\%d_%s.dbf' tablespace users; 周日
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周一
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周二
RMAN>backup incremental level 1 format='c:ackup\%d_%s.dbf' tablespace users; 周三
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周四
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周五
RMAN>backup incremental level 2 format='c:ackup\%d_%s.dbf' tablespace users; 周六
RMAN完全恢复
1、恢复数据库
1)、所有数据文件被删除
c: man target sys/oracel@test nocatalog
RMAN>startup force mount
RMAN> run {
restore databse ;
recover database;
sql 'alter database open' ;
}
2)、数据文件所在磁盘出现硬件故障
RMAN> run {
startup force mount;
set newname for datafile 1 to 'c:demosystem01.dbf';
set newname for datafile 2 to 'c:demodundotbs01.dbf';
set newname for datafile 3 to 'c:demosysaux01.dbf';
set newname for datafile 4 to 'c:demousers01.dbf';
set newname for datafile 5 to 'c:demoexample01.dbf';
set newname for datafile 6 to 'c:demo est0.dbf';
restore database;
switch datafile all;
recover database;
sql 'alter database open ';
}
2、恢复SYSTEM表空间的数据文件
1)、SYSTEM表空间的数据文件被误删除
RMAN>run {
startup force mount;
restore datafile 1;
recover datafile 1;
sql 'alter database open' ;
}
2)、SYSTEM表空间数据文件所在的磁盘出现故障
RMAN> run {
startup force mount;
set newname for datafile 1 to 'c:demosystem01.dbf';
restore datafile 1;
switch datafile 1;
recover datafile 1;
sql 'alter database open';
}
3、在OPEN状态下恢复关闭后意外丢失数据文件
1)、数据文件被删除
RMAN>run {
startup force mount;
sql 'alter database datafile 4 offline';
sql 'alter database open ';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
2)、数据文件所在的磁盘出现损坏
RMAN>run {
startup force mount;
sql 'alter database datafile 4 offline';
sql 'alter database open ';
set newname for datafile 4 to 'c:demouser01.dbf';
restore datafile 4;
switch datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
4、在OPEN状态下恢复打开时意外丢失的数据文件
1)、数据文件被误删除
RMAN>run {
sql 'alter database datafile 4 offline';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
2)、数据文件所在磁盘出现故障
RMAN>run {
sql 'alter database datafile 4 offline';
set newname for datafile 4 to 'c:demouser01.dbf';
restore datafile 4;
switch datafile 4 ;
recover datafile 4;
sql 'alter database datafile 4 online';
}
5、在OPEN状态下恢复未备份的数据文件(创造新数据文件后没有进行过备份)
1)、数据文件被误
RMAN>run {
startup force mount;
sql 'alter database datafile 7 offline ';
sql 'alter database open';
restore datafile 7;
recover datafile 7;
sql 'alter database datafile 7 online';
}
2)、数据文件所在磁盘出现故障
RMAN>run {
startup force mount;
sql 'alter database datafile 7 offline ';
sql 'alter database open';
set newname for datafile 7 to 'c:demouser04.dbf';
restore datafile 7;
switch datafile 7;
recover datafile 7;
sql 'alter database datafile 7 online';
}
6、恢复表空间
1)、表空间被删除
RMAN>run {
sql 'alter tablespace users offline for recover';
restore tablespace users;
recover tablespace users;
sql 'alter tablespace users online';
}
2)、表空间的数据文件所在磁盘出现故障
RMAN>run {
sql 'alter tablespace users offline for recover';
set newname for datafile 4 to 'c:demouser01.dbf';
restore tablespace users;
switch tablespace users;
recover tablespace users;
sql 'alter tablespace users online';
}
7、数据块介质恢复
RMAN>blockrecover device type disk datafile 5 block 20,21,100 ;
RMAN不完全恢复
1、基本时间恢复
c:set nls_date_format=yyyy-dd-mm hh24:mi:ss
c: man target sys/oracle@test nocatalog
RMAN>run {
startup force mount;
set until time='2010-08-22 12:00:08';
restore database;
recover database;
sql 'alter database open resetlogs;
}
2、基于SCN恢复
RMAN>run {
startup force mount;
set until scn=123456;
restore database;
recover database;
sql 'alter database open resetlogs';
}
3、基于日志序列号恢复
RMAN>run {
startup force mount;
set until seqence=10;
restore database;
recover database;
sql 'alter database open resetlogs';
}
4、基于备份控制文件恢复
c:set nls_date_format=yyyy-dd-mm hh24:mi:ss
c: man target sys/oracle@test nocatalog
RMAN>startup force nomount;
RMAN>set dbid=1113606269;
RMAN>restore controlfile from autobackup maxseq 6;
RMAN>alter database mount;
RMAN>run {
set until time='2010-08-22 12:00:08';
restore database;
recover database;
sql 'alter database open resetlogs;
}
当执行了上述4种不完全恢复之后,建议删除早期的所有备份,并重新备份数据库
RMAN>run {
delete noprompt backup;
delete noprompt copy;
backup database format='c:ackup\%d_%s.bak';
sql 'alter system archive log current';
}
RMAN维护命令
REPORT
1、报告目标数据库的物理结构
RMAN>report schema;
2、报告需要备份的数据文件
1)、报告需要转储的增量备份超出特定个数的数据文件
RMAN> report need backup incremental 3;
2)、报告特定天数未备份的数据文件
RMAN>report need backup days 3 tablespace users ;
3)、报告低于特定备份次数的数据文件
RMAN> report need backup redundancy 2 database ;
4)、报告在恢复时间窗口内未备份的数据文件
RMAN> report need backup recovery window of 3 days ;
3、报告陈旧备份
RMAN>report obsolete redundancy 2;
4、报告不可恢复的数据文件
RMAN>report unrecoverable;
LIST
1、列出数据文件备份集
RMAN>list backup of database ;
RMAN>list backup of tablespace users;
RMAN>list backup of datafile 4;
2、列出控制文件备份集
RMAN>list backup of controlfile ;
3、列出归档日志备份集
RMAN>list backup of archivelog all;
4、列出SPFILE备份集
RMAN>list backup of spfile ;
5、列出数据文件映像副本
RMAN>list copy of database;
RMAN>list copy of tablespace users;
RMAN>list copy of datafile 4;
6、列出控制文件映像副本
RMAN>list copy of controlfile;
7、列出归档日志映像副本
RMAN>list copy of archivelog all;
8、列出数据库副本
RMAN>list incarnation of database ;
注意,每次用RESETLOGS选项打开数据库之后都会生成一个新的数据库副本。
9、列出备份集文件的信息
RMAN>list backupset 100;
CROSSCHECK
1、核对所有备份集
RMAN>crosscheck backup;
2、核对所有数据文件的备份集
RMAN>crosscheck backup of database ;
3、核对特定表空间的备
RMAN>crosscheck backup of tablespace system;
4、核对特定数据文件的备份集
RMAN>crosscheck backup of datafile 1;
5、核对控制文件的备份集
RMAN>crosscheck backup of controlfile ;
6、核对SPFILE的备份集
RMAN> crosscheck backup of spfile;
7、核对归档日志的备份集
RMAN> crosscheck backup of archivelog sequence 40;
8、核对所有映像副本
RMAN> crosscheck copy ;
9、核对所有数据文件的映像副本
RMAN> crosscheck copy of database;
10、核对特定表空间的映像副本
RMAN> crosscheck copy of tablespace users;
11、核对特定数据文件的映像副本
RMAN> crosscheck copy of datafile 1;
12、核对控制文件的映像副本
RMAN> crosscheck copy of controlfile;
13、核对归档日志的映像副本
RMAN> crosscheck copy of archivelog sequence 44;
DELETE
1、删除陈旧备份
delete obsolete; #提示
delete noprompt obsolete; #不提示
2、删除EXPIRED备份集
delete noprompt expired backup;
3、删除EXPIRED副本
delete noprompt expired copy ;
4、删除特定备份集
delete noprompt backupset 19;
5、删除特定备份片
delete noprompt backuppiece 'c: estdemo1.bak';
6、删除所有备份集
delete noprompt backup ; 或者
delete noprompt backupset;
7、删除特定映像副本
delete noprompt datafilecopy 'c: estdemo.bak'; 删除数据文件
delete noprompt controlfilecopy 'c: estcontrolfile_bak.ctl'; 删除控制文件
delete noprompt archivelog 'c: estarc.bak'; 删除归档日志
8、删除所有映像副本
delete noprompt copy;
9、在备份后删除输入对象
backup archivelog all delete input ;
backup backupset 22 format='c: est\%u.bak' delete input ;
CHANGE
1、改变备份集状态
change backupset 22 unavailable;
2、改变映像副本状态
change datafilecopy 'c:demo.bak' unavailable ;
change controlfilecopy 'c:demo.bak' unavailable ;
change archivelog 'c:demo.bak' unavailable ;
3、建立长期备份
change backupset 100 keep forver logs; 使备份集100永久保留
change backupset 100 keep until time 'sysdate+60' logs; 使备份集100保留60天
change backupset 156 nokeep ; 免除备份集100的保留期限
CATALOG
1、注册副本
catalog datafilecopy 'c:user01.bak';
2、注册备份片
catalog backuppiece 'c:demo_10.dbf' ;
3、注册特定目录的所有备份文件
catalog start with 'c:ak';
4、注销备份记录
change datafilecopy 'c:user01.bak' uncatalog;
change controlfilecopy 'c:demo.ctl' uncatalog;
change backuppiece 'c:demo_10.bak' uncatalog;
恢复目录管理
建立恢复目录
1、建立恢复目录表空间
SQL> create tablespace rman_ts
2 datafile 'D:oracleproduct10.1.0db_1 rain man.dbf'
3 size 15m ;
表空间已创建。
2、建立恢复目录所有者
SQL> create user rman identified by rman
2 default tablespace rman_ts;
用户已创建。
3、授予恢复目录所有者角色
SQL> grant connect,resource,recovery_catalog_owner to rman;
授权成功。
4、建立恢复目录
c: man catalog rman/rman@train
RMAN>create catalog;
5、注册目标数据库
RMAN>connect target sys/oracle@train
RMAN>register database;
RMAN>report schema;
使用存储脚本
1、建立存储脚本
C:>rman catalog rman/rman@train target sys/dddddd@train
RMAN>create script bak_database {
backup format='c: emp\%d_%s.bak'
database include current controlfile
plus archivelog;
sql 'alter system archive log current' ;
}
2、运行脚本
(1)、在RMAN提示符下运行存储脚本
RMAN>run { execute script bak_database; }
(2)、在命令行运行存储脚本
c: man catalog rman/rman@train target sys/dddddd@train script bak_database
3、显示存储脚本内容
RMAN>print script bak_database;
4、替换存储脚本
RMAN>replace script bak_database {
backup database format='c: emp\%d_%s.bak';
}
5、删除存储脚本
RMAN>delete script bak_database;
6、列出所有存储脚本
RMAN>list script names;
维护恢复目录
1、重新同步恢复目录
RMAN> resync catalog;
2、注销目标数据库
RMAN>unregister database;
当注销了目标数据库之后,会丢失早于controlfile_record_keep_time设置时间的RMAN资料库记录。
3、升级恢复目录
C:>rman catalog rman/rman@train target sys/dddddd@train
RMAN> upgrade catalog;
RMAN> upgrade catalog;
4、删除恢复目录
C:>rman catalog rman/rman@train target sys/dddddd@train
RMAN> drop catalog ;
RMAN> drop catalog ;
5、恢复数据库到早期数据库副本