1、数据库全备到硬盘
创新互联建站专注于青山企业网站建设,响应式网站建设,商城建设。青山网站建设公司,为青山等地区提供建站服务。全流程定制网站建设,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务[oracle@centos7 scripts]$ cat rman_backup.sh source /home/oracle/.bash_profile rman target / log=/home/oracle/backup/backupall_rman.log<<EOF run { allocate channel ch2 device type disk; #分配通道 allocate channel ch3 device type disk; sql 'alter system archive log current'; #归档当前日志 backup database format '/home/oracle/backup/db_%d_%T_%U'; #备份数据文件 sql 'alter system archive log current'; backup archivelog all format '/home/oracle/backup/arch_%t_%s' delete all input; #备份归档文件 backup format '/home/oracle/backup/con_%s_%p' current controlfile; #备份控制文件 crosscheck backup; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before 'sysdate -15'; #删除15天之前的数据库备份集 delete noprompt archivelog all; delete noprompt backup of archivelog all completed before 'sysdate -15'; #删除15天之前的归档备份集 release channel ch2; release channel ch3; } EOF2、增量备份脚本
0级增量
[oracle@centos7 scripts]$ cat rman_backup_level0.sh source /home/oracle/.bash_profile rman target / log=/home/oracle/backup/backupall_rman.log<<EOF run { allocate channel ch2 device type disk; #分配通道 allocate channel ch3 device type disk; sql 'alter system archive log current'; #归档当前日志 backup incremental level 0 database format '/home/oracle/backup/db_level0_%d_%T_%U'; #备份数据文件 sql 'alter system archive log current'; backup archivelog all format '/home/oracle/backup/arch_level0_%t_%s' delete all input; #备份归档文件 backup format '/home/oracle/backup/con_level0_%s_%p' current controlfile; #备份控制文件 crosscheck backup; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before 'sysdate -15'; #删除15天之前的数据库备份集 delete noprompt archivelog all; delete noprompt backup of archivelog all completed before 'sysdate -15'; #删除15天之前的归档备份集 release channel ch2; release channel ch3; } EOF1级增量
[oracle@centos7 scripts]$ cat rman_backup_level1.sh source /home/oracle/.bash_profile rman target / log=/home/oracle/backup/backupall_rman.log<<EOF run { allocate channel ch2 device type disk; #分配通道 allocate channel ch3 device type disk; sql 'alter system archive log current'; #归档当前日志 backup incremental level 1 database format '/home/oracle/backup/db_level1_%d_%T_%U'; #备份数据文件 sql 'alter system archive log current'; backup archivelog all format '/home/oracle/backup/arch_level1_%t_%s' delete all input; #备份归档文件 backup format '/home/oracle/backup/con_level1_%s_%p' current controlfile; #备份控制文件 crosscheck backup; crosscheck archivelog all; delete noprompt expired backup; delete noprompt obsolete; delete noprompt backup of database completed before 'sysdate -15'; #删除15天之前的数据库备份集 delete noprompt archivelog all; delete noprompt backup of archivelog all completed before 'sysdate -15'; #删除15天之前的归档备份集 release channel ch2; release channel ch3; } EOF注意:1级备份需要在0级备份的基础上执行。
3、支持全备和增量备份
[oracle@centos7 scripts]$ cat db_back_rman.sh ##=========================================================== ## db_bak_rman.sh ## created by Robinson ## 2017/12/15 ## usage: db_bak_rman.sh <$ORACLE_SID> <$BACKUP_LEVEL> ## BACKUP_LEVEL: ## F: full backup ## 0: level 0 ## 1: level 1 ##============================================================ #!/bin/bash # User specific environment and startup programs if [ -f ~/.bash_profile ]; then . ~/.bash_profile fi ORACLE_SID=${1}; export ORACLE_SID RMAN_LEVEL=${2}; export RMAN_LEVEL TIMESTAMP=`date +%Y%m%d%H%M`; export TIMESTAMP DATE=`date +%Y%m%d`; export DATE RMAN_DIR=/u02/database/${ORACLE_SID}/backup/rman; export RMAN_DIR RMAN_DATA=${RMAN_DIR}/${DATE}; export RMAN_DATA #RMAN_LOG=$RMAN_DATA/log; export RMAN_LOG RMAN_LOG=/u02/database/${ORACLE_SID}/backup/rman/log export RMAN_LOG # Check rman level #====================================================================== if [ "$RMAN_LEVEL" == "F" ]; then unset INCR_LVL BACKUP_TYPE=full else INCR_LVL="INCREMENTAL LEVEL ${RMAN_LEVEL}" BACKUP_TYPE=lev${RMAN_LEVEL} fi RMAN_FILE=${RMAN_DATA}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}; export RMAN_FILE SSH_LOG=${RMAN_LOG}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}.log; export SSH_LOG MAXPIECESIZE=4G; export MAXPIECESIZE #Check RMAN Backup Path #========================================================================= if ! test -d ${RMAN_DATA} then mkdir -p ${RMAN_DATA} fi echo "---------------------------------" >>${SSH_LOG} echo " " >>${SSH_LOG} echo "Rman Begin to Working ........." >>${SSH_LOG} echo "Begin time at:" `date` --`date +%Y%m%d%H%M` >>${SSH_LOG} #Startup rman to backup #============================================================================= $ORACLE_HOME/bin/rman log=${RMAN_FILE}.log <<EOF connect target / run { CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS; CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${RMAN_FILE}_%F'; ALLOCATE CHANNEL 'ch2' TYPE DISK maxpiecesize=${MAXPIECESIZE}; ALLOCATE CHANNEL 'ch3' TYPE DISK maxpiecesize=${MAXPIECESIZE}; set limit channel ch2 readrate=10240; set limit channel ch2 kbytes=4096000; set limit channel ch3 readrate=10240; set limit channel ch3 kbytes=4096000; CROSSCHECK ARCHIVELOG ALL; DELETE NOPROMPT EXPIRED ARCHIVELOG ALL; BACKUP #AS COMPRESSED BACKUPSET ${INCR_LVL} DATABASE FORMAT '${RMAN_FILE}_%U' TAG '${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}'; SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT'; BACKUP ARCHIVELOG ALL FORMAT '${RMAN_FILE}_arc_%U' TAG '${ORACLE_SID}_arc_${TIMESTAMP}' DELETE INPUT; DELETE NOPROMPT OBSOLETE; RELEASE CHANNEL ch2; RELEASE CHANNEL ch3; } sql "alter database backup controlfile to ''${RMAN_DATA}/cntl_${BACKUP_TYPE}.bak''"; exit; EOF RC=$? cat ${RMAN_FILE}.log >>${SSH_LOG} echo "Rman Stop working @ time:"`date` `date +%Y%m%d%H%M` >>${SSH_LOG} echo >>${SSH_LOG} echo "------------------------" >>${SSH_LOG} echo "------ Disk Space ------" >>${SSH_LOG} df -h >>${SSH_LOG} echo >>${SSH_LOG} if [ $RC -ne "0" ]; then echo "------ error ------" >>${SSH_LOG} else echo "------ no error found during RMAN backup peroid------" >>${SSH_LOG} rm -rf ${RMAN_FILE}.log fi #Remove old backup than 3 days #============================================================================ RMDIR=${RMAN_DIR}/`/bin/date +%Y%m%d -d "3 days ago"`; export RMDIR echo >>${SSH_LOG} echo -e "------Remove old backup than 3 days ------\n" >>${SSH_LOG} if test -d ${RMDIR} then rm -rf ${RMDIR} RC=$? fi echo >>${SSH_LOG} if [ $RC -ne "0" ]; then echo -e "------ Remove old backup exception------ \n" >>${SSH_LOG} else echo -e "------ no error found during remove old backup set peroid------ \n" >>${SSH_LOG} fi exit另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享名称:rman备份脚本shell版-创新互联
标题链接:https://www.cdcxhl.com/article46/dhiceg.html
成都网站建设公司_创新互联,为您提供云服务器、定制开发、App设计、品牌网站建设、域名注册、网页设计公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联