oracle accumulation increment and difference increment

Accumulation incremental and differential incremental backup:
For RMAN, accumulation incremental backup and differential incremental backup are both forms of incremental backup. The difference between them lies in the scope of backup and the way of backup set.

  1. Cumulative incremental backup: When performing a cumulative incremental backup, RMAN backs up all changed data since the last full or incremental backup and applies these changes to the backup set. This ensures that the backup set contains the complete history of data set changes and can be restored to any point in time.
    Example of cumulative incremental backup command:
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
  1. Differential incremental backup: When performing a differential incremental backup, RMAN backs up all changed data since the last full backup, but does not apply these changes to the backup set. Instead, RMAN creates a backup set that contains only the latest incremental backup data. Therefore, a differential incremental backup has a smaller backup set, and restoring data requires a full backup and the most recent differential incremental backup.
    Differential incremental backup command example:
BACKUP INCREENTAL LEVEL 1 DATABASE;

Backup strategy:
Insert image description here

Write Oracle RMAN incremental backup in shell script. If it is Sunday, perform level 0 increment. If it is Wednesday, perform cumulative increment. Perform full backup on Saturday. The rest will perform differential incremental backup.

#!/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

Guess you like

Origin blog.csdn.net/qq_39412605/article/details/132182719