0级增量备份脚本代码清单:
create script bak_0{
crosscheck backup;
crosscheck archivelog all;
allocate channel c1 type disk maxpiecesize=200000m;
sql 'alter system archive log current';
backup incremental level 0
skip inaccessible database tag 'inc_0'
format '/oracle/ora_rman/bak_0%p_%s_%t.bak' filesperset 4
include current controlfile
plus
archivelog tag 'arc_o'
format '/oracle/ora_rman/bak_arc%U.bak' filesperset 2
delete all input ;
delete obsolete ;
release channel c1 ;
}
2.1级增量备份脚本
1级增量备份脚本代码清单:
create script bak_1{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
sql 'alter system archive log current';
backup incremental level 1 tag 'inc_1'
database
format '/oracle/ora_bak/bak_1%U.bak'
include current controlfile
plus
archivelog
format '/oracle/ora_bak/bak_arc%U.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
3.Linux RAC 环境下的备份脚本
Linux RAC 环境下的备份脚本代码清单:
run{
crosscheck archivelog all;
allocate channel c1 device type disk connect sys/xxx@node1 maxpiecesize=200000m;
allocate channel c2 device type disk connect sys/xxx@node2 maxpiecesize=200000m;
sql 'alter system archive log thread 1 current';
sql 'alter system archive log thread 2 current';
backup incremental level 0 tag 'inc_0'
database
format '/oracle/archive/arch1/ora_rman/peppdb_%p_%s_%t.bak' filesperset 10
include current controlfile
plus
archivelog
format '/oracle/archive/arch1/ora_rman/peppdb_arc%p_%s_%t.bak' filesperset 10
delete all input ;
delete obsolete ;
release channel c1 ;
release channel c2 ;
}
4.日常0级增量备份
日常0级增量备份通过脚本bak_0.sh实现,代码如下:
#!/bin/bash
#Author:xxx
#date:20240117
#Purpose:For Database Backup
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=node1
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG="American_America.UTF8"
source ~/.profile
log_path=/oracle/misc/script/backup/logs
log=back_0.log
cat /dev/null > $log_path/$log
if [ $? -ne 0 ];then
echo "Clear $log Failed!..." > /tmp/$log
fi
rman target / >/tmp/rman.log
echo $log>/tmp/rman.log
if [ $? -ne 0 ];then
echo "Errors in rman.log's heading" >> /tmp/rman.log
fi
cat $log_path/$log >> /tmp/rman.log
if [ $? -ne 0 ];then
echo "Error put rman.log message!" >> /tmp/rman.log
fi
5.日常1级增量备份
日常1级增量备份通过脚本bak_1.sh实现,代码如下:
#!/bin/bash
#Author:xxx
#date:20240117
#Purpose:For Database Backup
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=node1
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG="American_America.UTF8"
log_path=/oracle/misc/script/backup/logs
source ~/.profile
log=bak_1.log
cat /dev/null > $log_path/$log
if [ $? -ne 0 ];then
echo "Clear $log Failed!..." > /tmp/$log
fi
rman target / >/tmp/rman.log
echo $log>/tmp/rman.log
if [ $? -ne 0 ];then
echo "Errors in rman.log's head in rman.log" >> /tmp/rman.log
fi
cat $log_path/$log >> /tmp/rman.log
if [ $? -ne 0 ];then
echo "Error put rman.log message!" >> /tmp/rman.log
fi
参数说明:
Channel:是一个通道,用来连接数据库备份与备份的存储介质;
--------------------------------------------------------------------------------------------------------
通道配置选项说明:
connect:是一个Oracle Net连接串。一般不适用于单实例环境。
format:为通道创建的备份片或映像副本确定路径与文件名。
duration:控制作业的时间总量,以小时和分钟进行指定
maxopenfiles:该选项限制RMAN一次能够打开的输入文件数。
maxpiecesize:限制一个备份集分隔的备份片的大小,以字节(默认)、k、m、g为单位。
parms:能够被用于设置sbt_type通道所需的任何变量。
filesperset:备份集中可容纳的文件数。
backup set:是一个集合,是由一个或多个物理文件组成,是一个逻辑单位。
backup piece:是真正的一个输出文件,收到操作系统单个文件的限制,即 maxpiecesize 这个参数;
--------------------------------------------------------------------------------------------------------
backuppiece:备份片,表示一个由RMAN产生备份的文件。用OS工具可以实实在在看得到的。
backupset:备份集,表示进行一次备份所产生的所有备份片集合,是一个逻辑上的概念;一个数据文件可以跨备份片存在,不能跨备份集存在。
示例1:
RMAN> run
{
allocate channel c1 device type disk maxpiecesize 1500m;
backup database plus archivelog delete all input;
release channel c1;
}
allocate channel命令在目标数据库启动一个服务器进程,同时必须定义服务器进程执行备份或者恢复操作使用的I/O类型。每个备份片的最大为1500M,超过这个大小就会产生新的备份片,在启动备份时,会归档当前的日志,生成一个备份片,删除已备份的归档日志;然后备份数据文件,生成两个备份片(数据文件2G),再备份当前的SPFILE 和CONTROLFILE,生成一个备份片,最后再做一次LOGSWITCH,备份归档日志,生成一个备份片,因此可以这样描述,这个备份集包含成五个备份片,一个备份片包含文件个数由 FILESPERSET 指定。
示例2:
RMAN> run
{
allocate channel c1 device type disk maxpiecesize 1500m;
backup database filesperset 1;
release channel c1;
}