rman備份指令碼 傳送郵件通知
指令碼大部分內容載錄網上,本人僅新增郵件傳送內容。郵件使用sendEmail包實現,需要自己單獨安裝。然後再次封裝。
#!/bin/bash
#use Oracle Env.
source ~/.bash_profile
#Def backupdir
dirname=`date "+%Y-%U"`
lastweek=`date -d "-3 week" +%Y-%U`
backupdir=/mnt/usbp/u01/database/rman_bak/$dirname
rmdir=/mnt/usbp/u01/database/rman_bak/$lastweek
#check backdir
if [ ! -d $backupdir ];then
mkdir -p $backupdir
fi
#
#Get Time And Set Backup Level.
#
Dayname=`date +%a`
if [ $Dayname = 'Sun' ]; then
Level=0
elif [ $Dayname = 'Thu' ];then
Level=1
else
Level=2
fi
#Wed means wedsday
#
#Define Backup Type.
#
if [ $Level = 0 ]; then
BACKUP_TYPE="incremental level 0"
elif [ $Level = 1 ]; then
BACKUP_TYPE="incremental level 1"
else
BACKUP_TYPE="incremental level 2"
fi
#
#Log.
#
logdate=`date +"%Y%m%d"`
logdate2=`date +%F`
logfile=$backupdir/racdb_rman_"$logdate".log
echo `date +'%Y%m%d %T'`' start backup-----' >> $logfile
cat >$logfile <<EOF
#
#This is RMAN Backup log.
#
#Today is $logdate2,$Dayname.The RMAN Backup Level is $Level and Backup type is $BACKUP_TYPE.
#
#RMAN Bakcup Process starting.
EOF
#backup body
rman target / log $logfile append <<EOF
run{
allocate channel a1 type disk;
crosscheck backup;
delete noprompt expired backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
backup as compressed backupset $BACKUP_TYPE database format '${backupdir}/incr${Level}_%T_%d_%s_%p.bak' filesperset=8;
sql 'alter system archive log current';
backup as compressed backupset archivelog all format '${backupdir}/arc_%T_%d_%s_%p.bak' delete all input;
backup current controlfile format '${backupdir}/ctl_%T_%d_db_%s_%p.bak';
release channel a1;
}
EOF
echo `date +'%Y%m%d %T'`' end backup-----' >> $logfile
#delete last week backup.
if [ -d $rmdir ];then
rm -rf $rmdir
echo `date +'%Y%m%d %T'`' end rm_his-----' >> $logfile
echo 'hello'
fi
#send mail to smc,if it have some error in backing
if [ -f ${logfile} ];then
sum=`cat ${logfile} | grep -E "RMAN-|ORA-"|wc -l`
if [ ${sum} -lg 0 ];then
sh /home/oracle/shell/mail_pl.sh "***.sohu.com" '備份報警' "`cat ${logfile} | grep -E 'RMAN-|ORA-'`" "${logfile}"
fi
fi
exit 0
-----------------------------------------------------------------------------------------------
mail_pl.sh指令碼內容:
#!/bin/bash
SMTP_server='***.sohu.com'
username='*****'
password='****'
from_email_address='***.sohu.com'
to_email_address="$1"
message_subject_utf8="$2"
message_body_utf8="$3"
attachment="$4"
message_subject_gb2312=`iconv -t UTF-8 -f UTF-8 << EOF
$message_subject_utf8
EOF`
[ $? -eq 0 ] && message_subject="$message_subject_gb2312" || message_subject="$message_subject_utf8"
message_body_gb2312=`iconv -t UTF-8 -f UTF-8 << EOF
$message_body_utf8
EOF`
[ $? -eq 0 ] && message_body="$message_body_gb2312" || message_body="$message_body_utf8"
sendEmail='/home/oracle/shell/sendEmail.pl'
if [ -e ${message_body} ];then
$sendEmail -s "$SMTP_server" -xu "$username" -xp "$password" -f "$from_email_address" -t "$to_email_address" -u "$message_subject" -o message-file="$message_body" -a ${attachment} -o message-content-type=text -o message-charset=gb2312
else
$sendEmail -s "$SMTP_server" -xu "$username" -xp "$password" -f "$from_email_address" -t "$to_email_address" -u "$message_subject" -m "$message_body" -a ${attachment} -o message-content-type=text -o message-charset=gb2312
fi
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28572479/viewspace-2123959/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux配置msmtp+mutt傳送郵件(可放在指令碼中定時傳送郵件)Linux指令碼
- Shell指令碼中傳送html郵件的方法指令碼HTML
- 【主機】傳送郵件指令碼的改進指令碼
- rman 備份指令碼指令碼
- rman備份指令碼指令碼
- gitlab自動定時備份檔案,備份失敗傳送郵件Gitlab
- 郵件傳送庫原始碼原始碼
- 郵件傳送
- 傳送郵件
- rman備份和增量備份指令碼指令碼
- rman 全備份指令碼指令碼
- rman增量備份指令碼指令碼
- windows rman備份指令碼Windows指令碼
- RMAN常用備份指令碼指令碼
- oracle RMAN備份指令碼Oracle指令碼
- 谷歌郵箱,配置傳送郵件密碼谷歌密碼
- laravel 傳送郵件修改密碼Laravel密碼
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- Laravel 傳送郵件Laravel
- PHP傳送郵件PHP
- Django——郵件傳送Django
- java郵件傳送Java
- Laravel傳送郵件Laravel
- gmail傳送郵件AI
- Oracle郵件傳送Oracle
- java傳送郵件Java
- Powershell郵件傳送
- thinkphp 郵件傳送PHP
- centos 傳送郵件CentOS
- phpcms傳送郵件PHP
- 郵件的傳送
- [Oracle] rman備份指令碼(2)Oracle指令碼
- 使用rman備份的指令碼指令碼
- oracle rman備份指令碼收集Oracle指令碼
- Windows下RMAN備份指令碼Windows指令碼
- RMAN全庫備份指令碼指令碼
- RMAN備份Shel指令碼示例指令碼
- Rman備份的shell指令碼指令碼