Nagios 被動檢測oracle Rman備份情況

Michael_DD發表於2014-11-10
Nagios 被動檢測oracle Rman備份情況


nagios監控伺服器ip:192.168.9.172

被監控伺服器ip:192.168.9.133
資料庫例項名:orcl

需要開通被監控伺服器到nagios監控伺服器的nsca埠:5667

被監控伺服器:
1. 準備Rman指令碼rman_orcl.rcv
crosscheck archivelog all;
crosscheck backup;
crosscheck copy;
delete noprompt obsolete;
delete noprompt expired archivelog all;
delete noprompt expired backup;
delete noprompt expired copy;
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
backup as compressed backupset database format '/backup/rman/orcl_full_%U'
plus archivelog skip inaccessible format '/backup/rman/orcl_ARC_%U';
delete noprompt archivelog all completed before 'sysdate-1';
backup current controlfile format '/backup/rman/grp1_control_bak_%T';
backup spfile format '/backup/rman/grp1_spfile_bak_%T';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}


2.編輯backup_db的shell指令碼backup_db.sh
SIDNAME=orcl
source /home/oracle/prof_orcl
cd /backup/rman

#find /backup/rmanbak/ -name $SIDNAME"_"* -exec rm -rf {} \;
rm /backup/rmanbak/orcl_*

mv /backup/rman/$SIDNAME"_"* /backup/rmanbak/

logName=$SIDNAME"_rman"_`date +'%Y%m%d%H%M%S'`_full.log

cd /backup/rman
rman target / CMDFILE rman_$SIDNAME.rcv >> $logName
##################################
sh check_backup.sh
##################################


3.檢查備份情況日誌backup_status.log(自動生成)(備份成功)
192.168.9.133    Rman_Backup_GRP1    0    Backup Suess!

4.編輯檢查備份情況指令碼check_backup.sh
IP=192.168.9.133
SID=orcl

status=`sqlplus  -silent "/as sysdba" < set feedback off
set verify off
set heading off
set echo off
set pagesize 0
SELECT  /*+ rule */ DECODE (
             TRUNC (SYSDATE - start_time),
             0, DECODE (
                   status,
                   'COMPLETED', '0',
                   'COMPLETED WITH WARNINGS','1',
                   '2'),
             '2')
          backup_status
  FROM v\\$rman_backup_job_details
 WHERE start_time = (SELECT MAX (start_time) FROM v\\$rman_backup_job_details);
exit;
eof`
output=`sqlplus  -silent "/as sysdba" < set feedback off
set verify off
set heading off
set echo off
set pagesize 0
SELECT /*+ rule */ DECODE (
          TRUNC (SYSDATE - start_time),
          0, DECODE (status,
                     'COMPLETED', 'Backup Suess!',
                     'COMPLETED WITH WARNINGS', 'Backup With Warnings!',
                     'Backup Failed!'),
          'No Backup!')
          backup_status
  FROM v\\$rman_backup_job_details
 WHERE start_time = (SELECT MAX (start_time) FROM v\\$rman_backup_job_details);
exit;
eof`
hostip=$IP
checkname="Rman_Backup_"$SID

#把rman備份資訊寫到目錄中去
echo -e "$hostip\t$checkname\t$status\t$output" > backup_status.log

#透過nsca方式把backup_status.log的內容傳到監控伺服器192.168.9.172
/usr/local/nagios/bin/send_nsca 192.168.9.172 -c /usr/local/nagios/etc/send_nsca.cfg < backup_status.log


5.編輯定期執行指令碼crontab
[oracle@orcl ~]$ crontab -l
0 22 * * * cd /backup/rman ; sh backup.sh

[oracle@orcl ~]$ cd /backup/rman
[oracle@orcl rman]$ ll
total 520688
-rw-r--r-- 1 oracle oinstall       389 Jul 28 09:44 backup.sh
-rw-r--r-- 1 oracle oinstall        50 Nov 10 09:20 backup_status.log
-rw-r--r-- 1 oracle oinstall      1428 Oct 15 16:18 check_backup.sh
-rw-r----- 1 oracle oinstall  61839872 Nov  9 21:00 orcl_ARC_dapn7432_1_1
-rw-r----- 1 oracle oinstall   1165312 Nov  9 21:01 orcl_ARC_dkpn7458_1_1
-rw-r----- 1 oracle oinstall  17596416 Nov  9 21:01 orcl_control_bak_20141109
-rw-r----- 1 oracle oinstall 197828608 Nov  9 21:01 orcl_full_dbpn743i_1_1
-rw-r----- 1 oracle oinstall 133578752 Nov  9 21:01 orcl_full_dcpn743i_1_1
-rw-r----- 1 oracle oinstall 113934336 Nov  9 21:01 orcl_full_ddpn743i_1_1
-rw-r----- 1 oracle oinstall   1196032 Nov  9 21:00 orcl_full_depn743i_1_1
-rw-r----- 1 oracle oinstall   1368064 Nov  9 21:00 orcl_full_dfpn743i_1_1
-rw-r----- 1 oracle oinstall   1515520 Nov  9 21:00 orcl_full_dgpn743j_1_1
-rw-r----- 1 oracle oinstall   1073152 Nov  9 21:00 orcl_full_dhpn743j_1_1
-rw-r----- 1 oracle oinstall   1277952 Nov  9 21:00 orcl_full_dipn743j_1_1
-rw-r----- 1 oracle oinstall     98304 Nov  9 21:00 orcl_full_djpn743q_1_1
-rw-r--r-- 1 oracle oinstall     13624 Nov  9 21:01 orcl_rman_20141109210001_full.log
-rw-r----- 1 oracle oinstall     98304 Nov  9 21:01 orcl_spfile_bak_20141109
-rw-r--r-- 1 oracle oinstall       954 Jul 22 09:47 rman_orcl.rcv
[oracle@amcxypjdbvm1 rman]$


nagios監控伺服器:

1. 會透過被動式check_dummy來檢測
[root@sznagios libexec]# ./check_dummy 0
OK
[root@sznagios libexec]# ./check_dummy 1
WARNING
[root@sznagios libexec]# ./check_dummy 2
CRITICAL
[root@sznagios libexec]# ./check_dummy 3
UNKNOWN

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1327157/,如需轉載,請註明出處,否則將追究法律責任。

相關文章