• RMAN命令简介


    1、创建恢复目录

    E:>sqlplus /nolog

    SQL*Plus: Release 11.2.0.1.0 Production on 星期一 5月 29 19:37:43 2017

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

    SQL> conn / as sysdba
    Connected.
    SQL> create tablespace rman_ts datafile 'D:/app/Liushuai/oradata/orcl/rmants.dbf' size 50M;

    Tablespace created.

    SQL> create user rman identified by rman default tablespace rman_ts;

    User created.

    SQL> grant connect,resource,recovery_catalog_owner to rman;

    Grant succeeded.

    SQL> host
    Microsoft Windows [版本 6.1.7601]
    版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

    2、调用RMAN

    E:>rman target / catalog rman/rman@orcl

    Recovery Manager: Release 11.2.0.1.0 - Production on 星期一 5月 29 19:41:14 2017


    Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

    connected to target database: ORCL (DBID=1459597614)
    connected to recovery catalog database

    RMAN>
    本例使用Target选项,通过操作系统身份验证连接到数据库,使用catalog选项连接到数据库的恢复目录。在启动RMAN时可使用13个不同的RMAN命令行选项,最常见的的如下:
    • target 确定要备份的Oracle数据库的连接字符串
    • catalog 制定用于备份信息的恢复目录数据库
    • nocatalog 使用控制文件来备份信息
    • cmdfile 指定一个输入文件,其中包括一系列RMAN命令
    • log 为RMAN的消息的日志文件设置名称

    RMAN选项:
    E:>rman help

    Argument Value Description
    -----------------------------------------------------------------------------
    target quoted-string connect-string for target database
    catalog quoted-string connect-string for recovery catalog
    nocatalog none if specified, then no recovery catalog
    cmdfile quoted-string name of input command file
    log quoted-string name of output message log file
    trace quoted-string name of output debugging message log file
    append none if specified, log is opened in append mode
    debug optional-args activate debugging
    msgno none show RMAN-nnnn prefix for all messages
    send quoted-string send a command to the media manager
    pipe string building block for pipe names
    timeout integer number of seconds to wait for pipe input
    checksyntax none check the command file for syntax errors
    -----------------------------------------------------------------------------

    3、RMAN命令类型

    命令类型有两种,分别为独立命令和作业命令。独立命令仅在RMAN>提示符下执行,是独立的命令,独立命令有CHANGE、CONNECT、CREATA SCRIPT和CREATE CATALOG;作业命令与此相反,它们经常组合在一起,使用RUN命令在命令块中运行,如果命令块中任何命令出现故障,块的执行将会终止。ALLOCATE CHANNEL是一个仅可以用做作业命令的RMAN命令示例:通道分配仅在命令块期间有效(可以使用独立命令CONFIGURE CHANNEL创建默认通道)。RMAN通道是数据库到设备的一个数据流,与一个数据库服务器会话对应。

    4、常见的RMAN命令

    RMAN命令 说明
    @ 运行在@后制定的路径名处的RMAN命令脚本。如果未指定任何路径,将假定路径是从中调用RMAN的目录
    ADVISE FAILURE 显示找到故障的修复选项
    ALLOCATE CHANNEL 在RMAN和数据库实例间创建连接,初始化一个数据库服务器会话,此会话备份、还原或恢复RMAN备份
    BACKUP 执行RMAN备份(包含或不包含归档重做日志)。备份数据文件、数据文件副本,或执行增量级别0或级别1备份。备份整个数据库或单个表空间或数据文件。使用VALIDATE字句验证要备份的块
    CREATE SCRIPT 创建存储在恢复目录中的脚本
    CATALOG 将有关文件副本和用户管理的备份的信息添加到仓库中
    CHANGE 更改RMAN仓库中的备份的状态。用于在还原或恢复操作中明确排除某个备份,或向RMAN通知以下内容:RMAN之外的操作系统命令有意或无意中删除了备份文件
    CONFIGURE 配置RMAN的持久性参数。除非明确清除或修改,否则可以在随后的每个RMAN会话中使用配置的参数
    CONVERT 转换数据文件格式,以便跨越平台传输表空间或整个数据库
    CREATE CATALOG 创建仓库目录,其中包含一个或多个目标数据库的RMAN元数据。强烈建议不要将此目录存储在一个目标数据库中
    CROSSCHECK 对照磁盘或磁带上的实际文件核实RMAN仓库中的备份记录。将对象标记为EXPIRED、AVAILABLE、UNAVAILABLE或OBSOLETE。如果RMAN无法访问相应对象,会将其标记为UNAVAILABLE
    DELETE 删除备份文件或副本,并在目标数据库控制文件中将其标记为DELETED。如果使用仓库,会删除备份文件的记录
    DROP DATABASE 从磁盘删除目标数据库并予以注销。必须以EXCLUSIVE模式安装目标数据库。会删除所有数据文件、联机重做日志和控制文件。会删除在恢复目录中存储的所有元数据
    DUPLICATE 使用目标数据库的备份创建冗余数据库
    FLASHBACK DATABASE 执行ORACLE 10g中引入的闪回数据库操作。使用闪回日志按系统更改号SCN或日志序列号将数据库还原到回去的一个时间点,以便撤销SCN或日志序列号之前的更改,然后应用归档重做日志将数据库前移到一致状态
    LIST 显示在目标数据库的RMAN仓库(目录)中记录的备份集和映像副本的信息。参考REPORT命令来了解备份集之间的复杂关系
    RECOVER 执行数据文件、表空间或整个数据库的完整或不完整恢复。也可将增量备份应用于数据文件映像副本以将其及时前滚
    REGISTER DATABASE 在RMAN仓库中注册目标数据库
    REPAIR FAILURE 修复在自动诊断仓库ADR中记录的一个或多个故障
    REPORT 详细分析RMAN仓库。例如,此命令可以确定需要备份哪些文件以便满足保留策略,或可以删除哪些备份文件
    RESTORE 将映像副本或备份集的文件还原到磁盘上(通常在发生介质故障后恢复)。如果指定PREVIEW选项,则不需要真正执行还原就可以验证还原操作
    RUN 如果在{}之间输入一系列RMAN语句,将作为一组命令来运行。
    SET 设置RMAN会话期间的RMAN配置项,如分配的磁盘或磁带通道。使用CONFIGURE分配持久性设置
    SHOW 显示所有或个别的RMAN配置设置
    SHUTDOWN 从RMAN关闭目标数据库
    STARTUP 启动目标数据库
    SQL 运行无法使用标准RMAN命令直接或间接完成的SQL命令。例如,在还原和恢复users表空间前,在RMAN中运行SQL ‘ALTER TABLESPACE USERS OFFLINE IMMEDIATE’
    TRANSPORT TABLESPACE 根据一个或多个表空间的备份创建可传输的表空间集
    VALIDATE 检查备份集,并报告数据是否完整一致
    5、定义保留策略

    可以使用SHOW ALL查看现有保留策略,默认为冗余1,即保留一份副本。
    RMAN> show all;

    RMAN configuration parameters for database with db_unique_name ORCL 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 COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOA
    D TRUE ; # default
    CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
    CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'D:APPLIUSHUAIPRODUCT11.2.0DBHOME_1
    DATABASESNCFORCL.ORA'; # default

    可使用两种方法之一来自动保留和管理备份:恢复窗口和冗余。使用恢复窗口时,RMAN将根据需要保留足够多的备份,以便将数据恢复到恢复窗口中的任何时间点。不需要用于支持此恢复窗口的任何备份被标记为OBSOLETE,如果正在使用闪回恢复区而且要将磁盘空间用于新备份,RMAN将自动删除相应的过时的备份内容。
    冗余保留策略让RMAN保留指定数量的备份(数据文件和控制文件的副本)。如果副本或备份数量超过冗余策略中指定的数量,会将超过的副本或者备份标记为OBSOLETE。可以自动删除过时的备份内容,也可以使用DELETE OBSOLETE进行手动删除。
    如果将保留策略设置为NONE,则备份或副本将永不过时,DBA必须以手动方式从目录或磁盘中删除不必要的备份文件。

    例如:将保留策略设置为保留2份
    RMAN> configure retention policy to redundancy 2;

    new RMAN configuration parameters:
    CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
    new RMAN configuration parameters are successfully stored
    starting full resync of recovery catalog
    full resync complete

    将保留策略的恢复窗口设置为7天
    RMAN> configure retention policy to recovery window of 7 days;

    old RMAN configuration parameters:
    CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
    new RMAN configuration parameters:
    CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
    new RMAN configuration parameters are successfully stored
    starting full resync of recovery catalog
    full resync complete

    Oracle的最佳做法建议使用恢复窗口或时间段,在这段时间内将可以发现与数据库相关的任何问题,如无意间删除了表或者行,并且能够在错误发生前执行时间点恢复。
    6、RMAN备份和维护命令

    VALIDATE BACKUPSET:验证备份集的可用性
    RMAN> validate backupset 50;

    Starting validate at 02-JUN-17
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=135 device type=DISK
    channel ORA_DISK_1: starting validation of datafile backup set
    channel ORA_DISK_1: reading from backup piece E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    channel ORA_DISK_1: piece handle=E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP tag=TAG20170602T111712
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: validation complete, elapsed time: 00:00:16
    Finished validate at 02-JUN-17

    查看备份集汇总信息
    RMAN> list backup summary;


    List of Backups
    ===============
    Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
    ------- -- -- - ----------- --------------- ------- ------- ---------- ---
    49 B A A DISK 02-JUN-17 1 1 NO TAG20170602T111710
    50 B F A DISK 02-JUN-17 1 1 NO TAG20170602T111712
    51 B A A DISK 02-JUN-17 1 1 NO TAG20170602T111809
    52 B F A DISK 02-JUN-17 1 1 NO TAG20170602T111810

    RESTORE...VALIDATE:验证数据库对象是否在当前的备份集中
    验证表空间USERS备份信息是否存在备份集中
    RMAN> restore tablespace users validate;

    Starting restore at 02-JUN-17
    using channel ORA_DISK_1

    channel ORA_DISK_1: starting validation of datafile backup set
    channel ORA_DISK_1: reading from backup piece E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    channel ORA_DISK_1: piece handle=E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP tag=TAG20170602T111712
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
    Finished restore at 02-JUN-17

    验证数据文件是否在备份集中
    RMAN> restore datafile 7 validate;

    Starting restore at 02-JUN-17
    using channel ORA_DISK_1

    channel ORA_DISK_1: starting validation of datafile backup set
    channel ORA_DISK_1: reading from backup piece E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    channel ORA_DISK_1: piece handle=E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP tag=TAG20170602T111712
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
    Finished restore at 02-JUN-17

    RESTORE。。。PREVIEW
    查看恢复整个数据库所需的备份文件是否存在
    RMAN> restore database preview;

    Starting restore at 02-JUN-17
    using channel ORA_DISK_1


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


    BS Key Type LV Size Device Type Elapsed Time Completion Time
    ------- ---- -- ---------- ----------- ------------ ---------------
    50 Full 1.51G DISK 00:00:50 02-JUN-17
    BP Key: 50 Status: AVAILABLE Compressed: NO Tag: TAG20170602T111712
    Piece Name: E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    List of Datafiles in backup set 50
    File LV Type Ckp SCN Ckp Time Name
    ---- -- ---- ---------- --------- ----
    1 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLSYSTEM01.DBF
    2 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLSYSAUX01.DBF
    3 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLUNDOTBS01.DBF
    4 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLUSERS01.DBF
    5 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLEXAMPLE01.DBF
    6 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLRMANTS.DBF
    7 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLTEST.DBF

    List of Archived Log Copies for database with db_unique_name ORCL
    =====================================================================

    Key Thrd Seq S Low Time
    ------- ---- ------- - ---------
    49 1 5 A 02-JUN-17
    Name: E:APPALEN.LIUFLASH_RECOVERY_AREAORCLARCHIVELOG2017_06_02O1_MF_1_5_DM1P7JRW_.ARC

    Media recovery start SCN is 13980588
    Recovery must be done beyond SCN 13980588 to clear datafile fuzziness
    Finished restore at 02-JUN-17

    查看还原表空间或者数据文件是否存在
    RMAN> restore tablespace users preview;

    Starting restore at 02-JUN-17
    using channel ORA_DISK_1


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


    BS Key Type LV Size Device Type Elapsed Time Completion Time
    ------- ---- -- ---------- ----------- ------------ ---------------
    50 Full 1.51G DISK 00:00:50 02-JUN-17
    BP Key: 50 Status: AVAILABLE Compressed: NO Tag: TAG20170602T111712
    Piece Name: E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    List of Datafiles in backup set 50
    File LV Type Ckp SCN Ckp Time Name
    ---- -- ---- ---------- --------- ----
    4 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLUSERS01.DBF

    List of Archived Log Copies for database with db_unique_name ORCL
    =====================================================================

    Key Thrd Seq S Low Time
    ------- ---- ------- - ---------
    49 1 5 A 02-JUN-17
    Name: E:APPALEN.LIUFLASH_RECOVERY_AREAORCLARCHIVELOG2017_06_02O1_MF_1_5_DM1P7JRW_.ARC

    Media recovery start SCN is 13980588
    Recovery must be done beyond SCN 13980588 to clear datafile fuzziness
    Finished restore at 02-JUN-17

    RMAN> restore datafile 7 preview;


    LIST指令:查看备份集信息
    通过LIST查看可以需要的指令
    RMAN> list;

    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, archivelog, backed, backuppiece, backupset, backup, completed, controlfilecopy, copy, datafilecopy, db_unique_name, device, expired, failure, foreign, global, incarnation, like, proxy, recoverable, restore, script, tag"
    RMAN-01007: at line 1 column 5 file: standard input

    查看表空间在备份集中的信息
    RMAN> list backup of tablespace users;


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


    BS Key Type LV Size Device Type Elapsed Time Completion Time
    ------- ---- -- ---------- ----------- ------------ ---------------
    50 Full 1.51G DISK 00:00:50 02-JUN-17
    BP Key: 50 Status: AVAILABLE Compressed: NO Tag: TAG20170602T111712
    Piece Name: E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    List of Datafiles in backup set 50
    File LV Type Ckp SCN Ckp Time Name
    ---- -- ---- ---------- --------- ----
    4 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLUSERS01.DBF

    数据文件在备份集中的信息
    RMAN> list backup of datafile 7;


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


    BS Key Type LV Size Device Type Elapsed Time Completion Time
    ------- ---- -- ---------- ----------- ------------ ---------------
    50 Full 1.51G DISK 00:00:50 02-JUN-17
    BP Key: 50 Status: AVAILABLE Compressed: NO Tag: TAG20170602T111712
    Piece Name: E:APPALEN.LIUFLASH_RECOVERY_AREAORCLBACKUPSET2017_06_02O1_MF_NNNDF_TAG20170602T111712_DM1P5T5Y_.BKP
    List of Datafiles in backup set 50
    File LV Type Ckp SCN Ckp Time Name
    ---- -- ---- ---------- --------- ----
    7 Full 13980588 02-JUN-17 E:APPALEN.LIUORADATAORCLTEST.DBF

    RMAN> list backup of archivelog all;
    RMAN> list backup of archivelog from time ='sysdate -1';
    RMAN> list backup of controlfile;
    RMAN> list backup of spfile;
    RMAN> list backup of controlfile;

    查看备份汇总信息
    RMAN> list backup summary;


    List of Backups
    ===============
    Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
    ------- -- -- - ----------- --------------- ------- ------- ---------- ---
    49 B A A DISK 02-JUN-17 1 1 NO TAG20170602T111710
    50 B F A DISK 02-JUN-17 1 1 NO TAG20170602T111712
    51 B A A DISK 02-JUN-17 1 1 NO TAG20170602T111809
    52 B F A DISK 02-JUN-17 1 1 NO TAG20170602T111810
    其中,KEY是备份集标识,B表示备份集,LV的A标识是归档文件,F表示数据文件的全备份,S的A表示可用。

    REPORT命令:报告,具体一定的分析功能
    RMAN> report;

    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: "device, need, obsolete, schema, unrecoverable"
    RMAN-01007: at line 1 column 7 file: standard input



  • 相关阅读:
    iPhone 3开发基础教程这本书怎么样
    好久没有用过VS6.0了。
    关于UNIX环境高级编程(第2版)——图灵计算机科学丛书的读后感
    强烈推荐C++ Primer 习题解答(第4版)
    C标准库这本书怎么样
    关于C语言程序设计:现代方法(第2版)的读后感
    强烈推荐JavaScript DOM高级程序设计
    强烈推荐深入浅出Ext JS(第2版)(附光盘)
    关于PHP与MySQL程序设计(第3版)的读后感
    强烈推荐NET设计规范:约定、惯用法与模式(第2版)(附光盘)
  • 原文地址:https://www.cnblogs.com/alen-liu-sz/p/12975740.html
Copyright © 2020-2023  润新知