Oracle 培训笔记 9.4 rman

1、基本概念
RMAN:recover manager

备份集:backupset
备份片:默认一个备份集一个备份片,如果设置备份片大小,则一个备份集可能
有多个备份片

块级备份:只备份用过的数据块

备份信息记录
恢复目录:是独立的数据库
控制文件:可循环使用的和不可循环使用的
SQL> show parameter record
NAME                                 TYPE        VALUE
------------------------------------ ----------- -------------
control_file_record_keep_time        integer     7

数据库
target: 指要备份的数据库
catalog:恢复目录数据库,记录备份信息
auxiliary:辅助数据库,(dataguard,表空间不完全恢复)

2、rman配置
RMAN> show all;

2.1 备份信息保留策略
冗余: REDUNDANCY 1; 如果存在一次备份,再备份时,上个备份就是废弃的
时间: recovery window of 7 days;
RMAN> configure retention policy to recovery window of 7 days;
RMAN> configure retention policy clear;

run{
backup database;
delete obsolete;
}

2.2 优化模式
CONFIGURE BACKUP OPTIMIZATION on; //设成on,rman备份时可跳过不需重复备份的内容

RMAN> backup archivelog all;
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=11 recid=1 stamp=760976161
input archive log thread=1 sequence=12 recid=2 stamp=760976180

RMAN> backup archivelog all;

channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=11 recid=1 stamp=760976161
input archive log thread=1 sequence=12 recid=2 stamp=760976180
input archive log thread=1 sequence=13 recid=3 stamp=760976210

RMAN> CONFIGURE BACKUP OPTIMIZATION on;

RMAN> backup archivelog all;

skipping archive log file E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\ARCHIVELOG\2011_09_04\O1_MF_1_11_7665X0KL_.ARC; already
skipping archive log file E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\ARCHIVELOG\2011_09_04\O1_MF_1_12_7665XNN0_.ARC; already
skipping archive log file E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\ARCHIVELOG\2011_09_04\O1_MF_1_13_7665YL5C_.ARC; already
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=14 recid=4 stamp=760976258

2.3 设备类型
默认磁盘,也可设成磁带
RMAN>CONFIGURE DEFAULT DEVICE TYPE TO SBT;

rman> run{
allocate channel c1 device type sbt PARMS="SBT_LIBRARY=oracle.disksbt,ENV=(BACKUP_DIR=d:\)";
backup database;
}

2.4 控制文件自动备份
如果为off,当备份信息中含system表空间时,控制文件和参数文件会备份
如果为on,备份任何内容,控制文件和参数文件会备份,另外数据发生结构性变化时
也会备份

RMAN> backup tablespace users;  //没有备份控制文件
RMAN> backup tablespace system; //备份了控制文件

设置自动备份
RMAN> configure controlfile autobackup on;

RMAN> backup tablespace users;
Starting Control File and SPFILE Autobackup at 04-SEP-11
piece handle=E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF_S_760977070_7666SH0Z_.
Finished Control File and SPFILE Autobackup at 04-SEP-11

2.5 并行度
并行度决定分配通道数(服务器进程)
RMAN>CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; # default
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK

allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=154 devtype=DISK

2.6 备份集大小
备份集大小不能小于单个数据文件大小
CONFIGURE MAXSETSIZE TO UNLIMITED; # default

2.7 归档删除策略
CONFIGURE ARCHIVELOG DELETION POLICY TO ( APPLIED ON STANDBY | NONE | CLEAR )
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY to applied on standby;
这个设置并不是自动删除归档日志,而是删除的时候确认归档已经被DATA GUARD、
流环境等所应用。这个功能的目的是避免删除其他功能所需要的归档日志。
比如备份时候,backup database plus archivelog delete input时,避免某个归
档日志还没有被应用,但rman备份后就直接删除了。

3、备份
3.1 连接数据库
rman target /
rman target sys/1@remote
rman target / catalog u1/u1@other

3.2 备份
backup {database|tablespace xxx|datafile ###|archivelog all [delete input]}

RMAN> backup database;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
【注】channel对应一个服务器进程

channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\SYSTEM01.DBF
input datafile fno=00002 name=E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\UNDOTBS01.DBF
input datafile fno=00003 name=E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\SYSAUX01.DBF
input datafile fno=00004 name=E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\USERS01.DBF
【注】指定备份集中包含的数据文件

channel ORA_DISK_1: starting piece 1 at 04-SEP-11
channel ORA_DISK_1: finished piece 1 at 04-SEP-11
piece handle=E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_NNNDF_TAG20110904T140616_7665BS3X_.BKP
tag=TAG20110904T140616 comment=NONE
【注】备份片信息

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
【注】备份集结束



channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 04-SEP-11
channel ORA_DISK_1: finished piece 1 at 04-SEP-11
piece handle=E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_NCSNF_TAG20110904T140616_7665CMPG_.BKP
tag=TAG20110904T140616 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 04-SEP-11

3.3 查看备份
1)list
RMAN> list backup summary;
List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
32      B  F  A DISK        04-SEP-11       1       1       NO         TAG20110904T154109
33      B  F  A DISK        04-SEP-11       1       1       NO         TAG20110904T154134
34      B  A  A DISK        04-SEP-11       1       1       NO         TAG20110904T154218
35      B  F  A DISK        04-SEP-11       1       1       NO         TAG20110904T154220

RMAN> list backup  tag TAG20110904T154109;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
32      Full    351.80M    DISK        00:00:17     04-SEP-11
        BP Key: 32   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154109
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_N
  List of Datafiles in backup set 32
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 208250     04-SEP-11 E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\SYSTEM01.DBF
  2       Full 208250     04-SEP-11 E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\UNDOTBS01.DBF
  3       Full 208250     04-SEP-11 E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\SYSAUX01.DBF
  4       Full 208250     04-SEP-11 E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\USERS01.DBF

RMAN> list backup by file;


List of Datafile Backups
========================

File Key     TY LV S Ckp SCN    Ckp Time  #Pieces #Copies Compressed Tag
---- ------- -  -- - ---------- --------- ------- ------- ---------- ---
1    32      B  F  A 208250     04-SEP-11 1       1       NO         TAG20110904T154109
2    32      B  F  A 208250     04-SEP-11 1       1       NO         TAG20110904T154109
3    32      B  F  A 208250     04-SEP-11 1       1       NO         TAG20110904T154109
4    32      B  F  A 208250     04-SEP-11 1       1       NO         TAG20110904T154109

List of Archived Log Backups
============================

Thrd Seq     Low SCN    Low Time  BS Key  S #Pieces #Copies Compressed Tag
---- ------- ---------- --------- ------- - ------- ------- ---------- ---
1    16      204206     04-SEP-11 34      A 1       1       NO         TAG20110904T154218

List of Control File Backups
============================

CF Ckp SCN Ckp Time  BS Key  S #Pieces #Copies Compressed Tag
---------- --------- ------- - ------- ------- ---------- ---
208322     04-SEP-11 35      A 1       1       NO         TAG20110904T154220
208266     04-SEP-11 33      A 1       1       NO         TAG20110904T154134
List of SPFILE Backups
======================

Modification Time BS Key  S #Pieces #Copies Compressed Tag
----------------- ------- - ------- ------- ---------- ---
04-SEP-11         35      A 1       1       NO         TAG20110904T154220
04-SEP-11         33      A 1       1       NO         TAG20110904T154134

RMAN> list backup of tablespace users;


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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
32      Full    351.80M    DISK        00:00:17     04-SEP-11
        BP Key: 32   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154109
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_NNNDF_
  List of Datafiles in backup set 32
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 208250     04-SEP-11 E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\USERS01.DBF

RMAN> list backup of archivelog;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found ";": expecting one of: "all, from, high, like, logseq, low, scn, sequen
RMAN-01007: at line 1 column 26 file: standard input

RMAN> list backup of archivelog;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found ";": expecting one of: "all, from, high, like, logseq, low, scn, sequen
RMAN-01007: at line 1 column 26 file: standard input

RMAN> list backup of archivelog all;


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

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
34      3.94M      DISK        00:00:02     04-SEP-11
        BP Key: 34   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154218
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_ANNNN_

  List of Archived Logs in backup set 34
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    16      204206     04-SEP-11 208316     04-SEP-11

RMAN> list backup of controlfile;


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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
33      Full    6.80M      DISK        00:00:01     04-SEP-11
        BP Key: 33   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154134
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF_S_760
  Control File Included: Ckp SCN: 208266       Ckp time: 04-SEP-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
35      Full    6.80M      DISK        00:00:01     04-SEP-11
        BP Key: 35   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154220
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF_S_760
  Control File Included: Ckp SCN: 208322       Ckp time: 04-SEP-11

RMAN> list backup of spfile;


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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
33      Full    6.80M      DISK        00:00:01     04-SEP-11
        BP Key: 33   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154134
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF_S_760
  SPFILE Included: Modification time: 04-SEP-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
35      Full    6.80M      DISK        00:00:01     04-SEP-11
        BP Key: 35   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154220
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF_S_760
  SPFILE Included: Modification time: 04-SEP-11

RMAN> list backup of datafile 1;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
32      Full    351.80M    DISK        00:00:17     04-SEP-11
        BP Key: 32   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T154109
        Piece Name: E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_NNNDF_
  List of Datafiles in backup set 32
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 208250     04-SEP-11 E:\ORACLE\PRODUCT\10.2.0\ORADATA\MYDB\SYSTEM01.DBF

RMAN> list backup;

2)report
查看废弃备份
RMAN> report obsolete;
RMAN> backup database;
RMAN> backup tablespace users;

RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           37     04-SEP-11
  Backup Piece       37     04-SEP-11          E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF

RMAN> backup tablespace users;
RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           37     04-SEP-11
  Backup Piece       37     04-SEP-11          E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF
Backup Set           38     04-SEP-11
  Backup Piece       38     04-SEP-11          E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_
Backup Set           39     04-SEP-11
  Backup Piece       39     04-SEP-11          E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\AUTOBACKUP\2011_09_04\O1_MF

3)备份信息和物理备份集不匹配

RMAN> list backup;
List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
36      Full    351.91M    DISK        00:00:16     04-SEP-11
        BP Key: 36   Status: AVAILABLE  Compressed: NO  Tag: TAG20110904T155241

手动误删备份集文件

RMAN> crosscheck backup;

using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=E:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\MYDB\BACKUPSET\2011_09_04\O1_MF_NNNDF_TAG20110904T155241_766CLB4D_.BKP recid=36 stamp=760981962
......

RMAN> list expired backup;
RMAN> list backup;

RMAN> delete expired backup;

3.4 删除备份
RMAN> delete backup;
RMAN> delete obsolete;
RMAN> delete expired backup;


3.5 查看控制文件内容
SQL> alter system set events 'immediate trace name controlf level 12';

找trace文件,udump


你可能感兴趣的:(oracle,list,File,Flash,disk,archive)