----检查磁盘空间------------------
bin/sh
d1=`df -h | grep /home | awk '{print $5}' | awk -F% '{print $1}'`
if [ $d1 -ge 80 ]
then
echo "`date +%F" "%H:%M:%S` The disk is not enough ,the message from ip " | mail -s "primary_ipdisk alert
" jie.du@mail
fi
------------检查oracle standby服务器的状态---------------------------
#!/bin/bash
primary_log=`ls -t /home/oracle/archive_log | head -n 1 | awk -F_ '{print $2}'`
standby_log=`ssh -p65508 oracle@192.168.10.13 "ls -t /home/oracle/archive_log | head -n 1 " |awk -F_ '{print $2}'`
apply_log=`ssh -p65508 oracle@192.168.10.13 'grep "Media Recovery Log" /home/oracle/admin/sfgame/bdump/alert_sfgame.log| tail -n 1'
| awk -F/ '{print $5}' | awk -F_ '{print $2}'`
d1=`expr $primary_log - $standby_log `
d2=`expr $standby_log - $apply_log `
echo $primary_log
echo $standby_log
echo $apply_log
if [ $d1 -ge 2 ]
then
echo ------ `date +%F" "%H:%M:%S` >>check_stantdby_status.log
echo "The archive_log was not sended" >> check_stantdby_status.log
echo "The archive_log was not sended " | mail -s "standby_ip" jie.du@email
if [ $d2 -ge 2 ]
then
echo ------ `date +%F" "%H:%M:%S` >>check_stantdby_status.log
echo "The archived_log was not applied" >>check_stantdby_status.log
echo "The archive_log was not applied " | mail -s "standby_ipalert" jie.du@email
--------数据库备份脚本---------
rman target / << EOF
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup
filesperset 5
full
format "/home/oracle/dbbackup/sfgame_full_p%p_s%s_t%t_%T.bak"
(database include current controlfile);
}
exit
EOF
if [ $? -ge 0 ]
then
echo `date +"%F %H:%M:%S"` backup failed >> dbbackup.log
fi
------日志备份脚本-------------
primary_log=`ls -t /home/oracle/archive_log | head -n 1 | awk -F_ '{print $2}'`
standby_log=`ssh -p65508 oracle@192.168.10.13 "ls -t /home/oracle/archive_log | head -n 1 " |awk -F_ '{print $2}'`
d1=`expr $primary_log - $standby_log `
time=`date +%H`
if [ $d1 -le 2 ]
then
#-------delete data of 5 days ago if standby log can normal archived
if [ $time = 00 ]
then
cd /home/oracle/oracle_maintenance
$ORACLE_HOME/bin/sqlplus /nolog< conn / as sysdba
set feed off
set heading off
set head off
set echo off
spool removeArch1.sh
select 'rm '||name From v$archived_log where dest_id=1 and deleted='NO' and completion_time>trunc(sysdate-3) and comple
tion_time spool off
EOF
cat removeArch1.sh | sed '1d' | sed '$d' > /home/oracle/oracle_maintenance/removeArch2.sh
sh /home/oracle/oracle_maintenance/removeArch2.sh
#-------delete data which deleted use system cmd rm in rman
rman target / << EOF
run {
crosscheck archivelog all;
delete noprompt expired archivelog all;
}
exit
EOF
fi
fi
rman target / << EOF
run {
allocate channel c1 type disk;
backup
format "/home/oracle/archive_log_backup/arch_p%p_s%s_t%t_%T.arc"
filesperset 20
archivelog all;
}
exit
EOF
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7668955/viewspace-987055/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7668955/viewspace-987055/