龙空技术网

oracle备份恢复---分享RMAN定时全备份和增备脚本(0+1)

波波说运维 11380

前言:

现时姐妹们对“oracle备份时full”大致比较关心,我们都想要知道一些“oracle备份时full”的相关资讯。那么小编也在网摘上收集了一些对于“oracle备份时full””的相关资讯,希望咱们能喜欢,朋友们快快来了解一下吧!

概述

分享之前自己写的两个rman备份恢复脚本,大家可以自己跟着测试一下,修改一些自定义参数,根据实际情况更改创建目录,全备及增量备份的日期根据需要设置就可以了。

下面分享下脚本的内容。

RMAN定时全备脚本1、建立对应目录

mkdir -p /rmanbackup/rmanlogmkdir -p /rmanbackup/dbbakmkdir -p /rmanbackup/scriptsmkdir -p /rmanbackup/weekmkdir -p /rmanbackup/daychown -R oracle:oinstall /rmanbackupchmod -R 755 /rmanbackup
2、脚本内容(oracle执行)

vi /rmanbackup/scripts/rmanbackup.sh

#/bin/bash export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1export ORACLE_OWNER=oracleexport ORACLE_SID=nwppdb_1export ORACLE_UNQNAME=nwppdbexport PATH=/u01/app/oracle/product/11.2.0/db_1/bin:/u01/app/oracle/product/11.2.0/db_1/OPatch:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/binexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/libexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlibexport NLS_LANG=AMERICAN_AMERICA.ZHS16GBKexport NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"export ORACLE_PATH=/home/oracle today=`date +%Y-%m-%d` #删除7天过期的 find /rmanbackup/dbbak/ -name "*full*" -mtime +7 -exec rm {} \; find /rmanbackup/dbbak/ -name "*archivelog*" -mtime +7 -exec rm {} \; find /rmanbackup/dbbak/ -name "controlfile*" -mtime +7 -exec rm {} \; find /rmanbackup/dbbak/ -name "spfile*" -mtime +7 -exec rm {} \; #全备 rman target / nocatalog log /rmanbackup/rmanlog/rmanbk_$today.log append <<EOF run {  crosscheck backup; delete noprompt expired backup;  allocate channel c1 device type disk; --maxpiecesize = 3500M 限制RMAN备份片的大小  allocate channel c2 device type disk;  allocate channel c3 device type disk;  allocate channel c4 device type disk; backup as compressed backupset format '/rmanbackup/dbbak/nwppdb_full_%T_%d_%s_%p_%u.dbf' database plus archivelog;  sql "ALTER SYSTEM switch logfile";  sql "ALTER SYSTEM switch logfile"; sql "ALTER SYSTEM switch logfile";  delete noprompt archivelog until time 'sysdate-7'; backup current controlfile format '/rmanbackup/dbbak/controlfile_%T_%U_%t.crl';  backup spfile format '/rmanbackup/dbbak/spfile_%T_%U_%t.ora';  release channel c1;  release channel c2;  release channel c3; release channel c4;  }exit EOF 

日志输出:

生成如下:

3、定时任务(oracle)

格式:分钟 小时 几号 月份 星期几 command

30 22 * * * /rmanbackup/scripts/rmanbackup.sh

二、RMAN增备脚本(0+1)

1、备份脚本

1.1 周末0级全备

vi /rmanbackup/scripts/rman_0_level_full.sh

#/bin/bash export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1export ORACLE_OWNER=oracleexport ORACLE_SID=nwppdb_1export ORACLE_UNQNAME=nwppdbexport PATH=/u01/app/oracle/product/11.2.0/db_1/bin:/u01/app/oracle/product/11.2.0/db_1/OPatch:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/binexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/libexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlibexport NLS_LANG=AMERICAN_AMERICA.ZHS16GBKexport NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"export ORACLE_PATH=/home/oracle today=`date +%Y-%m-%d` #删除7天过期的 find /rmanbackup/week/ -name "*full*" -mtime +7 -exec rm {} \; find /rmanbackup/week/ -name "*arch*" -mtime +7 -exec rm {} \; find /rmanbackup/week/ -name "ctl*" -mtime +7 -exec rm {} \; find /rmanbackup/week/ -name "spfile*" -mtime +7 -exec rm {} \; #0级全备 rman target / nocatalog msglog /rmanbackup/rmanlog/fullback0_$today.log <<EOFrun{crosscheck backup;delete noprompt expired backup;allocate channel d1 type disk;allocate channel d2 type disk;allocate channel d3 type disk;allocate channel d4 type disk;backup incremental level 0 as compressed backupset database format '/rmanbackup/week/nwppdbfull0_%d_%T_%t_%s_%p';sql 'alter system archive log current';backup as compressed backupset filesperset 10 format '/rmanbackup/week/arch_%d_%T_%t_%s_%p' archivelog all;backup current controlfile format '/rmanbackup/week/ctl_%d_%T_%t_%s_%p';backup spfile format '/rmanbackup/week/spfile_%T_%U_%t.ora';release channel d1;release channel d2;release channel d3;release channel d4;}EOF

1.2 周一到周六,针对周末的0级全备,每天进行1级差异增量备份

vi /rmanbackup/scripts/rman_1_level_incremental.sh

#/bin/bash export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1export ORACLE_OWNER=oracleexport ORACLE_SID=nwppdb_1export ORACLE_UNQNAME=nwppdbexport PATH=/u01/app/oracle/product/11.2.0/db_1/bin:/u01/app/oracle/product/11.2.0/db_1/OPatch:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/binexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/libexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlibexport NLS_LANG=AMERICAN_AMERICA.ZHS16GBKexport NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"export ORACLE_PATH=/home/oracle today=`date +%Y-%m-%d` #删除7天过期的 find /rmanbackup/day/ -name "*full*" -mtime +7 -exec rm {} \; find /rmanbackup/day/ -name "*arch*" -mtime +7 -exec rm {} \; find /rmanbackup/day/ -name "ctl*" -mtime +7 -exec rm {} \; find /rmanbackup/day/ -name "spfile*" -mtime +7 -exec rm {} \; rman target / nocatalog msglog /rmanbackup/rmanlog/incrementback1_$today.log <<EOFrun{crosscheck backup;delete noprompt expired backup;allocate channel d1 type disk;allocate channel d2 type disk;allocate channel d3 type disk;allocate channel d4 type disk;backup incremental level 1 as compressed backupset database format '/rmanbackup/day/increment1_%d_%T_%t_%s_%p';sql 'alter system archive log current';backup as compressed backupset filesperset 10 format '/rmanbackup/day/arch_%d_%T_%t_%s_%p' archivelog all;backup current controlfile format '/rmanbackup/day/ctl_%d_%T_%t_%s_%p';backup spfile format '/rmanbackup/day/spfile_%T_%U_%t.ora';release channel d1;release channel d2;release channel d3;release channel d4;}EOF

2、crontab定时任务,避开业务繁忙时段

0 4 * * 0 /rmanbackup/scripts/rman_0_level_full.sh0 4 * * 1-6 /rmanbackup/scripts/rman_1_level_incremental.sh

单单做rman定时备份其实还不够,大家还需要定期去校验备份数据的有效性,要不指不定什么时候备份失效了呢~

后面会分享更多RMAN备份恢复方面内容,感兴趣的朋友可以关注下!

标签: #oracle备份时full