一些脚本

----检查磁盘空间------------------

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_timespool 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/25706402/viewspace-705444/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25706402/viewspace-705444/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值