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