NinGoo's Notes

I Love This Oracle

Rman简明备忘录

Author:NinGoo

Version:0.1
修改日期:2005-03-01
Mail:NinGoo#itpub.net

 

测试环境

Oracle Version: 9.2.0.1.0

OS Version:Windows 2000 Server

 

RMAN备份的信息可以保存在专门的catalog数据库中,也可以保存在目标DB的控制文件中。

初始化参数control_file_record_keep_time指定了控制文件保存RMAN备份信息的天数,默认是7

 

1.     使用Catalog数据库
建议catalog放在单独的instance,假设名为rcvcat
a.添加tablespace
  create tablespace rman datafile ‘rman01.dbf’ size 20M;
b.
创建用户
  create users rman identified by rman default tablespace rman;
c.
授权
  grant RECOVERY_CATALOG_OWNER to rman;
  grant connect,resource to rman;

C:/>
rman catalog rman/rman@rcvcat                   ---连接到catalog所在的server
RMAN>create catalog;                                         ---创建Catalog
RMAN>exit
C:/>rman catalog rman/rman@rcvcat target /           ---
连接目标数据库
RMA
N>register database;                                     ---注册目标数据库
RMAN>upgrade catalog;                                       ---升级catalog
RMAN>drop catalog;                                            ---删除catalog

2.     不使用Catalog
C:/>rman nocatalog
Recovery Manager: Release 9.2.0.1.0 – Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
RMAN>connect target /
connected to target database: OraDB (DBID=3038703659)
using target database controlfile instead of recovery catalog

3.     RMAN配置
RMAN> show all;
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 ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # 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 SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/product/9.2.0/dbs/snapcf_Technet.f'; # default

4.     RMAN基本命令
列出数据库的schema
RMAN>report schema;
列出废弃的备份
RMAN>report obsolete;
检查备份
RMAN> crosscheck backup;
删除过期失效的备份信息
RMAN>delete expired backup;
备份表空间
RMAN>backup tablespace system;
拷贝数据文件
RMAN>copy datafile 1 to ‘d:/oracle/oraback/datafile1.dbf’;
列出备份和拷贝
RMAN>list backup;
RMAN>list copy;

验证备份能否还原
RMAN>restore database validate;

5.     备份脚本
热全备
---backup.bat
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  set dt=%%i%%j%%k
rman nocatalog target sys/pass @d:/backup_full.rcv
>D:/oracle/oraback/backup_Full_%dt%.log
---
backup_full.rcv
# script:bakup_full.rcv
# desc:backup all database datafile in archive with rman
# connect database
#connect rcvcat rman/rman@back;
#connect target sys/pass ;
# start backup database
run{
allocate channel c1 type disk;
backup full tag 'Full'
filesperset 5 format 'D:/oracle/oraback/%d_Full_%T_%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup archivelog all filesperset 5 format 'D:/oracle/oraback/%d_Log_%T_%u_%p_%c';
sql 'alter system archive log current';
release channel c1;
}
# end
0
级备份
---backup0.bat

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  set dt=%%i%%j%%k
rman nocatalog target sys/pass @d:/backup_lvl_0.rcv >D:/oracle/oraback/backup_Level0_%dt%.log
---backup_lvl_0.rcv
# script:bakup_lvl_0.rcv
# desc:backup database with incremental level 0 datafile in archive with rman
# connect database
#connect rcvcat rman/rman@back; 
#connect target sys/pass ;
# start backup database
run{
allocate channel c1 type disk;
backup
incremental level 0 tag 'Level_0' maxsetsize=500M format 'D:/oracle/oraback/%d_Level0_%T_%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup archivelog all filesperset 5 format 'D:/oracle/oraback/%d_Log_%T_%u_%p_%c';
sql 'alter system archive log current';
release channel c1;
}
# end

1
级备份
---backup1.bat

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  set dt=%%i%%j%%k
rman nocatalog target sys/pass @d:/backup_lvl_0.rcv >D:/oracle/oraback/backup_Level0_%dt%.log
---backup_lvl_1.rcv
# script:bakup_lvl_1.rcv
# desc:backup database with incremental level 0 datafile in archive with rman
# connect database
#connect rcvcat rman/rman@back; 
#connect target sys/pass ;
# start backup database
run{
allocate channel c1 type disk;
#backup incremental level 1
cumulative tag 'Level_1' …
backup incremental level 1 tag 'Level_1' format 'D:/oracle/oraback/%d_Level1_%T_%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup archivelog all filesperset 5 format 'D:/oracle/oraback/%d_Log_%T_%u_%p_%c';
sql 'alter system archive log current';
release channel c1;
}
# end
注:
%c 备份片的拷贝数
%d
数据库名称
%D
位于该月中的第几天 (DD)
%M
位于该年中的第几月 (MM)
%F
一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBIDYYYYMMDD为日期,QQ是一个1-256的序列
%n
数据库名称,向右填补到最大八个字符
%u
一个八个字符的名称代表备份集与创建时间
%p
该备份集中的备份片号,从1开始到创建的文件数
%U
一个唯一的文件名,代表%u_%p_%c
%s
备份集的号
%t
备份集时间戳
%T
年月日格式(YYYYMMDD)

6.     还原与恢复
完全恢复
C:/>rman nocatalog
RMAN>connect target /
RMAN>run {
        allocate channel c1 type disk;
        alter database mount;
        restore database;
        recover database;
        alter database open;
        release channel c1;
       }
不完全恢复
C:/>rman nocatalog
RMAN>connect target /
RMAN>run {
        allocate channel c1 type disk;
        set until time ‘2005-01-24 15:20:00’;
        #set until sequence 120 thread 1;
        alter database mount;
        restore database;
        recover database;
        alter database resetlogs
        release channel c1;
       }
恢复控制文件
可以使用如下方法,在RMAN中恢复备份片的控制文件
restore controlfile from backuppiecefile;
如果是9i的自动备份,可以采用如下的方法
restore controlfile from autobackup;
但是,如果控制文件全部丢失,需要指定DBID,如SET DBID=?
自动备份控制文件的默认格式是%F,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII就是DBID

特殊恢复
如果catalog和控制文件中的备份信息丢失,可以通过dbms_backup_restore包来直接从备份集恢复
restore
控制文件
declare
 devtype varchar2(100)
 done boolean;
 recid number;
 stamp number;
 fullname varchar2(100);
begin
 devtype:=dbms_backup_restore.deviceallocate
(type=>'',ident=>'t1');
 dbms_backup_restore
.restoresetdatafile;
 dbms_backup_restore.
restorecontrolfileto(' d:/oracle/o

Radata/TEST/control01.ctl');
 dbms_backup_restore.
restorebackuppiece(' D:/oracle/oraback/C-3965546666-20050228-00',DONE=>done);
 sys.dbms_backup_restore.deviceDeallocate;
End;

/
restore 0
级备份文件
declare
 devtype varchar2(100)
 done boolean;
 recid number;
 stamp number;
 fullname varchar2(100);
begin
 devtype:=dbms_backup_restore.deviceallocate
(type=>'',ident=>'t1');
 
sys.dbms_backup_restore.restoreSetDatafile;
 sys.dbms_backup_restore.
restoreDatafileTo(dfnumber=>01,toname=>'d:/oracle/o

Radata/TEST/SYSTEM01.DBF');
 sys.dbms_backup_restore.
restoreDatafileTo(dfnumber=>02,toname=>' d:/oracle/o

Radata/TEST/UNDOTBS01.DBF');
 

     sys.dbms_backup_restore.
restoreBackupPiece(done=>done,handle=>' D:/oracle/oraback/TEST_LEVEL0_20050228_46GDTAV8_1_1 ', params=>null);
    sys.dbms_backup_restore.
restoreBackupPiece(done=>done,handle=>' D:/oracle/oraback/TEST_LEVEL0_20050228_47GDTB28_1_1 ', params=>null);
    sys.dbms_backup_restore.deviceDeallocate;
END;
/
restore 1级备份文件
declare
 devtype varchar2(100)
 done boolean;
 recid number;
 stamp number;
 fullname varchar2(100);
begin

devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');

sys.dbms_backup_restore.applySetDatafile;
sys.dbms_backup_restore.applyDatafileTo(dfnumber=>02,toname=>' d:/oracle/o

Radata/TEST/SYSTEM01.DBF');

sys.dbms_backup_restore.applyDatafileTo(dfnumber=>02,toname=>' d:/oracle/o

Radata/TEST/UNDOTBS01.DBF');

sys.dbms_backup_restore.applyBackupPiece(done=>done,handle=>' D:/oracle/oraback/ TEST_LEVEL1_20050301_4AGE6UDI_1_1 ', params=>null);
     sys.dbms_backup_restore.deviceDeallocate;

END;
/

restore 归档日志
declare
 devtype varchar2(100)
 done boolean;
 recid number;
 stamp number;
 fullname varchar2(100);
begin

devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');

sys.dbms_backup_restore.restoreSetArchivedLog;
 sys.dbms_backup_restore.restoreArchivedLogRange;
 sys.dbms_backup_restore.
restoreBackupPiece(done=>done,handle=>' D:/oracle/oraback/TEST_LOG_20050228_48GDTB5K_1_1', params=>null);
 sys.dbms_backup_restore.deviceDeallocate;

    End;
    /

 

NinGoo收集整理,转载请注明出处http://blog.csdn.net/NinGoo

 

阅读更多
个人分类: Database
想对作者说点什么? 我来说一句

rman简明使用手册.doc

2008年08月04日 102KB 下载

RMAN简明使用手册

2008年11月19日 102KB 下载

简明微积分(第四版龚昇)

2017年11月05日 14.08MB 下载

简明法语教程》孙辉 音频

2009年06月25日 13.67MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭