Oracle备份恢复四(RMAN备份)

时间:2022-02-14 07:47:43

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-09allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=35 devtype=DISKchannel ORA_DISK_1: starting full datafile backupsetchannel ORA_DISK_1: specifying datafile(s) in backupsetinput 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-09channel ORA_DISK_1: finished piece 1 at 12-JUN-09piece handle=/oracle/rmanback/DB2_1.dbf tag=TAG20090612T071426 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35channel ORA_DISK_1: starting full datafile backupsetchannel ORA_DISK_1: specifying datafile(s) in backupsetincluding current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 12-JUN-09channel ORA_DISK_1: finished piece 1 at 12-JUN-09piece handle=/oracle/rmanback/DB2_2.dbf tag=TAG20090612T071426 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04Finished 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]$ lsDB2_1.dbf  DB2_2.dbf
2.非一致性备份
    因为一致性备份要中断业务,一般使用非一致性备份,但非一致性备份一定要在归档模式下.
RMAN> connect target sys/123456RMAN> backup database format='/oracle/rmanback/%d_%s.dbf';[oracle@oracle rmanback]$ lsDB2_1.dbf  DB2_2.dbf  DB2_3.dbf  DB2_4.dbf

备份表空间

    下面以表空间chenxy为例
RMAN> connect target sys/123456RMAN> backup tablespace chenxy format='/oracle/rmanback/%N_%s.dbf';channel ORA_DISK_1: specifying datafile(s) in backupsetinput 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-09Finished backup at 12-JUN-09[oracle@oracle rmanback]$ lsCHENXY_6.dbf  CHENXY_7.dbf  DB2_1.dbf  DB2_2.dbf  DB2_3.dbf  DB2_4.dbf
    可以看到备份表空间就是把表空间内的所有数据文件备份下来
备份单个数据文件
RMAN> connect target sys/123456RMAN> 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]$ lsdb2.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]$ lltotal 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://chenxy.blog.51cto.com/729966/171360