source: trunk/third/moira/backup/nightly.sh @ 23095

Revision 23095, 2.1 KB checked in by ghudson, 16 years ago (diff)
Import the moira package from SIPB Debathena.
Line 
1#!/bin/sh
2#
3#       Nightly script for backing up Moira.
4#
5#
6BKUPDIRDIR=/backup
7PATH=/usr/athena/bin:/bin:/usr/bin:/usr/ucb; export PATH
8ORACLE_HOME=/usr/oracle; export ORACLE_HOME
9ORACLE_SID=moira; export ORACLE_SID
10chdir ${BKUPDIRDIR}
11
12if [ -d in_progress ]
13then
14        echo "Two backups running?"
15        exit 1
16fi
17
18trap "rm -rf ${BKUPDIRDIR}/in_progress" 0 1 15
19
20if mkdir in_progress
21then
22        echo "Backup in progress."
23else
24        echo "Cannot create backup directory"
25        exit 1
26fi
27chmod 750 in_progress
28if /moira/bin/mrbackup ${BKUPDIRDIR}/in_progress/
29then
30        failed=`ls -s ${BKUPDIRDIR}/in_progress/ \
31                | awk ' !/total/ {
32                          if ( FILENAME ~ /conf$/ ) {
33                            minsize[$2]=$1;
34                          } else {
35                            size[$2]=$1
36                          }
37                        }
38                        END {
39                          for ( i in minsize ) {
40                            if ( minsize[i] > size[i] ) {
41                              j+=1
42                            }
43                          }
44                          print j
45                        }' ${BKUPDIRDIR}/conf -`
46        if [ "$failed" -gt 0 ]
47        then
48                echo "Backup was incomplete!  $failed table(s) too small!"
49                echo "Current file sizes:"
50                ls -s in_progress/
51                exit 1
52        fi
53        echo "Backup successful"
54else
55        echo "Backup failed!"
56        exit 1
57fi
58
59/moira/bin/report.pl ${BKUPDIRDIR}/in_progress > ${BKUPDIRDIR}/in_progress/report
60
61if [ -d stale ]
62then
63        /usr/ucb/echo -n "Stale backup "
64        rm -r stale
65        echo "removed"
66fi
67/usr/ucb/echo -n "Shifting backups "
68
69mv backup_3 stale
70/usr/ucb/echo -n "3 "
71mv backup_2 backup_3
72/usr/ucb/echo -n "2 "
73mv backup_1 backup_2
74/usr/ucb/echo -n "1 "
75mv in_progress backup_1
76echo
77/bin/df -k /moira/moira.log | /usr/ucb/tail -1
78echo
79echo "deleting last backup"
80rm -rf stale
81echo
82echo "Shipping over the net"
83rcp -rpx ${BKUPDIRDIR}/* oregano:/backup
84rcp -rpx ${BKUPDIRDIR}/* nessus:/backup/moira
85
86if [ "`/usr/bin/find /moira/critical.log -mtime -1 -print`" = "/moira/critical.log" ]; then
87        (/bin/echo "To: dbadmin";\
88         /bin/echo "Subject: Moira update status";\
89         /usr/ucb/tail /moira/critical.log) | /bin/mail dbadmin
90fi
91
92plfile=/afs/athena.mit.edu/system/info/public-mailing-lists
93awk -F\| '$3==1 && $4==1 && $5==0 && $6==1 {printf "%-20s %s\n", $1, $9}' \
94        ${BKUPDIRDIR}/backup_1/list \
95        | sort > $plfile.new && mv -f $plfile.new $plfile
96
97exit 0
Note: See TracBrowser for help on using the repository browser.