积累增量和差异增量:
对于 RMAN 来说,积累增量备份和差异增量备份都是增量备份的一种形式,它们之间的区别在于备份的范围和备份集的方式。
- 积累增量备份:在进行积累增量备份时,RMAN 会备份自最后一次完全备份或增量备份以来所做的所有更改数据,并将这些更改应用到备份集中。这样可以保证备份集中包含完整的数据集变化历史,并且能够恢复到任意时间点。
积累增量备份命令示例:
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
- 差异增量备份:在进行差异增量备份时,RMAN 会备份自最后一次完全备份以来所做的所有更改数据,但不会将这些更改应用到备份集中。相反,RMAN 会创建一个只包含最新增量备份数据的备份集。因此,差异增量备份的备份集更小,还原数据需要使用完全备份和最近的差异增量备份。
差异增量备份命令示例:
BACKUP INCREENTAL LEVEL 1 DATABASE;
备份策略:
shell脚本编写oracle rman增量备份,如果是星期天执行0级增量,如果是星期三执行积累增量,星期六执行全量备份其余均执行差异增量备份
#!/bin/bash
export DBNAME=orclcdb
export ORACLE_SID=orclcdb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$HOME/bin:$PATH
export BACPATH=/u01/app/oracle/oradata/backup
export BACTIME=`date "+%Y-%m-%d"`
export LGNAME=rman_backup_`date "+%Y-%m-%d"`.log
mkdir ${BACPATH}/$BACTIME
current_day=$(date +%A) # 获取当前星期几
if [ "$current_day" = "Sunday" ]; then
# 执行0级增量备份
rman target / > ${BACPATH}/${BACTIME}/${LGNAME} << EOF
run{
CONFIGURE RETENTION POLICY TO REDUNDANCY 7;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${BACPATH}/${BACTIME}/${DBNAME}_ful_%U';
ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
BACKUP INCREMENTAL LEVEL 0 DATABASE format '${BACPATH}/${BACTIME}/${DBNAME}_ful0_data_file_%d_%T_%s_%p_%u';
sql 'alter system archive log current';
backup archivelog all format '${BACPATH}/${BACTIME}/${DBNAME}_arc_%U';
backup current controlfile format '${BACPATH}/${BACTIME}/${DBNAME}_ctl_%U';
backup spfile format '${BACPATH}/${BACTIME}/${DBNAME}_spf_%U';
release channel c1;
}
quit
EOF
elif [ "$current_day" = "Wednesday" ]; then
# 执行积累增量备份
rman target / > ${BACPATH}/${BACTIME}/${LGNAME} << EOF
run{
CONFIGURE RETENTION POLICY TO REDUNDANCY 7;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${BACPATH}/${BACTIME}/${DBNAME}_ful_%U_%I';
ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE format '${BACPATH}/${BACTIME}/${DBNAME}_fulCUM_data_file_%d_%T_%s_%p_%u_%I';
sql 'alter system archive log current';
backup archivelog all format '${BACPATH}/${BACTIME}/${DBNAME}_arc_%U_%I';
backup current controlfile format '${BACPATH}/${BACTIME}/${DBNAME}_ctl_%U_%I';
backup spfile format '${BACPATH}/${BACTIME}/${DBNAME}_spf_%U_%I';
release channel c1;
}
quit
EOF
elif [ "$current_day" = "Saturday" ]; then
# 执行全量备份
rman target / > ${BACPATH}/${BACTIME}/${LGNAME} << EOF
run{
CONFIGURE RETENTION POLICY TO REDUNDANCY 7;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${BACPATH}/${BACTIME}/${DBNAME}_ful_%U_%I';
ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
BACKUP DATABASE format '${BACPATH}/${BACTIME}/${DBNAME}_ful_data_file_%d_%T_%s_%p_%u_%I';
sql 'alter system archive log current';
backup archivelog all format '${BACPATH}/${BACTIME}/${DBNAME}_arc_%U_%I';
backup current controlfile format '${BACPATH}/${BACTIME}/${DBNAME}_ctl_%U_%I';
backup spfile format '${BACPATH}/${BACTIME}/${DBNAME}_spf_%U_%I';
release channel c1;
}
quit
EOF
else
# 执行差异增量备份
rman target / > ${BACPATH}/${BACTIME}/${LGNAME} << EOF
run{
CONFIGURE RETENTION POLICY TO REDUNDANCY 7;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${BACPATH}/${BACTIME}/${DBNAME}_ful_%U_%I';
ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
BACKUP INCREMENTAL LEVEL 1 DATABASE format '${BACPATH}/${BACTIME}/${DBNAME}_fulINC_data_file_%d_%T_%s_%p_%u_%I';
sql 'alter system archive log current';
backup archivelog all format '${BACPATH}/${BACTIME}/${DBNAME}_arc_%U_%I';
backup current controlfile format '${BACPATH}/${BACTIME}/${DBNAME}_ctl_%U_%I';
backup spfile format '${BACPATH}/${BACTIME}/${DBNAME}_spf_%U_%I';
release channel c1;
}
quit
EOF
fi