首页未分类 › oracle 利用shell脚本自动执行raman热备(全量和增量)

oracle 利用shell脚本自动执行raman热备(全量和增量)

1、不废话直接上脚本
vim oracle_rman_bak.sh
#!/bin/sh
source /home/oracle/.bash_profile

if [ -z $1 ]
then
echo “Please Input a number,Usage: 0|1|2”
exit
else
RMAN_LEVEL=$1
fi

export ORACLE_SID=jkdata
export TODAY=date '+%Y%m%d'
export RMAN_DIR=/data/backup/oracledata/rmanbak/$ORACLE_SID/$TODAY-$RMAN_LEVEL
#######
mkdir -p $RMAN_DIR
cd $RMAN_DIR
LogFile=ora_rman_bk_$ORACLE_SID-L$RMAN_LEVEL-date '+%Y%m%d'.log

# rman backup
rman target / msglog=$RMAN_DIR/$LogFile<<EOF
delete noprompt obsolete;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘$RMAN_DIR/cf%F’;
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset incremental level $RMAN_LEVEL filesperset 3 tag ‘dbL$RMAN_LEVEL’ format ‘$RMAN_DIR/ora_o_%d_%t_%c%s%p%u’
database skip readonly include current controlfile;
sql ‘alter system archive log current’ ;
backup(archivelog all format ‘$RMAN_DIR/ora_a_%d_%t_%c%s%p%u’ delete input);
release channel c1;
release channel c2;
}

list backup;
exit;
EOF

#mail backup log
mail -s “$ORACLE_SID rman L$RMAN_LEVEL backup log $TODAY” [email protected] <$RMAN_DIR/$LogFile

 

2、在crontab 中设置如下:
0 4 * * 5 sh /home/oracle/backup_scripts/oracle_rman_bak.sh 0 > /data/backup/oracledata/logs/rman.log 2>&1
0 4 * * 2 sh /home/oracle/backup_scripts/oracle_rman_bak.sh 1 > /data/backup/oracledata/logs/rman.log 2>&1

发表评论