got things a bit closer to right, but there is still a nasty problem on
[feisty_meow.git] / scripts / database / serene_backer_upper.sh
1 #!/bin/bash
2
3 function check_if_failed()
4 {
5   if [ $? -ne 0 ]; then
6     echo "Step FAILed: $*"
7     return 1
8   fi
9 }
10
11 function exit_if_failed()
12 {
13   check_if_failed
14   if [ $? -ne 0 ]; then
15     exit 1
16   fi
17 }
18
19 function synch_to_backup()
20 {
21   local source="$1"; shift
22   local dest="$1"; shift
23   if [ -z "$source" -o -z "$dest" ]; then
24     echo synch_to_backup function requires a source and a target folder to synch.
25     exit 1
26   fi
27   echo "Synchronizing $source into $dest."
28 #hmmm: temporary measure until top-level dir bug fixed in synch_files app.
29   if [ ! -d "$dest" ]; then
30     mkdir -p "$dest"
31     if [ $? -ne 0 ]; then
32       echo "FAILed to make target directory: $dest"
33       return 1
34     fi
35   fi
36   synch_files "$source" "$dest"
37   check_if_failed "synching $source to $dest"
38 }
39
40 # just undo it first, to try to be sure we know we are mounted properly later.
41 umount /z/backup &>/dev/null
42
43 # now saddle up the backup.
44 mount /z/backup/
45 exit_if_failed "mounting backup folder"
46
47 # we should always be synching to an existing set in there.  make sure they exist.
48 # for the first ever backup, this is not a good check...
49 #test -d /z/backup/etc -a -d /z/backup/home
50 #exit_if_failed "testing presence of prior backup"
51
52 ##############
53
54 synch_to_backup /etc /z/backup/etc/
55
56 ##############
57
58 for subdir in albums deepcore drupal fred git sharedspam sim svn trac ; do 
59   synch_to_backup /home/$subdir /z/backup/home/$subdir
60 done
61
62 ##############
63
64 synch_to_backup /var/lib/mailman /z/backup/var/lib/mailman
65
66 ##############
67
68 umount /z/backup/
69 exit_if_failed "unmounting backup folder"
70
71