Oracle RMAN 学习:演练进阶篇
5 Rman备份演练进阶篇
5.1 是否选择增量备份
Backup命令生成的备份集中只备份了那些使用了的数据块,备份集实际大小已经较目标数据库的数据文件小了很多
备份时只备份那些修改过的数据,
如果数据库在非归档模式下,只能在db处于数据库干净关闭的情况才能进行一致的增量备份
在归档模式下,db处于打开,关闭都可以
5.1.1 增量备份选项
实质就是指定一个参数,incremental level=n,在backup时加上即可,增量备份可以创建两个级别,,用整型数字 0…n(n<=4),从0开始,所有增量备份都必须先创建0级备份,0级备份相当于db的完整备份,
Backup database是数据库的完整备份,但是不同于数据库增量备份的0级备份,
在创建增量备份时,既可以对全库进行备份,也可以仅对表空间甚至数据文件级创建增量备份
例: 1建立增量级别0的全库备份
RMAN> backup incremental level=0 database format '/u01/oracle/backup/backup_increment_%U';
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 0 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/grs/system01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/grs/cmask01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/grs/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/grs/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/grs/yyhhqq.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/grs/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/backup_increment_0kon7io8_1_1 tag=TAG20131024T163000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:06
Finished backup at 24-OCT-13
Starting Control File and SPFILE Autobackup at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829672447_96kpw106_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 24-OCT-13
2 为数据文件创建增量级别1的备份
RMAN> backup incremental level=1 datafile '/u01/app/oracle/oradata/grs/users01.dbf' format '/u01/oracle/backup/backup_increm_datafile_%U';
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/backup_increm_datafile_0mon7j7k_1_1 tag=TAG20131024T163812 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 24-OCT-13
Starting Control File and SPFILE Autobackup at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829672695_96kq3qv3_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 24-OCT-13
3 为表空间yyhhqq建立增量级别1的备份
RMAN> backup incremental level=1 tablespace users format '/u01/oracle/backup/backup_increm_user_%U';
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/backup_increm_user_0oon7j84_1_1 tag=TAG20131024T163828 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-OCT-13
Starting Control File and SPFILE Autobackup at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829672709_96kq45hg_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 24-OCT-13
5.1.2 增量备份类型
Rman提供了2中增量类型,differential(差异,默认),cumulative(累积),
默认情况下,rman 是差异备份,如果要建立累积备份,需要在backup时显示指定
Rman>backup increment level=1 cumulative database;
5.1.3 增量备份注意事项
9i之前,执行rman备份,都会把所有数据块都读入内存,检查每一个块头的scn信息,
10g中提供了:块修改跟踪block change tracking(企业版的),rman不用再去扫描数据文件中的每一个块,直接通过块修改跟踪文件可以获取那些块发生了修改的信息
启用块修改跟踪,--增量备份中
SQL> Alter database enable block change tracking using file'/u01/oracle/backup/block_change_tracking.log';
Database altered.
SQL> select filename,status,bytes from v$block_change_tracking;
FILENAME STATUS BYTES
/u01/oracle/backup/block_change_tracking.log ENABLED 11599872
禁用
Alter database disable block change tracking
查看是否启动
select * from v$block_change_tracking
DISABLED
虽然备份时间可能减短,并且备份集可以减小,但是进行恢复操作时,所花费的时间有可能会增加,因为数据恢复是不得的访问多个备份集才能完成恢复操作
select status,filename from v$block_change_tracking
alter database enable block change tracking using file '/u02/Oracle_change.trace'
alter database enable block change tracking using file '/u02/Oracle_change_pdb.trace'
SQL> select status,filename from v$block_change_tracking;
no rows selected
SQL> alter database enable block change tracking using file '/u02/Oracle_change_pdb.trace';
alter database enable block change tracking using file '/u02/Oracle_change_pdb.trace'
*
ERROR at line 1:
ORA-65040: operation not allowed from within a pluggable database
alter database disable block change tracking
5.2 是否使用rman 备份集的保留策略
Rman 提供了2种保留策略:基于时间和基于冗余数量的保留策略
5.2.1 基于时间的保留策略
就是你希望数据库最早能恢复到几天前,比如将恢复时间设置为7,那么rman所保留的备份就是可以保证你将数据库恢复到一周内任何时刻下的那些文件,通过configure命令配置
Rman> configure retention policy to recovery window of n days;n>=0整数
RMAN> configure retention policy to recovery window of 7 days;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored
执行该命令后,rman将会保留那些将数据库恢复到7天前的状态时需要用到的备份
各个数据文件满足 system – backup checkpoint time>=7,任何不满足上述条件的备份都将被rman废弃,并delete obsolete删除,
对于nocatalog下的备份,rman备份集都是保留在目标端的控制文件中,对于rman保存在控制文件的信息受到参数control_file_record_keep_time,默认是7天,一般建议该参数的设置不小于rman备份设置的时间,
当前控制文件中分配的空间,可存储记录和已存储记录都可以通过v$controlfile_record_section
select * from v$controlfile_record_section
5.2.2 基于冗余数量的备份保留策略
实质是某个数据文件以各种形式(包括备份集和镜像复制)存在的备份数量,如果某个数据文件的冗余备份超过了指定的数量,rman自动废弃,
configure retention policy to redundancy n;n>=0
也可以通过下列命令设置成不采用任何备份策略
configure retention policy to redundancy none
5.2.3 根据备份策略来维护备份集
为rman设置备份策略,rman会自动判断哪些备份集或镜像复制文件不必保留
Delete obsolete命令
Note:1 如果被判断为废弃的备份是一个单独数据文件的镜像复制,在delete时直接删除
2 如果是备份集中的一部分,则必须等整个备份集都废弃了,才能删除
RMAN对于obsolete和expired的定义,对于手工删除的文件,物理上已经不存在的,在执行了crosscheck命令之后,rman将其标记为expired,对于那些超出了备份保留策略的备份集片段,则标记为obsolete
5.3 是否使用多个通道
备份设备:磁带sbt,磁盘disk
5.3.1 手工分配通道
Allocate channel,该命令只能在run块中使用
run{
allocate channel c1 device type disk format 'f:\mydb\backup\back_%u';
backup tablespace yyhhqq;
}
RMAN> run{
2> allocate channel c1 device type disk format '/u01/oracle/backup/back_%U';
3> backup tablespace users;
4> };
released channel: ORA_DISK_1
allocated channel: c1
channel c1: sid=144 devtype=DISK
5.3.2 自动分配通道
没有显示手动分配,rman在执行backup时,将使用预定义配置中的设置来自动分配通道
configure device type sbt/disk parallelism n;
configure default device type to sbt/disk;
configure channel device type sbt/disk format 'f:\mydb\backup\back_%u';
configure channel n device type sbt/disk format 'f:\mydb\backup\back_%u';
5.4 是否启用复合备份
Rman提供了duplexed备份,实质就是在生成备份集的同时,向指定位置生成指定的备份数(不超过4份),异地异机备份,
Rman提供了3种方式实现duplex备份
1 Rman>backup copies 3 database;自动生成全库备份的2个复制到默认路径
2 run{
set copies 2;
backup device type disk format 'f:\mydb\backup\back_%u','f:\mydb\backup_%U'
tablespace yyhhqq;
}
3 configure 。。backup copies
5.5 是否设置备份集属性
5.5.1 设置备份片段文件名
Fromart
5.5.2 设置备份集标签
Rman叫tag,默认tagyyyymmddthhmiss
Rman>backup tablespace yyhhqq tag tas_yyhhqq_bak;
5.5.3 设置备份集片段/备份集大小
在fat32文件系统中,单个文件不大于4g,
Rman在分配通道时,参数maxpiecesize,专门用来指定备份片段大小
run{
allocate channel c1 device type disk maxpiecesize=10m format 'f:\mydb\backup\back_%u';
backup tablespace yyhhqq;
}---指定备份片集大小为10m
Rman>backup database maxsetsize=100m;指定单个备份集的最大值
5.6 是否使用rman恢复目录(recovery catalog)
当没有恢复目录时,rman相关的备份信息都存在在目标数据库的控制文件中,
Rman 使用恢复目录才专门存储备份的相关信息,
1 要为该目录创建一个单独的tablespace和对应的schema
Create tablespace bbb、、、、一般50m
Note:不要将恢复目录创建在要备份的目标数据库上
当使用CATALOG命令时,要求目标数据库必须处于MOUNT或OPEN状态;当使用恢复目录时,要求恢复目录数据库必须处于OPEN状态
2 创建一个单独对应的schema,并赋予权限
CREATE TABLESPACE rman_catalog DATAFILE
'/u01/app/oracle/oradata/grs/rman_catalog.dbf' SIZE 50M ;
Create user rman_catalog identified by rman_catalog default tablespace rman_catalog
Temporary tablespace yhq_temp
Grant connect,resource to rman_catalog
grant RECOVERY_CATALOG_OWNER to rman_catalog
Grant connect ,resource,recovery_catalog_owner to abc identifies by abc;
3 通过rman连接
[oracle@localhost ~]$ rman catalog rman_catalog/rman_catalog
4在rman中创建catalog
RMAN> create catalog tablespace rman_catalog;
ORACLE error from recovery catalog database: ORA-01031: insufficient privileges
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06433: error installing recovery catalog
RMAN> create catalog tablespace rman_catalog;
ORACLE error from recovery catalog database: ORA-00955: name is already used by an existing object
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06433: error installing recovery catalog
解决方式:
drop user rman_catalog cascade; 重建用户跟赋予权限
RMAN> create catalog tablespace rman_catalog;
recovery catalog created===========创建成功
5 一个恢复目录数据库可以同时为多个目标数据库提供服务,要使用目录数据时,必须先注册该数据库
[oracle@localhost ~]$ rman target / catalog scott/987064@grs
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 24 17:39:15 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GRS (DBID=325518186)
connected to recovery catalog database
RMAN> register database
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of register command at 10/24/2013 17:39:33
RMAN-06428: recovery catalog is not installed
Rman>unregister database---可以取消注册
[oracle@localhost ~]$ rman target / catalog rman_catalog/rman_catalog@grs
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 24 17:54:03 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GRS (DBID=325518186)
connected to recovery catalog database
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
对之后创建的备份信息都会存入恢复目录中,备份信息是否存在catalog中,看在rman是是否指定了catalog模式连接,
5.7 是否启用优化备份
满足某些条件,rman自动跳过某些文件
1 Configure backup optimization参数设置为on
2执行backup database或backup archivelog中带有all或者like参数
3分配的通道只使用了一种设备类型
RMAN> configure backup optimization on;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored
5.8是否对备份集进行压缩
10g版本新加了可以压缩功能
Rman>backup as compressed backupset tablespace yyhhqq
RMAN> list backup of tablespace yyhhqq;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 645.97M DISK 00:02:35 24-OCT-13
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20131024T105740
Piece Name: /u01/oracle/backup/back_05on6v94_1_1
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
25 Full 712.00K DISK 00:00:09 25-OCT-13
BP Key: 25 Status: AVAILABLE Compressed: YES Tag: TAG20131025T110610
Piece Name: /u01/oracle/backup/backup_compress_0ton9k52_1_1
List of Datafiles in backup set 25
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 1032037 25-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf
5.9 是否启用备份集加密
10g r2后可以对备份集进行加密,对备份集进行了加密,在恢复时需要相应的解密
Oracle提供了3种加密模式:透明加密:密码模式:双重模式
Rman提供了2种两种方式设置加密
Configure命令—预定义配置,除非显示修改,否则一直有效
Set encryption 命令—对当前session有效
1使用configure命令启用备份加密(先在db端配置好了 oracle 钱夹)
Rman>configure encryption for database on;然后在执行备份创建的备份集,就是加密备份集
Rman>configure encryption for database off;关闭
Rman>configure encryption for tablespace yyhhqq on;指定在表空间级
2 使用set encryption命令随时都可以
Rman> set encryption on identified by enback only;----enback 密钥
5.6 实战rman备份
编写脚本
5.6.1编写rman批处理文件
[oracle@localhost ~]$ cd /u01/oracle/backup/logs/
[oracle@localhost logs]$ vi yhq_rman_test.man
RUN {
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;--并行2
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/oracle/backup/rman_backup_%F';
ALLOCATE CHANNEL C1 DEVICE TYPE DISK FORMAT '/u01/oracle/backup/rman_backup_%U';
BACKUP AS COMPRESSED BACKUPSET DATABASE SKIP INACCESSIBLE FILESPERSET 10—开启压缩
PLUS ARCHIVELOG FILESPERSET 20
DELETE ALL INPUT;
RELEASE CHANNEL C1;
}
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
DELETE NOPROMPT OBSOLETE;
数据库全备份,同时备份控制文件及归档日志文件,备份文件保存在F:\MYDB\BACKUP\目录下,并在完成归档日志文件备份后,自动删除已备份的归档日志
备份保留至7天,过期自动删除
保留操作日志备查
将此文件保存至F:\MYDB\BACKUP\yyhhqq.rman
(1) backup skip 参数:
SKIP INACCESSIBLE 表示跳过不可读的文件,
SKIP OFFLINE:表示跳过offline 的数据文件
Skip readonly:表示跳过那些所在表空间为read only的数据文件
(2) filesperset参数—默认64
用来设置一个备份集中最多包含的文件,超过设置的数,在执行备份时会创建多个归档文件的备份集
(3) ALLOCATE CHANNEL FOR MAINTENANCE
用来分配通道,但分配的通道专用于 change,delete,crosscheck,不能包含在run块中,
PLUS ARCHIVELOG:rman会自动对当前的archivelog进行归档,
5.6.2 编写命令执行批处理脚本
设置备份的数据库的sid=orcl,将日志按照日期输出在F:\MYDB\BACKUP
[oracle@localhost ~]$ mkdir /u01/oracle/backup/logs
[oracle@localhost logs]$ vi rman_yhq_test.bat
set ORACLE_SID=grs
rman target / log /u01/oracle/backup/logs\bak_%date:~0,10%.log cmdfile=/u01/oracle/backup/logs/yhq_rman_test.man
将上述内容保存至/u01/oracle/backup/logs/ rman_yhq_test.bat
[oracle@localhost logs]$ ll
总计 16
-rwxr-xr-x 1 oracle oinstall 133 10-25 15:10 rman_yhq_test.bat
-rw-r--r-- 1 oracle oinstall 512 10-25 15:06 yhq_rman_test.man
[oracle@localhost logs]$ chmod +x rman_yhq_test.bat ----可执行文件?
[oracle@localhost logs]$ ll
总计 16
-rwxr-xr-x 1 oracle oinstall 133 10-25 15:10 rman_yhq_test.bat
-rw-r--r-- 1 oracle oinstall 512 10-25 15:06 yhq_rman_test.man
[oracle@localhost logs]$ ./rman_yhq_test.bat
5.6.3设定执行计划
Windows下,控制面板-任务计划中-添加任务计划,运行f:\mydb\backup\yyhhqq.bat
[mysql@hongquan ~]$ more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
30 01 * * 0 oracle /u02/scripts_oracle/r_f_level0.sh >> /u02/for_crontab/mylog.log 2>&1
30 01 * * 3 oracle /u02/scripts_oracle/r_f_level1.sh >> /u02/for_crontab/mylog.log 2>&1
30 01 * * 1,2,4,5,6 oracle /u02/scripts_oracle/r_f_level2.sh >> /u02/for_crontab/mylog.log 2>&1
###
RMAN-08591: WARNING: invalid archived log deletion policy
RMAN> configure ARCHIVELOG DELETION POLICY clear;
5.7 rman基础补充
5.7.1 format格式化
%F特定的对control file?
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup plus archivelog command at 08/05/2015 01:16:30
ORA-19715: invalid format F for generated name
ORA-27302: failure occurred at: slgpn
FORMAT
BACKUP
FORMAT 'AL_%d/%t/%s/%p'
ARCHIVELOG LIKE '%arc_dest%';
TAG
BACKUP
TAG 'weekly_full_db_bkup'
DATABASE MAXSETSIZE 10M;
5.7.2 通过configure进行预定义配置
Rman>show all;
后面有#default,表示没有修改默认配置
如果想恢复到默认值:configure retention policy clear;
1 configure retention policy 配置备份集保留策略
A 基于时间
configure retention policy to recovery window of n days;
b 基于冗余数量的保留策略
configure retention policy to redundancy n;--n大于=1的整数
c 取消设置的保留策略
configure retention policy to none;
2 configure backup optimization配置备份集优化
configure backup optimization on;
configure backup optimization off;
3 configure default device type 配置I/O设备类型
configure default device type to dick/sbt
配置磁盘的默认并行度为2
Configure device type disk parallelism 2;
4 configure controlfile autobackup配置控制文件自动备份
configure controlfile autobackup off/on ;
同时指定备份的路径和格式
Configure controlfile autobackup format for device type disk to ‘f:\mydb\backup\%f’;
备份期间,将产生一个控制文件的快照,用于控制文件的读一致性,快照可以通过如下配置
Configure snapshot controlfile name to ‘f:\xxxx\..ora’;
5 configure device type 设置并行配置
Configure device type disk parallelism 2;指定在以后的备份和恢复操作中的并行度为2,同时开启2个通道进行备份和恢复,
默认情况下,自动分配通道的并行度为1,如果通过parallelism设置了并行度为2,那么在run块中,如果没有单独设置allocate channel命令指定通道,它会默认使用2条通道并行,如果run块中设置了allocate channel指定通道,那么rman在备份时已channel为准,不管configure的。
在backup备份时,filesperset参数默认是64
6 configure datafile/archivelog backup copies设置备份文件的冗余度
configure datafile/archivelog backup copies 2;
7 configure maxsetsize设置备份集的最大尺寸
allocate channel c1 device type disk maxpiecesize=10m format 'f:\mydb\backup\back_%u';
8 configure encryption配置备份集加密
10g新特性,前提是配置好了oracle钱夹功能。
5.7.3 set 设置会话级
1 常在run块外运行的命令
显示或关闭rman提示
Rman>set echo off/on;
指定客户端信息
Set command id to‘scott’;然后查看v$session视图,会发现一条client_Info列值包含了id=scott;的信息,相当于加了一条标示,便于查看备份的状态。
指定数据库的标示符,只能在nomount模式下运行,--mount—open
Rman>set dbid n;n 10长度组成的字符串
2 常在run块中运行的命令
给数据文件指定路径和名称
Run{
Allocate channel c1 device type disk;
Set newname for datafile 4 to ‘f:\oracle\oracledata\user01.dbf’;
}
设置恢复到的时间或scn
Run{
Allocate channel c1 device type disk;
Set until time “to_date(‘2013-07-24’,’yyyy-mm-dd’)”;
}
定义备份片段的冗余数
Set backup copies 3;
指定restore/recover命令产生的归档文件的路径
默认情况下,这些归档文件会存储在初始化参数log_archive_dest_1指定的路径,
SET ARCHIVELOG DESTINATION TO ‘F:\ORACLE\ORACOEDATE\ARCHIVE\’;
5.7.4 增量备份的工作机制
1 差异备份(默认)
2 累计增量备份
1 level0 backup
#!/bin/bash
# full backup script
source /home/oracle/.bash_profile
current_day=`date '+%Y%m%d-%H%M'`
incr_day=incr_$current_day
#mkdir /u02/backup_incr/$incr_day
echo '-------------------------------------'
echo "-- Begin Increment Backup of DB 192.168.32.8 DateTime: `date` --"
echo '-------------------------------------'
rman target / log=/u02/logs/rman_logs_$current_day.log <<EOF
RUN
{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/backup_incr/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;
ALLOCATE CHANNEL C1 DEVICE TYPE DISK MAXPIECESIZE=1024M FORMAT '/u02/backup_incr/r_%n_%T_%U_lev0';
ALLOCATE CHANNEL C2 DEVICE TYPE DISK MAXPIECESIZE=1024M FORMAT '/u02/backup_incr/r_%n_%T_%U_lev0';
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 TAG 'LOCAL_LEVEL0'
DATABASE SKIP INACCESSIBLE FILESPERSET 10
PLUS ARCHIVELOG FILESPERSET 20;
# DELETE ALL INPUT;
BACKUP ARCHIVELOG ALL FORMAT '/u02/backup_incr/arc_%n_%T_%U';
RELEASE CHANNEL C1;
RELEASE CHANNEL C2;
}
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
REPORT OBSOLETE;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED BACKUP;
EOF
echo '------------------------------------'
echo "-- End Increment Backup of DB 192.168.32.8 DateTime: `date` --"
echo '------------------------------------'
#scp -l 51200 -r /u02/backup/$incr_day oracle@192.168.32.9:/u02/backup/ &
#wait
echo '------------------------------------'
echo "-- End of Send file to 192.168.32.8 DateTime: `date` --"
echo '------------------------------------'
echo ''
echo ''
2 level1
INCREMENTAL LEVEL 1 TAG 'LOCAL_LEVEL1'
BACKUP INCREMENTAL LEVEL 0 DATABASE;
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
BACKUP INCREMENTAL LEVEL 1 DATABASE;
RECOVER COPY OF DATABASE
WITH TAG 'incr_update';
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'incr_update'
DATABASE;
5.7.5 备份加密模式
3种
5.7.6 恢复目录数据(recovery catalog)
5.7.8 rman 备份的相关视图
1 v$archived_Log视图
select name,thread#,sequence#,first_time,creator,applied,status from v$archived_Log
1 20 2013-10-24 9:26:58 FGRD NO D
1 21 2013-10-24 14:54:33 FGRD NO D
1 22 2013-10-24 15:47:59 ARCH NO D
creator:arch由归档进程创建
fgrd由前台进程创建
rman由rman创建
srmn由standby端的rman创建
lgwr由logwritor进程创建
status:a 正常归档状态
d 该记录指向的归档文件已经删除
u 该记录执行的归档文件不存在
x 指该条记录失效,通常是在rman中执行了crosscheck archivelog检查后有可能出现
2 v$backup_set视图
显示了当前创建的备份集信息,与list backup类型
select * from v$backup_set
backup_type字段:l:表示包含归档重做日志文件
d:表示数据文件完全备份
i:表示增量备份
v$backup_set_details:包含了v$backup_set的信息,而已还有备份集的大小,所在设备,
select * from v$backup_set_details
device_type:DISK
3 v$backup_piece 显示备份片段的信息,
Status:a (可用),d(已删除),x(不存在)
select * from v$backup_piece where status=’a’ and handle is not null
v$backup_piece_details
4 v$backup_corruption 记录了备份集中发行损坏的数据块,当在rman 中执行了backup validate 命令对备份集进行检查后,如果发行有操作的数据块就会写入该视图中,不包括控制文件和归档文件,他们是一个独立体,一旦损坏,就无法修复,
select * from v$backup_corruption
5 v$session v$process
v$session 每一个连接到oracle的会话都会在改视图中有一条记录
select sid,serial#,paddr,username,client_info,osuser,machine,terminal,program,sql_address,sql_hash_value,event from v$session
v$process 视图中一条记录对应为操作系统中的一个进程(winddow为线程)
select * from v$process
6 v$session_longops 记录数据库中执行时间超过6秒的操作,
select * from v$session_longops
5.8 备份策略的制定
1 最早希望恢复到什么时间点
只关心数据库的状态是否正常,可以采用基于冗余数量的备份,保留策略为保留最近的3份
Rman>configure retention policy to redundancy 3
对于关心做过什么操作,并且希望恢复到某个时间点,
可用logminer来分析目标数据库的归档文件,并保证在恢复时间点之前创建的有备份,以及相关的归档文件,可用选择基于冗余时间的保留备份策略,
比如最早恢复到7天
Rman>configure retention policy to recovery window of 7 days;
由于备份集占用空间的大小,必须考虑到设备存储设备空闲的问题
2 系统什么时间比较空闲
备份的大量读写会占用大量资源,在数据库空闲的时间来备份
3 数据库的数据规模大小
1 >1TB 2 1TB<X>200GB 3 <200G
大量数据的备份时间较长,恢复时间可能更长
数据规模较小的可以进行全备份
4 数据修改频繁度
1 每天修改10%的数据
2 每天基本没变化,只有少量修改
3 数据每天都在变,但量不大
对于1,基本不采用增量备份
对于2 可以采用增量备份
对于3 根据数据规模来确定是否采用增量备份
5 能否预估给予的恢复时间
对于核心业务,采用rman恢复,做不到快速恢复,得采用其他的高可用性能
非核心业务,不需要及时恢复
6 什么原因导致的错误
1 用户误操作—flashback:利用之前的备份,恢复到错误的时间点之前:输入正确数据
2 介质故障—备份
3 数据块错误—rman进行数据块修复
备份策略决定了恢复方式,能恢复的数据及恢复的效率