ORACLE10G RMAN 命令

RMAN 命令



连接到目标数据库(不用恢复目录数据库)
rman target / nocatalog

显示rman配置
RMAN> show all;


====================
报告目标数据库的物理结构
RMAN> report schema;

报告陈旧备份
RMAN> report obsolete;

报告不可恢复的数据文件
RMAN> report unrecoverable;

列出备份信息
RMAN> list backup;

RMAN> list backup of database;

RMAN> list backup of tablespace table_name;

RMAN> list backup of controlfile;

RMAN> list backup of spfile;

RMAN> list backupset id;

========================
校验备份信息:
RMAN> crosscheck backup;

RMAN> crosscheck backup of database;

RMAN> crosscheck backup of tablespace system;

RMAN> crosscheck backup of controlfile;

RMAN> crosscheck backup of spfile;


========================
删除备份

Use the ALLOCATE CHANNEL FOR MAINTENANCE command to manually allocate a channel in preparation for issuing a CHANGE, DELETE, or CROSSCHECK command. You can use the RELEASE CHANNEL command to unallocate the channel.

ALLOCATE CHANNEL FOR MAINTENANCE device type (disk,sbt ...)


RMAN> delete obsolete; -- 删除陈旧备份

RMAN> delete expired backup;

RMAN> delete backupset id;

RMAN> delete backup; -- 删除所有备份


--------------------------------------------------------------------------------


--------------------------------------------------------------------------------

1 列出对应物  RMAN>list incarnation;

2 列出备份

2.1概述可用的备份    RMAN>list backup summary;
B 表示 backup
F 表示 FULL
A 表示 archive log
0 1 表示 incremental backup
S 说明备份状态 (A AVAILABLE   X EXPIRED )

2.2按备份类型列出备份  RMAN>list backup by file;
按照 数据文件备份,归档日志备份,控制文件备份,服务器参数文件备份 列出

2.3列出详细备份     RMAN>list backup;

2.4列出过期备份     RMAN>list expired backup;

2.5列出表空间和数据文件备份
list backup of tablespace 和list backup of datafile 输出和list backup 相似
如:list backup of tablespace user_tbs;
list backup of datafile 3;

2.6列出归档日志备份   RMAN>list archivelog all;      简要信息
RMAN>list backup of archivelog all; 详细信息

2.7列出控制文件和服务器参数文件
RMAN>list backup of controfile;
RMAN>list backup of spfile;

=====================================================
=====================================================
RMAN 的 report命令

1. 报告最近没有被备份的数据文件
RMAN>report need backup days=3;

2. 报告备份冗余或恢复窗口
RMAN>report need backup redundancy=2;
RMAN>report need backup recovery window of 2 days;

3. 报告数据文件的不可恢复操作
RMAN>report unrecoverable;

4. 报告数据库模式
RMAN>report schema;

5. 报告丢弃的备份
如果使用了保存策略,备份会标记为丢弃状态  RMAN>report obsolete; 删除丢弃状态备份RMAN>delete obsolete;

=====================================================
=====================================================
RMAN的crosscheck 命令

1 备份集有两种状态A(Available,RMAN认为该项存在于备份介质上)X(Expired,备份存在于控制文件或恢复目录中,但是并没有物理存在于备份介质上)

2 crosscheck 的目的是检查RMAN 的目录以及物理文件,如果物理文件不存在于介质上,将标记为Expired。如果物理文件存在,将维持Available。如果原先标记为Expired的备份集再次存在于备份介质上(如恢复了损坏的磁盘驱动器后),crosscheck将把状态重新从Expired标记回Available。

3 crosscheck 输出分两部分。第一部分列出确定存在于备份介质上的所有备份集片,第二部分列出不存在于备份介质上的备份集片,并将其标记为Expired。当设置备份保 存策略后,一个备份过期,crosscheck之后标记为丢弃的备份状态依旧为availabel,要删除丢弃备份delete obsolete。

4 示例:
crosscheck backup
crosscheck backup of datafile 1;
crosscheck backup of tablespace users;
crosscheck backup of controfile;
crosscheck backup of controlfile;
crosscheck backup tag='SAT_BACKUP';
crosscheck backup completed after 'sysdate - 2'
crosscheck backup completed between 'sysdate - 5' and 'sysdate -2 '
crosscheck backup device type sbt;
crosscheck archivelog all;
crosscheck archivelog like '%ARC00012.001'
crosscheck archivelog from sequence 12;
crosscheck archivelog until sequence 522;

=====================================================
=====================================================
RMAN 的validate 命令

1 validate 命令验证备份集片是否能够被还原

2 list backup summary; 得到了备份集得主键ID如40,然后validate backupset 40;
=====================================================
=====================================================
RMAN 的备份保存策略以及change ,delete命令

0.带delete参数的change 命令删除备份集,从备份介质,并且从控制文件和恢复目录中删除。
change backupset 117,118 delete;
change backuppiece 1304 delete;
change archivelog until logseq =544 delete;

1.两类策略:恢复窗口备份保存策略(recovery windows backup retension policy) 基于时间
备份冗余备份保存策略(backup redundancy backup retension policy) 基于备份的数量

两类策略互相排斥

2.即使使用了备份保存策略,备份到期并不删除,只是在RMAN目录中标记为丢弃,看到的状态依旧为available;
要查看标记为丢弃的备份 report obsolete,只有使用delete obsolete才真正物理删除。

3.configure retension policy to recovery window of 7 days;
configure retension policy to redundancy 3;
显示结果 show all;

4.查看到期丢弃的备份时,可能需要手工保存一些备份 ,可以使用change 命令带keep 参数,使用这个命令后,那些被修改的备份将被认为是个long-term backup,不在受保存策略影响也就是说delete obsolete 也不删除。

5.要使备份时候不受保存策略影响 ,使用带keep参数的backup 命令
backup database keep forever;
backup database keep 5 days;

6.change 命令功能

可以修改备份为永久保存并将以及该备份的相关的日志保存下来,保证总能将备份恢复到当前时间点
change backupset 31 keep forever logs;
可以设置备份丢弃的新日期 ,将备份在多保存7 天,7 天后将删除
change backupset 32 keep until time 'sysdata + 7' logs;

7.change 可以将备份集设置为unavailable
change backupset 33 unavailable;
标记为unavailable状态的备份集并不参与crosscheck;
=====================================================
=====================================================
恢复目录的记录删除

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;
=====================================================
=====================================================
手工同步恢复目录

resync catalog;

Oracle同步恢复目录的时候,首先创建快照控制文件,然后比较这个文件和恢复目录,完成后,Oracle 更新恢复目录,使恢复目录和控制文件同步
=====================================================
=====================================================
在RMAN 中存储脚本

1,连接到目标数据库和恢复目录
rman target / catalog rman/rman@rman9i

2,创建脚本
RMAN>create script my_bk_script
2>{backup database plus archivelog;}
create script my_bk_script

3,打印脚本
RMAN>print script my_bk_script;
printing stored scipt:my_bk_script
{backup database plus archivelog;}

4,运行这个脚本,备份目标数据库
RMAN>run {execute scipt my_bk_script;}

5 删除脚本
RMAN>delete script my_bk_script;
=====================================================
=====================================================
archivelog模式下的完全恢复

step1:set oracle_sid=recover
rman target rman_backup/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;

表空间恢复

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";

数据文件恢复

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";

=====================================================
=====================================================
切换当前的incarnation 回到resetlogs 前RESET DATABASE TO INCARNATION inc_key

=====================================================
=====================================================

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;

==================================

c:/> rman cmdfile='' log=''

在run{}脚本里面,format后面的参数含义:%t代表当前时间,s%代表备份集,%p代表备份片


使用恢复目录数据库执行RMAN步骤
我想建立一个RMAN备份机制,本机为目标数据库,sid为orcl10的数据库为恢复目录来做备份,但总不成功,以下是我的执行步骤:
        SQL> conn sys/e2000jl@orcl10 as sysdba
        Connected.
        SQL> create user rman
               2  identified by rman123;
        User created.
        SQL> grant dba to rman;
        Grant succeeded.

        C:\Documents and Settings\zouyang>rman target sys/system catalog rman/rman123@orcl10
         Recovery Manager: Release 10.1.0.2.0 - Production
         Copyright (c) 1995, 2004, Oracle.  All rights reserved.
         connected to target database: ORCL (DBID=1227672490)
         connected to recovery catalog database
         recovery catalog is not installed

         RMAN> show channel for device type disk;
         recovery catalog is not installed
         recovery catalog is not installed
         RMAN-00571: ===============================================
         RMAN-00569: =========ERROR MESSAGE STACK FOLLOWS ========
         RMAN-00571: ===============================================
         RMAN-03002: failure of show command at 10/14/2009 09:30:02
         RMAN-06429: RCVCAT database is not compatible with this version of RMAN

         RMAN>
         可以连接上恢复目录数据库,但是无法使用这个恢复目录,Oracle报错“recovery catalog is not installed”。

         在网上搜了下,重新建立步骤如下:
第一步:Create Recovery Catalog
         First create a user to hold the recovery catalog:
         -- Create tablepsace to hold repository
         SQL> create tablespace rman_tools
                2  datafile
                3  'D:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL10\rman01.dbf'
                4  size 100m;
          Tablespace created
         -- Create rman schema owner
         SQL> create user rman
                2  identified by rman123
                3  default tablespace rman_tools
                4  quota unlimited on rman_tools;
           User created

          C:\Documents and Settings\zouyang>rman catalog rman/rman123@orcl10
             Recovery Manager: Release 10.1.0.2.0 - Production
             Copyright (c) 1995, 2004, Oracle.  All rights reserved.
             RMAN-00571: ===============================================
             RMAN-00569: ====== ERROR MESSAGE STACK FOLLOWS ==========
             RMAN-00571: ===============================================
             RMAN-00554: initialization of internal recovery manager package failed
             RMAN-04004: error from recovery catalog database: ORA-01045: user RMAN lacks CREATE SESSION privilege; logon denied
          -- 报错!要给rman用户分配一定的权限!
          SQL> grant connect,resource,create session,recovery_catalog_owner
                2        to rman;
           Grant succeeded

          C:\Documents and Settings\zouyang>rman  catalog rman/rman123@orcl10
           Recovery Manager: Release 10.1.0.2.0 - Production
           Copyright (c) 1995, 2004, Oracle.  All rights reserved.
           connected to recovery catalog database
           recovery catalog is not installed

          RMAN> create catalog tablespace rman_tools;
           recovery catalog created      ——很好!!建立了!!
         
          可是,当我重新连接,显示RMAN设置信息时又报错了!!
          C:\Documents and Settings\zouyang>rman target sys/system catalog rman/rman123@orcl10
          Recovery Manager: Release 10.1.0.2.0 - Production
          Copyright (c) 1995, 2004, Oracle.  All rights reserved.
          connected to target database: ORCL (DBID=1227672490)
          connected to recovery catalog database
          RMAN> show channel for device type disk;
          RMAN configuration parameters are:
          RMAN-00571: ===============================================
          RMAN-00569: ========= ERROR MESSAGE STACK FOLLOWS =======
          RMAN-00571: ===============================================
          RMAN-03002: failure of show command at 10/14/2009 10:32:36
          RMAN-06004: ORACLE error from recovery catalog database: RMAN-20001: target database not found in recovery catalog
          RMAN>

          又在网上查找原因,原来还需要注册数据库!!
第二步:Register Database
         Each database to be backed up by RMAN must be registered!
         RMAN> register database;
          database registered in recovery catalog
          starting full resync of recovery catalog
          full resync complete
         RMAN> show channel for device type disk;
          RMAN configuration parameters are:CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   'D:\BACKUP\RMAN\%d_%s.bak';
         RMAN>
   
         成功啦!!!
http://407882.blog.51cto.com/397882/212142
=========================================================
oracle10g用rman全备及控制文件在别的机器还原实验


利用rman全备文件(控制文件、归档日志、数据文件)在别处一台oracle10g上还原
要求两台服务器的oracle版本一致并且数据文件、控制文件、归档日志文件目录结构一样
rman全备是用nocatalog方式备份的,所以备份集信息保存在控制文件里。在这里证明一点,就是利用全备方式所备份出来的控制文件含的备份集信息是不全的,如果原来的控制文件丢失会给恢复带来一定麻烦,只有通过
DBMS_BACKUP_RESTORE包来恢复。但如果打开自动备份控制文件功能就不一样了。
rman全备脚本:
#!/bin/bash
rman target sys/sysdba nocatalog   configure controlfile autobackup on ;

全备后的文件如下:
cd /u01/rman
[oracle@test rman]$ ll
总计 754936
-rw-r----- 1 oracle oinstall 375029760 12-20 22:48 full_wapdb_01k2ot0u_1_1
-rw-r----- 1 oracle oinstall 339255296 12-20 22:48 full_wapdb_02k2ot0u_1_1
-rw-r----- 1 oracle oinstall   7110656 12-20 22:45 full_wapdb_03k2ot0u_1_1
-rw-r----- 1 oracle oinstall  50874880 12-20 22:49 redolog_wapdb_04k2ot6v_1_1
--------------------------------------------------------------------------------
由于备份是nocatalog所以备份集信息是写到控制文件里的,用全备出来的控制文件信息是不全的。
来验证一下:(把日志文件 控制文件 数据文件删除)
1.从全备文件恢复
[oracle@test ~]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on 星期六 12月 20 23:28:31 2008
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: oradb (not mounted)
RMAN> restore controlfile from '/u01/rman/full_wapdb_03k2ot0u_1_1';
Starting restore at 20-12月-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u01/app/oracle/oradata/oradb/control01.ctl
output filename=/u01/app/oracle/oradata/oradb/control02.ctl
output filename=/u01/app/oracle/oradata/oradb/control03.ctl
Finished restore at 20-12月-08
这样三个控制文件就恢复了
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> list backup;
using target database control file instead of recovery catalog
在恢复出来的控制文件里找不到备份的信息
2.用自动备份控制文件来恢复(把刚才的三个控制文件删除)
RMAN> startup nomount;
connected to target database (not started)
Oracle instance started
Total System Global Area     167772160 bytes
Fixed Size                     1266392 bytes
Variable Size                 83889448 bytes
Database Buffers              79691776 bytes
Redo Buffers                   2924544 bytes
RMAN> exit
--------------------------------------------------------------------------------
2.再来看看用自动备份恢复的实验
Recovery Manager complete.
[oracle@test ~]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on 星期六 12月 20 23:34:45 2008
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: oradb (not mounted)
RMAN> restore controlfile from '/u01/app/oracle/flash_recovery_area/ORADB/autobackup/2008_12_20/o1_mf_s_674002170_4nt1hx4z_.bkp';
Starting restore at 20-12月-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output filename=/u01/app/oracle/oradata/oradb/control01.ctl
output filename=/u01/app/oracle/oradata/oradb/control02.ctl
output filename=/u01/app/oracle/oradata/oradb/control03.ctl
Finished restore at 20-12月-08
重新从autobackup里还原三个控制文件
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> list backup;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    6.77M      DISK        00:00:06     20-12月-08    
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20081220T224548
        Piece Name: /u01/rman/full_wapdb_03k2ot0u_1_1
  Control File Included: Ckp SCN: 339825       Ckp time: 20-12月-08
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    357.65M    DISK        00:02:44     20-12月-08    
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20081220T224548
        Piece Name: /u01/rman/full_wapdb_01k2ot0u_1_1
  List of Datafiles in backup set 2
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1       Full 339824     20-12月-08 /u01/app/oracle/oradata/oradb/system01.dbf
  4       Full 339824     20-12月-08 /u01/app/oracle/oradata/oradb/users01.dbf
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    323.53M    DISK        00:02:45     20-12月-08    
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20081220T224548
        Piece Name: /u01/rman/full_wapdb_02k2ot0u_1_1
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  2       Full 339825     20-12月-08 /u01/app/oracle/oradata/oradb/undotbs01.dbf
  3       Full 339825     20-12月-08 /u01/app/oracle/oradata/oradb/sysaux01.dbf
BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4       48.52M     DISK        00:00:21     20-12月-08    
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20081220T224901
        Piece Name: /u01/rman/redolog_wapdb_04k2ot6v_1_1
  List of Archived Logs in backup set 4
  Thrd Seq     Low SCN    Low Time   Next SCN   Next Time
  ---- ------- ---------- ---------- ---------- ---------
  1    29      327057     20-12月-08 340013     20-12月-08
这次rman找回了备份集的信息
3.开始恢复
RMAN> restore database;
Starting restore at 20-12月-08
Starting implicit crosscheck backup at 20-12月-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 20-12月-08
Starting implicit crosscheck copy at 20-12月-08
using channel ORA_DISK_1
Finished implicit crosscheck copy at 20-12月-08
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/ORADB/autobackup/2008_12_20/o1_mf_s_674002170_4nt1hx4z_.bkp
File Name: /u01/app/oracle/flash_recovery_area/ORADB/archivelog/2008_12_20/o1_mf_1_30_4nt1jdhs_.arc
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/oradb/system01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/oradb/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/rman/full_wapdb_01k2ot0u_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/rman/full_wapdb_01k2ot0u_1_1 tag=TAG20081220T224548
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/oradb/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/oradb/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /u01/rman/full_wapdb_02k2ot0u_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/rman/full_wapdb_02k2ot0u_1_1 tag=TAG20081220T224548
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 20-12月-08
RMAN> recover database noredo;
Starting recover at 20-12月-08
using channel ORA_DISK_1
Finished recover at 20-12月-08
RMAN> alter database open resetlogs;(注意在线日志不能恢复,用resetlogs打开)
database opened
RMAN> exit
恢复结束。
结论:
如果用rman选择nocatalog方式备份,因为备份信息放到控制文件里,所以控制文件非常重要,即使是全备,其里的备份信息也不全,必需打开自动备份控制文件configure controlfile autobackup on ;
一定要保存好自动备份文件。
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/40226/showart_1730431.html

猜你喜欢

转载自thomas0988.iteye.com/blog/1983743