rman增量备份脚本

配置rman

登录rman 

rman  target  /

RMAN> show all
2> ;


using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PU are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;   ----备份过期设定到7天
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF;                         -----不开启,自己写备份脚本
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/rmanbackup/bak_%F';              -----备份存放的路径
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/11g/dbs/snapcf_pu.f'; # default


编写level0脚本

#!/bin/bash
#export NLS_LANG='AMERICAN_AMERICA.AL32UTF8' ----字符集设置
export ORACLE_BASE=/u01/oracle ----目录
export ORACLE_HOME=/u01/11g ----家目录
export ORACLE_SID=pu ----sid
#export PATH=$PATH:$ORACLE_HOME/bin ----绝对路径下,加这行

/u01/11g/bin/rman target / <<EOF
run {
allocate channel c1 type disk;
allocate channel c2 type disk;                        -----开启两个队列      
backup incremental level 0  format '/u01/rmanbackup/lev0_db_%d_%T_t%t_s%s_p%p' database;-----备份数据库
sql 'alter system archive log current'; -----切换当前日志
backup  format '/u01/rmanbackup/lev0_controlfile_%d_%T_t%t_s%s_p%p' current controlfile;-----备份当前归档日志
backup archivelog all delete input format '/u01/rmanbackup/lev0_log_%d_%T_t%t_s%s_p%p';-----备份归档日志,并清空已备份的归档日志
release channel c1;
release channel c2;
crosscheck backup; -----检查过期的备份
delete noprompt obsolete; -----删除过期的备份
}
exit;

<<EOF


编写level1脚本

#!/bin/bash
#export NLS_LANG='AMERICAN_AMERICA.AL32UTF8' ----字符集设置
export ORACLE_BASE=/u01/oracle ----目录
export ORACLE_HOME=/u01/11g ----家目录
export ORACLE_SID=pu ----sid
#export PATH=$PATH:$ORACLE_HOME/bin ----绝对路径下,加这行

/u01/11g/bin/rman target / <<EOF
run {
allocate channel c1 type disk;
allocate channel c2 type disk;                        -----开启两个队列      
backup incremental level 0  format '/u01/rmanbackup/lev1_db_%d_%T_t%t_s%s_p%p' database;-----备份数据库
sql 'alter system archive log current'; -----切换当前日志
backup  format '/u01/rmanbackup/lev1_controlfile_%d_%T_t%t_s%s_p%p' current controlfile;-----备份当前归档日志
backup archivelog all delete input format '/u01/rmanbackup/lev1_log_%d_%T_t%t_s%s_p%p';-----备份归档日志,并清空已备份的归档日志
release channel c1;
release channel c2;
crosscheck backup; -----检查过期的备份
delete noprompt obsolete; -----删除过期的备份
}
exit;

<<EOF


写入到crontab里面

[oracle@oracle ~]$ crontab -l
#2 level0
0 0 * * 2 /home/oracle/level_0.sh >>/tmp/bak.log 2>&1         每周2,0点0分做0级备份,备份日志保存到/tmp/bak.log   
#level1
0 0 * * 0,1,3,4,5,6  /home/oracle/level_1.sh 1级备份

你可能感兴趣的:(rman增量备份脚本)