Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1114667
  • 博文数量: 227
  • 博客积分: 6860
  • 博客等级: 准将
  • 技术积分: 2688
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-02 16:06
文章分类

全部博文(227)

文章存档

2015年(7)

2014年(8)

2012年(5)

2011年(62)

2010年(145)

分类: Oracle

2010-09-09 14:29:36

1、连接到目标数据库(不用恢复目录数据库):
      Rman nocatalog target

      Rman catalog target
2、SHOW命令:
      显示rman配置: RMAN> show all;
3、REPORT命令:
   1、RMAN> report schema                        报告目标数据库的物理结构;
   2、RMAN>report need backup days=3;            报告最近3天没有被备份的数据文件;
   3、RMAN> report need backup days 3 tablespace users;   在USERS表空间上3天未备份的数据文件;
   4、RMAN> report need backup incremental 3;   报告恢复数据文件需要的增量备份个数超过3次的数据文件;
   5、RMAN> report need backup redundancy 2 database;           报告备份文件低于2份的所有数据文件;
             RMAN>report need backup redundancy=2;
   6、RMAN> report need backup recovery window of 6 days;     报告文件报表的恢复需要超过6天的归档日志的数据文件;
   7、RMAN> report unrecoverable;               报告数据库所有不可恢复的数据文件;
   8、RMAN> report obsolete redunndancy 2; 报告备份次数超过2次的陈旧备份;
   9、RMAN>report obsolete;                       报告丢弃的备份;
4、LIST命令:列出备份信息
   1、列出数据文件备份集
     RMAN> list backup         列出详细备份;
     RMAN> list expired backup     列出过期备份;
     RMAN> list backup of database;     列出所有数据文件的备份集;
     RMAN> list backup of tablespace user01; 列出特定表空间的所有数据文件备份集;
   2、RMAN> list backup of controlfile     列出控制文件备份集;
   3、RMAN> list backup of archivelog all      列出归档日志备份集详细信息;
        RMAN>list archivelog all;      列出归档日志备份集简要信息
   4、RMAN> list backup of spfile              列出SPFILE备份集;
   5、RMAN> list copy of datafile 5        列出数据文件映像副本;
   6、RMAN> list copy of controlfile           列出控制文件映像副本;
   7、RMAN> list copy of archivelog all    列出归档日志映像副本;
   8、RMAN> list incarnation of database       列出对应物/列出数据库副本;
   9、RMAN>list backup summary;    概述可用的备份;
        B表示backup
       F表示FULL
        A表示archive log
      0 1表示incremental backup
      S说明备份状态(A AVAILABLE   X EXPIRED )
      10、RMAN>list backup by file    按备份类型列出备份;
                    按照数据文件备份,归档日志备份,控制文件备份,服务器参数文件备份 列出
5、CROSSCHECK命令:校验备份信息
   1、RMAN> crosscheck backup             核对所有备份集;  
   2、RMAN> crosscheck backup of database      核对所有数据文件的备份集;  
   3、RMAN> crosscheck backup of tablespace users      核对特定表空间的备份集;  
   4、RMAN> crosscheck backup of datafile 4    核对特定数据文件的备份集;   
   5、RMAN> crosscheck backup of controlfile   核对控制文件的备份集;   
   6、RMAN> crosscheck backup of spfile    核对SPFILE的备份集;  
   7、RMAN> crosscheck backup of archivelog sequence 3 核对归档日志的备份集;  
   8、RMAN> crosscheck copy               核对所有映像副本;  
   9、RMAN> crosscheck copy of database       核对所有数据文件的映像副本;  
   10、RMAN> crosscheck copy of tablespace users       核对特定表空间的映像副本;   
   11、RMAN> crosscheck copy of datafile 6        核对特定数据文件的映像副本;  
   12、RMAN> crosscheck copy of archivelog sequence 4  核对归档日志的映像副本;  
   13、RMAN> crosscheck copy of controlfile       核对控制文件的映像副本; 
   14、RMAN> crosscheck backup tag='SAT_BACKUP';
   15、RMAN> crosscheck backup completed after 'sysdate - 2'
   16、RMAN> crosscheck backup completed between 'sysdate - 5' and 'sysdate -2 '
   17、RMAN> crosscheck backup device type sBT;
   18、RMAN> crosscheck archivelog all;
   19、RMAN> crosscheck archivelog like '%ARC00012.001'
   20、RMAN> crosscheck archivelog from sequence 12;
   21、RMAN> crosscheck archivelog until sequence 522;
6、DELETE:删除备份
   1、RMAN> delete obsolete;      删除陈旧备份;
   2、RMAN> delete expired backup; 删除EXPIRED备份    
   3、RMAN> delete expired copy;   删除EXPIRED副本;
   4、RMAN> delete backupset 19;   删除特定备份集;
   5、RMAN> delete backuppiece ''d:\backup\DEMO_19.bak''   删除特定备份片;
   6、RMAN> delete backup      删除所有备份集;
   7、RMAN> delete datafilecopy ''d:\backup\DEMO_19.bak''  删除特定映像副本;
   8、RMAN> delete copy   删除所有映像副本;
   9、RMAN> delete archivelog all delete input;
        RMAN> delete backupset 22 format = ''d:\backup\%u.bak'' delete input
                       在备份后删除输入对象;
   10、RMAN> delete backupset id;
7、CHANGE命令:改变备份集的状态
   1、RMAN> change backupset 22 unavailable      改变备份集状态;   
   2、RMAN> change datafilecopy ''d:\backup\demo_37.bak'' unavailable     改变映像副本状态;
   3、RMAN> change backupset 156 keep forever logs         使备份集156永久保留;
   4、RMAN> change backupset 198 keep until ''sysdate+60'' logs       使备份集198保留60天;
   5、RMAN> change backupset 156 nokeep         免除备份集156的保留期限;
   6、change backupset 117,118 delete;
   7、change backuppiece 1304 delete;
   8、change archivelog until logseq =544 delete;
8、CONFIGURE命令
   1显示当前的配置信息
      1.01 RMAN> show all;
      1.02查询RMAN设置中非默认值: 
     SQL> select name,value from v$rman_configuration;
    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 parallelism 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 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;

9、CATALOG命令   用于追加备份记录到RMAN资料库中。
    1、RMAN> catalog datafilecopy ''d:\backup\user01.bak'';
      RMAN>catalog controlfile ''d:\backup\demo.ctl'';
      RMAN> catalog archivelog ''d:\backup\demo_25.bak'';
    注册副本;
    2、RMAN> catalog backuppiece ''d:\backup\demo_40.dbf''        注册备份片;
    3、RMAN> catalog start with ''d:\bak''         注册特定目录的所有备份文件;
    4、RMAN> change datafilecopy ''d:\bak\user01.bak'' uncatalog;
        RMAN> change controlfilecopy ''d:\bak\demo.ctl'' uncatalog;
        RMAN> change backuppiece ''d:\bak\demo_25.bak'' uncatalog;
        注销备份记录
10、FORMAT字符串替代变量:
    使用FORMAT参数时可使用的各种替换变量,如下:
      %d:数据库名称;
      %D:位于该月中的天数(DD);
      %M:位于该年中的月份(MM);
      %F:一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,
      YYYYMMDD为日期,QQ是一个1-256的序列;
      %n:数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8;
      %u:是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称;
      %p:表示备份集中备份片段的编号,从1开始编号;
      %c:备份片的拷贝数(从1开始编号);
      %U:是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,
       这是最常用的命名方式;
      %s:备份集的号;
      %t:备份集时间戳;
      %T:年月日格式(YYYYMMDD);s
           注:如果在BACKUP命令中没有指定FORMAT选项,则RMAN默认使用%U为备份片段命名。
11、validate命令
      1、validate命令验证备份集片是否能够被还原;
      2、list backup summary;得到了备份集得主键ID如40,然后validate backupset 40;
12、恢复目录的记录删除
         1. $Oracle_HOME/rdbms/admin/prgrmanc.sql脚本定期删除恢复目录中具有DELETED状态的记录
         2.要删除旧的对应物记录incarnation.必须从DBINC表中删除这些对应物,
        使用RC_DATABASE_INCARNATION视图来确定要删除的对应物。记录要删除的每个对应物的DBINC_KEY,
    随后启动SQL*Plus,执行delete from dbinc where dbinc_key=2;
13、手工同步恢复目录:resync catalog;
14、在RMAN中存储脚本
    1,连接到目标数据库和恢复目录
    2,创建脚本
      RMAN>create script. my_bk_script
        2>{backup database plus archivelog;}
    3,打印脚本
      RMAN>print script. my_bk_script;
    4,运行这个脚本,备份目标数据库
      RMAN>run {execute scipt my_bk_script;}
    5删除脚本
      RMAN>delete script. my_bk_script;
15、archivelog模式下的完全恢复
  step1:set oracle_sid=testdb
      rman target rman_user/password
      configure controlfile autobackup on;
  step2:backup database plus archivelog delete input;
  step3:shutdown immediate;
  step4:重命名所有的数据文件和控制文件,不重命名联机重做日志。
      step5: startup nomount;
     set DBID=****
     restore controlfile from autobackup;
     alter database mount;
  step6: restore database;
     recover database;
     alter database open resetlogs;
16、表空间恢复
  sql"alter tablespace users offline";
  sql"alter tablespace tools offline";
  restore tablespace users,tools;
  recover tablespace users,tools;
  sql"alter tablespace users online";
  sql"alter tablespace tools online";
17、数据文件恢复
sql"alter database datafile 3 offline";
  sql"alter database datafile 'd:oracleoradatausers01.dbf' offline";
  restore datafile 3
  restore datafile 'd:oracleoradatausers01.dbf';
  recover datafile 3
  recover datafile 'd:oracleoradatausers01.dbf';
  sql"alter database datafile 3 online";
  sql"alter database datafile 'd:oracleoradatausers01.dbf'online";
18、RMAN高级恢复
  1基于时间点的恢复
  run
  {
   set until time "to_date('07/01/02 15:00:00','mm/dd/yy hh24:mi:ss')"
   restore database;
   recover database;
   alter database open resetlogs;
 }
  2基于SCN的恢复
   startup mount;
   restore database UNTIL SCN 10000;
   recover database UNTIL SCN 10000;
  alter database open resetlogs;
  3基于日志序列的恢复
   startup mount;
   restore database UNTIL SEQUENCE 100 thread 1;
   recover database UNTIL SEQUENCE 100 thread 1;
   alter database open resetlogs;

阅读(642) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~