]> andersk Git - moira.git/blob - backup/nightly.sh
Now rcp'ing with encryption, and actually checking that backup succeeded.
[moira.git] / backup / nightly.sh
1 #!/bin/sh -x
2 #
3 #       Nightly script for backing up Moira.
4 #
5 #
6 BKUPDIRDIR=/u1/backups
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         ftotal=`ls ${BKUPDIRDIR}/in_progress/ | awk '{n++} END {print n}'`
32         fzero=`ls -s ${BKUPDIRDIR}/in_progress/|awk '$1==0{z++} END{print z}'`
33         echo "Dumped $ftotal files, of which $fzero are zero length"
34         if [ "$fzero" -gt 2 ]
35         then
36                 echo "Backup was incomplete!"
37                 exit 1
38         fi
39         echo "Backup successful"
40 else
41         echo "Backup failed!"
42         exit 1
43 fi
44
45 /moira/bin/report.sh ${BKUPDIRDIR}/in_progress > ${BKUPDIRDIR}/in_progress/report
46
47 if [ -d stale ]
48 then
49         echo -n "Stale backup "
50         rm -r stale
51         echo "removed"
52 fi
53 echo -n "Shifting backups "
54
55 mv backup_3 stale
56 echo -n "3"
57 mv backup_2 backup_3
58 echo -n "2"
59 mv backup_1 backup_2
60 echo -n "1"
61 mv in_progress backup_1
62 echo
63 /bin/df /moira/moira.log | /usr/ucb/tail -1
64 echo 
65 echo -n "deleting last backup"
66 rm -rf stale
67 echo "Shipping over the net:"
68 rcp -rpx ${BKUPDIRDIR}/* oregano:/u1/moira
69 rcp -rpx ${BKUPDIRDIR}/* nessus:/backup/moira
70
71 if [ "`/usr/bin/find /moira/critical.log -mtime -1 -print`" = "/moira/critical.log" ]; then
72         (/bin/echo "To: dbadmin";\
73          /bin/echo "Subject: Moira update status";\
74          /usr/ucb/tail /moira/critical.log) | /bin/mail dbadmin
75 fi
76
77 exit 0
This page took 0.057031 seconds and 5 git commands to generate.