Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3386442
  • 博文数量: 631
  • 博客积分: 10716
  • 博客等级: 上将
  • 技术积分: 8397
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 22:35
文章分类

全部博文(631)

文章存档

2020年(2)

2019年(22)

2018年(4)

2017年(37)

2016年(22)

2015年(1)

2013年(12)

2012年(20)

2011年(19)

2010年(20)

2009年(282)

2008年(190)

分类: Oracle

2009-03-23 10:33:45

Version:0.1修改日期:2005-03-01

测试环境

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上,假设名为rcvcata.添加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
---连接到catalog所在的serverRMAN>create catalog; ---创建Catalog
RMAN>exit
C:>rman catalog
target / ---连接目标数据库
RMAN>register database; ---注册目标数据库RMAN>upgrade catalog; ---升级catalogRMAN>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; # defaultCONFIGURE 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基本命令
列出数据库的schemaRMAN>report schema;列出废弃的备份RMAN>report obsolete;检查备份RMAN> crosscheck backup;删除过期失效的备份信息RMAN>delete expired backup;备份表空间RMAN>backup tablespace system;拷贝数据文件RMAN>copy datafile 1 to ‘d:oracleorabackdatafile1.dbf’;列出备份和拷贝RMAN>list backup;
RMAN>list copy;验证备份能否还原RMAN>restore database validate;


5. 备份脚本热全备
---backup.batfor /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:oracleorabackbackup_Full_%dt%.log---backup_full.rcv
# script:bakup_full.rcv
# desc:backup all database datafile in archive with rman
# connect database
#connect rcvcat
;
#connect target sys/pass ;
# start backup database
run{
allocate channel c1 type disk;
backup full tag 'Full' filesperset 5 format 'D:oracleoraback%d_Full_%T_%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup archivelog all filesperset 5 format 'D:oracleoraback%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:oracleorabackbackup_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
;
#connect target sys/pass ;
# start backup database
run{
allocate channel c1 type disk;
backup incremental level 0 tag 'Level_0' maxsetsize=500M format 'D:oracleoraback%d_Level0_%T_%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup archivelog all filesperset 5 format 'D:oracleoraback%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:oracleorabackbackup_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
;
#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:oracleoraback%d_Level1_%T_%u_%p_%c' database include current controlfile;
sql 'alter system archive log current';
backup archivelog all filesperset 5 format 'D:oracleoraback%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为该数据库的DBID,YYYYMMDD为日期,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:oracleo


RadataTESTcontrol01.ctl');
dbms_backup_restore.restorebackuppiece(' D:oracleorabackC-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:oracleo


RadataTESTSYSTEM01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>02,toname=>' d:oracleo


RadataTESTUNDOTBS01.DBF');

sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>' D:oracleorabackTEST_LEVEL0_20050228_46GDTAV8_1_1 ', params=>null);
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>' D:oracleorabackTEST_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:oracleo

RadataTESTSYSTEM01.DBF');

sys.dbms_backup_restore.applyDatafileTo(dfnumber=>02,toname=>' d:oracleo

RadataTESTUNDOTBS01.DBF');

sys.dbms_backup_restore.applyBackupPiece(done=>done,handle=>' D:oracleoraback 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:oracleorabackTEST_LOG_20050228_48GDTB5K_1_1', params=>null);
sys.dbms_backup_restore.deviceDeallocate;

End;

阅读(1146) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~