[23095] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
| 3 | # Nightly script for backing up Moira. |
---|
| 4 | # |
---|
| 5 | # |
---|
| 6 | BKUPDIRDIR=/backup |
---|
| 7 | PATH=/usr/athena/bin:/bin:/usr/bin:/usr/ucb; export PATH |
---|
| 8 | ORACLE_HOME=/usr/oracle; export ORACLE_HOME |
---|
| 9 | ORACLE_SID=moira; export ORACLE_SID |
---|
| 10 | chdir ${BKUPDIRDIR} |
---|
| 11 | |
---|
| 12 | if [ -d in_progress ] |
---|
| 13 | then |
---|
| 14 | echo "Two backups running?" |
---|
| 15 | exit 1 |
---|
| 16 | fi |
---|
| 17 | |
---|
| 18 | trap "rm -rf ${BKUPDIRDIR}/in_progress" 0 1 15 |
---|
| 19 | |
---|
| 20 | if mkdir in_progress |
---|
| 21 | then |
---|
| 22 | echo "Backup in progress." |
---|
| 23 | else |
---|
| 24 | echo "Cannot create backup directory" |
---|
| 25 | exit 1 |
---|
| 26 | fi |
---|
| 27 | chmod 750 in_progress |
---|
| 28 | if /moira/bin/mrbackup ${BKUPDIRDIR}/in_progress/ |
---|
| 29 | then |
---|
| 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" |
---|
| 54 | else |
---|
| 55 | echo "Backup failed!" |
---|
| 56 | exit 1 |
---|
| 57 | fi |
---|
| 58 | |
---|
| 59 | /moira/bin/report.pl ${BKUPDIRDIR}/in_progress > ${BKUPDIRDIR}/in_progress/report |
---|
| 60 | |
---|
| 61 | if [ -d stale ] |
---|
| 62 | then |
---|
| 63 | /usr/ucb/echo -n "Stale backup " |
---|
| 64 | rm -r stale |
---|
| 65 | echo "removed" |
---|
| 66 | fi |
---|
| 67 | /usr/ucb/echo -n "Shifting backups " |
---|
| 68 | |
---|
| 69 | mv backup_3 stale |
---|
| 70 | /usr/ucb/echo -n "3 " |
---|
| 71 | mv backup_2 backup_3 |
---|
| 72 | /usr/ucb/echo -n "2 " |
---|
| 73 | mv backup_1 backup_2 |
---|
| 74 | /usr/ucb/echo -n "1 " |
---|
| 75 | mv in_progress backup_1 |
---|
| 76 | echo |
---|
| 77 | /bin/df -k /moira/moira.log | /usr/ucb/tail -1 |
---|
| 78 | echo |
---|
| 79 | echo "deleting last backup" |
---|
| 80 | rm -rf stale |
---|
| 81 | echo |
---|
| 82 | echo "Shipping over the net" |
---|
| 83 | rcp -rpx ${BKUPDIRDIR}/* oregano:/backup |
---|
| 84 | rcp -rpx ${BKUPDIRDIR}/* nessus:/backup/moira |
---|
| 85 | |
---|
| 86 | if [ "`/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 |
---|
| 90 | fi |
---|
| 91 | |
---|
| 92 | plfile=/afs/athena.mit.edu/system/info/public-mailing-lists |
---|
| 93 | awk -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 | |
---|
| 97 | exit 0 |
---|