different backups for primary and secondary
[scripts/scripts.git] / fai_backup.sh
1 #!/bin/bash
2
3 # subroutines:
4 configcp()      {
5         file=$1
6         mkdir -p $configdir/$file
7         rsync -av $file $configdir/$file/$myip
8 }
9 backupcp()      {
10         cat=$1
11         object=$2
12         if [ "$cat" = "dir" ] ; then
13                 rsync -av $object/ $backupdir/$object
14         elif [ "$cat" = "file" ] ; then
15                 dir=`dirname $object`
16                 rsync -av $object $backupdir/$dirname/
17         else
18                 echo "warning: dont know how to handle $cat"
19         fi
20 }
21
22 # variables
23 cserver="hermes"                # configs which may be restored by fai
24 rcdir="/mnt/extra/hdw-linux/fai/files"
25 configdir="/mnt/tmp1"
26
27 bserver="hermes"                # data not usable for fai
28 rbdir="/mnt/extra/backup"
29 backupdir="/mnt/tmp2"
30
31 # initializing custom variables
32 host=`hostname`
33 if [ -z $1 ] ; then
34         myip="`host $host | awk '{ print $4 }'`"
35 else
36         myip=$1
37 fi
38 res=$?
39 if [ "$res" != "0" ] ; then
40         echo "unable to determine the hosts ip address"
41         exit 1
42 fi
43 answer=n
44 echo "warning: the correct ip address is essential"
45 echo "please make sure it is the correct one"
46 echo "is the ip address correct? -> $myip [y/n]"
47 read answer
48 [ "$answer" != "y" ] && exit 1
49
50 # mount backup and config space
51 if [ -d $configdir -a -d $backupdir ] ; then
52         mount $cserver:$rcdir $configdir
53         res=$?
54         if [ "$res" != "0" ] ; then
55                 echo "unable to mount configdir"
56                 exit 1
57         fi
58         mount $bserver:$rbdir $backupdir
59         if [ "$res" != "0" ] ; then
60                 echo "unable to mount backupdir"
61                 exit 1
62         fi
63         res=$?
64         [ "$res" = "0" ] && b_mounted=1
65 else
66         echo "$configdir or $backupdir (or both) doesn't exist"
67         exit 1
68 fi
69
70 # config:
71 for configfile in /usr/src/linux/.config; do
72         [ -f $configfile ] && configcp $configfile
73 done
74 for onefile in profile network kernel wireless; do
75         configfile="/etc/conf/$onefile"
76         [ -f $configfile ] && configcp $configfile
77 done
78 for configfile in /etc/cron.d/* /var/spool/cron/crontabs/*; do
79         [ -f $configfile ] && configcp $configfile
80 done
81 for configfile in /etc/udev/rules.d/udev.rules /etc/X11/xorg.conf* \
82         /etc/opt/apache2/{httpd,ssl}.conf /etc/cups/cupsd.conf \
83         /etc/ppp/{pppoe.conf,ip-up,ip-down,pap-secrets} ; do
84         [ -f $configfile ] && configcp $configfile
85 done
86 for i in dhcpd.conf fstab hosts host.conf hosts.allow hosts.deny lilo.conf \
87                 profile sendmail.cf resolv.conf exports fb.modes inetd.conf \
88                 xinetd.conf mp3user mp3db.conf modules.conf named.conf \
89                 modprobe.devfs modprobe.conf crontab ethers HOSTNAME \
90                 lircd.conf; do
91         [ -f /etc/$i ] && configcp /etc/$i
92 done
93 for configfile in /var/named/*; do
94         [ -f $configfile ] && configcp $configfile
95 done
96 for configfile in /home/*/{xinitrc,.Xdefaults,.XHkeys,.directfbrc,.bashrc} \
97         /home/*/{.signature,sp12/*,.licq,.irssi,.ssh/*} ; do
98         [ -f $configfile ] && configcp $configfile
99 done
100 for configfile in `find /tftpboot -type f`; do
101         configcp $configfile
102 done
103
104 umount $configdir
105 umount $backupdir
106
107 echo "done ..."