Oracle 备份与恢复学习笔记(7)

第七章:RMAN

1、rman的定义和功能:
      1) Recovery Manager
      2)通过oracle 提供的包,建立备份和恢复的server process,在oracle server 上做备份和恢复
      3)rman 备份 database、tablespace、datafile、controlfile、spfile、archivelog
      4)支持归档和非归档
      5)在归档模式下支持一致性备份(冷备份)和非一致性备份(热备份)
      6)非归档只支持一致性备份
     
2、rman的优点:
       1)只备份数据文件中已经使用过的block(备份segment高水位线以下的block),节省空间
       2)备份时自动检查数据文件是否有坏块,并可以标记坏块,跳过坏块
       3)可以实现增量备份
       4)备份和恢复都是用rman的命令来完成

3、rman的架构:

    1)target  database:需要做备份的生产库
   
    2)存储设备:disk 、tape (sbt 磁带机)存放备份文件的设备
   
    3)channel :目标库和存储设备之间备份通道(服务进程)默认最少启动一个channel,可同时启动多个channel ,并发操作,加快备份和恢复的速度
   
    4)server process:用于备份和恢复
   
    5)rman备份的元数据:记录备份的信息(一般放在目标库的controlfile 里)
   
    6)catalog database :集中管理、存放备份的元数据,还可以存储备份脚本
   
    7} MML:media manage layer 介质管理层:用于管理磁带机的库文件或驱动

4、rman 链接目标库
          1) $ORACLE_SID 和目标库一致
[oracle@work ~]$ env |grep SID
ORACLE_SID=prod
[oracle@work ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Aug 18 05:06:08 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: PROD (DBID=170319990)

RMAN>
[oracle@work ~]$ rman

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Aug 18 05:10:11 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

RMAN> connect target /                                                                                                                  

connected to target database: PROD (DBID=170319990)

RMAN>

2)远程连接
1)在target database 启动listeners ,在client配置tnsnames
C:\Documents and Settings\liqx>rman target sys/oracle@prod

恢复管理器: Release 10.2.0.1.0 - Production on 星期四 8月 18 09:51:24 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

连接到目标数据库: PROD (DBID=170319990)

RMAN>

5、查看rman的默认配置,修改rman的配置信息
    1)查看rman的默认配置
   
RMAN> show all;                                                                                                                         

using target database control file instead of recovery catalog
RMAN configuration parameters are:
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 BACKUP TYPE TO BACKUPSET; # 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 ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_prod.f'; # default

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP  on;                                                                                             

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

------off:默认情况下,在备份system 表空间时,会备份控制文件和spfile
      on: 在做任何文件的备份时,会自动备份控制文件和spfile,并且数据库的物理结构发生变化时,也自动备份controlfile。
     
     
 2)format 指明备份文件的路径和文件名
 RMAN备份文件格式
备份文件可以自定义各种各样的格式,如下:

%c 备份片的拷贝数
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID 唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,
%d 数据库名称其中IIIIIIIIII 为该数据库的DBID,YYYYMMDD 为日期,QQ 是一个1-256 的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1 开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)

6、rman备份的分类:
     1)backupset:只备份datafile里已经使用过的块(HWM以下)、可以实现增量备份(可以备份到disk和tape)。如果只启用一个channel,默认会把所有备份的datafile放入到一个backupset里
     ,并且生成一个备份片(backup piece,在OS下看到的备份文件)
     2)backup piece :由backupset 生成的备份文件,保存在os下
     3) copy(snapshot 镜像):实际上和手工cp 是类似的,备份datafile 所有的数据块,不能实现增量备份(但可以作为增量备份的0级备份),只能备份到disk ,不能备份到tape,
        恢复时速度快     

6、rman的命令格式:
    1)交互式
RMAN> shutdown immediate;                                                                                                               

database closed
database dismounted
Oracle instance shut down

RMAN> startup force mount;                                                                                                              

Oracle instance started
database mounted

Total System Global Area     314572800 bytes

Fixed Size                     1219184 bytes
Variable Size                 67110288 bytes
Database Buffers             243269632 bytes
Redo Buffers                   2973696 bytes

RMAN> alter database open;                                                                                                              

database opened

RMAN> sql 'alter system switch logfile';                                                                                                

sql statement: alter system switch logfile

RMAN> sql 'select * from scott.emp';                                                                                                    

sql statement: select * from scott.emp
---------对select 不显示结果

RMAN> backup datafile 2 format '/disk1/rman/prod/%d_%s_%t.bak';                                                                         

Starting backup at 18-AUG-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=139 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00002 name=/u01/app/oracle/oradata/prod/users01.dbf
channel ORA_DISK_1: starting piece 1 at 18-AUG-11
channel ORA_DISK_1: finished piece 1 at 18-AUG-11
piece handle=/disk1/rman/prod/PROD_2_759476271.bak tag=TAG20110818T053751 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 18-AUG-11

RMAN> list backup;                                                                                                                      


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    464.00K    DISK        00:00:03     18-AUG-11     
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20110818T053751
        Piece Name: /disk1/rman/prod/PROD_2_759476271.bak
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  2       Full 1316126    18-AUG-11 /u01/app/oracle/oradata/prod/users01.dbf
 
  -----备份片的大小为464k ,只包含已经使用的block

RMAN>
    2)批处理
RMAN> run {                                                                                                                             
2> shutdown immediate;                                                                                                                  
3> startup mount;                                                                                                                       
4> allocate channel c1 type disk;                                                                                                       
5> allocate channel c2 type disk;                                                                                                       
6> backup database format '/disk1/rman/prod/%d_%s.bak';                                                                                 
7> alter database open;                                                                                                                 
8> }                                                                                                                                    
 

你可能感兴趣的:(oracle,oracle,职场,study,休闲)