专业只做数据库实训和认证的品牌机构

微信公众号新浪微博
免费咨询电话:400-0909-964
当前位置: 网站首页 > DBA实战 > DBA课程 > DBA基础课程:Oracle备份恢复-RMAN备份

DBA基础课程:Oracle备份恢复-RMAN备份

文章来源: 更新时间:2016/6/24 13:32:13

在线老师点击咨询:

最新学讯:近期OCP认证正在报名中,因考试人员较多请尽快报名获取最近考试时间,报名费用请联系在线老师,甲骨文官方认证,报名从速!

我要咨询

DBA基础课程:Oracle备份恢复-RMAN备份

平台:Redhat linux as5,Oracle10g

RMAN备份是指用恢复管理器备份数据文件,控制文件,归档日志和spfile的方法,前面手动备份(用户管理)的备份要借助OS命令执行备份操作,而RMAN备份由目标数据库的服务器进程来完.在RMAN备份中有三个新概念,备份集,备份片和映像副本,备份集是RMAN提供的一种用于存储备份信息的逻辑结构,备份片是用于存储备份集信息的二进制文件,也就是OS上的一个个文件,映像副本类似手动的备份,是单个数据文件,单个控制文件单个归档日志的完整备份文件.

完全数据库备份

1.一致性备份(冷备)完整过程

RMAN> connect target /

connected to target database: DB2 (DBID=1852673443)

RMAN> shutdown immediate;

RMAN> startup mount;

#开始备份

RMAN> backup database format='/oracle/rmanback/%d_%s.dbf';

Starting backup at 12-JUN-09

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=35 devtype=DISK

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=/home/oracle/oracle/oradata/db2/system01.dbf

input datafile fno=00003 name=/home/oracle/oracle/oradata/db2/sysaux01.dbf

input datafile fno=00002 name=/home/oracle/oracle/oradata/db2/undotbs01.dbf

input datafile fno=00004 name=/home/oracle/oracle/oradata/db2/usertbs.dbf

channel ORA_DISK_1: starting piece 1 at 12-JUN-09

channel ORA_DISK_1: finished piece 1 at 12-JUN-09

piece handle=/oracle/rmanback/DB2_1.dbf tag=TAG20090612T071426 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35

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 12-JUN-09

channel ORA_DISK_1: finished piece 1 at 12-JUN-09

piece handle=/oracle/rmanback/DB2_2.dbf tag=TAG20090612T071426 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04

Finished backup at 12-JUN-09

RMAN> sql 'alter database open';

RMAN> sql 'alter system archive log current';

这样一个数据库就备份完了,通过上面的输出可以看到,把表空间,数据文件,控制文件,SPFILE都备份了,其中表空间,数据文件都备在DB2_1.dbf里,控制文件和spfile保存在DB2_2.dbf里,(比手动备份简单多了)

查看备份后的文件

[Oracle@Oracle rmanback]$ pwd

/oracle/rmanback

[Oracle@Oracle rmanback]$ ls

DB2_1.dbf DB2_2.dbf

2.非一致性备份

因为一致性备份要中断业务,一般使用非一致性备份,但非一致性备份一定要在归档模式下.

RMAN> connect target sys/123456

RMAN> backup database format='/oracle/rmanback/%d_%s.dbf';

[Oracle@Oracle rmanback]$ ls

DB2_1.dbf DB2_2.dbf DB2_3.dbf DB2_4.dbf

备份表空间

下面以表空间chenxy为例

RMAN> connect target sys/123456

RMAN> backup tablespace chenxy format='/oracle/rmanback/%N_%s.dbf';

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00005 name=/home/oracle/oracle/oradata/db2/chenxy.dbf

input datafile fno=00005 name=/home/oracle/oracle/oradata/db2/chenpy.dbf

channel ORA_DISK_1: starting piece 1 at 12-JUN-09

Finished backup at 12-JUN-09

[Oracle@Oracle rmanback]$ ls

CHENXY_6.dbf CHENXY_7.dbf DB2_1.dbf DB2_2.dbf DB2_3.dbf DB2_4.dbf

可以看到备份表空间就是把表空间内的所有数据文件备份下来

备份单个数据文件

RMAN> connect target sys/123456

RMAN> backup datafile 5 format='/oracle/rmanback/%N_%f_%s.dbf';

备份控制文件和归档日志

#备份控制文件

RMAN> backup current controlfile format='/oracle/rmanback/%d_%s.ctl';

#备份前一天的备档日志

RMAN> backup format='/oracle/rmanback/%d_%s.arc'

2> archivelog from time='sysdate-1' until time='sysdate';

#同时备份数据文件和归档日志

RMAN> backup format '/oracle/rmanback/%d_%s.bak' tablespace chenxy plus archivelog;

备份映像副本

1.数据文件副本

RMAN> backup as copy format='/oracle/rmanback/df_5.dbf' datafile 5;

2.控制文件副本

RMAN> copy current controlfile to '/oracle/rmanback/db2.ctl';

[Oracle@Oracle rmanback]$ ls

db2.ctl df_5.dbf

3.归档日志副本

RMAN> backup as copy format='/oracle/rmanback/arc30.log' archivelog sequence 30;

RMAN> copy archivelog '/home/oracle/oracle/oradata/db2/arch/1_31_689217827.dbf'

2> to '/oracle/rmanback/arc31.log';

[Oracle@Oracle rmanback]$ ll

total 678288

-rw-r----- 1 Oracle oinstall 23883776 Jun 12 08:16 arc30.log

-rw-r----- 1 Oracle oinstall 1024 Jun 12 08:18 arc31.log

4.一次备份多个映像副本

RMAN> configure device type disk parallelism 3;

RMAN> backup as copy format='/oracle/rmanback/df_%f.dbf' datafile 2,3,4;

RMAN备份维护

1.报告目标数据库

RMAN>report schema;

RMAN>report need backup incremental 3;

RMAN>report need backup days 3 tablespace chenxy;

RMAN>report need backup redundancy 2 database;

RMAN>report obsolete redundancy 2;

RMAN>report unrecoverable;

2.详细分析RMAN资料库

RMAN>list backup of tablespace chenxy;

RMAN>list backup of controlfile;

RMAN>list backup of archivelog all;

RMAN>list backup of spfile;

RMAN>list copy of datafile 5;

RMAN>list copy of controlfile;

RMAN>list copy of archivelog;

RMAN>list incarnation of database;

3.核对磁盘和磁带上的备份文件

RMAN>crosscheck backup;

RMAN>crosscheck backup of database;

RMAN>crosscheck backup of tablespace system;

RMAN>crosscheck backup of datafile 4;

RMAN>crosscheck backup of controlfile;

RMAN>crosscheck backup of spfile;

RMAN>crosscheck backup of archivelog sequence 3;

RMAN>crosscheck backup of copy;

RMAN>crosscheck backup of database;

RMAN>crosscheck backup of tablespace users;

4.删除备份记录及相就的物理文件

RMAN>delete obsolete;

RMAN>delete noprompt expired backup;

RMAN>delete noprompt expired copy;

RMAN>delete noprompt backupset 12;

RMAN>delete noprompt backuppiece ‘/oracle/rmanback/ctl.bak’;

RMAN>delete noprompt backup;

RMAN>delete noprompt datafilecopy ‘/oracle/rmanback/*.bak’;

RMAN>delete noprompt copy;

RMAN>backup archivelog all delete input;

5.改变备份记录的状态

RMAN>change backupset 2 unavailable;

RMAN>change datafilecopy ‘/oracle/rmanback/*.bak’ unavailable;

RMAN>change backupset 10 keep forerer logs;

RMAN>change backupset 200 keep until time ‘sysdate+60’ logs;

RMAN>change backupset 20 nokeep;

6.追加备份记录到RMAN资料库

RMAN>catalog datafilecopy ‘/oracle/rmanback/chenxy01.bak’;

RMAN>catalog backuppiece ‘/oracle/rmanback/chenxy_10.dbf’;

RMAN>catalog start with ‘/oracle/rmanback’;

#注销

RMAN>change datafilecopy ‘/oracle/rmanback/chenxy01.bak’ uncatalog;

RMAN>change controlfilecopy ‘‘/oracle/rmanback/db2.ctl’ uncatalog;

RMAN>change backuppiece ‘/oracle/rmanback/chenxy02.bak’ uncatalog;

本文地址:http://www.cuug.com.cn/dba/kecheng/12299593763.html 转载请注明!


在线预约 抢先报名 获取课程排期

Oracle培训机构

金牌讲师<>

冉乃纲-老师CUUG金牌讲师
冉老师 CUUG金牌讲师 Oracle及RedHat高级讲师、Unix/Linux 资深专家...[详细了解老师]

免费咨询上课流程 客服在线中

陈卫星-老师CUUG金牌讲师
陈老师 CUUG金牌讲师 精通Oracle管理、备份恢复、性能优化 11年Ora...[详细了解老师]

免费咨询上课流程 客服在线中

选学校如何选择适合自己的学校

CUUG -CHINA UNIX USER GROUP,是国际UNIX组织UNIFORUM的中国代表,是国内悠久的专业UNIX培训机构,被誉为中国UNIX 的摇篮。多年来,以提高教学质量为本,强调素质教育,积极引进、消化国外的新技术,有效的结合中国....[详情]

一站式服务(从入学到就业一帮到底)

入学

学习

就业

实操

食宿
地址:北京市海淀区田村山南路35号院17号楼
课程咨询:010-59426307 010-59426319 400-0909-964
企业服务:137 1818 8639(陈经理)
部分信息来源于网络,如有错误请联系指正!
版权所有@北京神脑资讯技术有限公司 (CUUG,中国UNIX用户协会) Copyright 2016 ALL Rights Reserved 京ICP备11008061号-1