change to kernel config backup
[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 myip="`host $host | awk '{ print $4 }'`"
34 res=$?
35 if [ "$res" != "0" ] ; then
36         echo "unable to determine the hosts ip address"
37         exit 1
38 fi
39 answer=n
40 echo "warning: the correct ip address is essential"
41 echo "please make sure it is the correct one"
42 echo "is the ip address correct? -> $myip [y/n]"
43 read answer
44 [ "$answer" != "y" ] && exit 1
45
46 # mount backup and config space
47 if [ -d $configdir -a -d $backupdir ] ; then
48         mount $cserver:$rcdir $configdir
49         res=$?
50         if [ "$res" != "0" ] ; then
51                 echo "unable to mount configdir"
52                 exit 1
53         fi
54         mount $bserver:$rbdir $backupdir
55         if [ "$res" != "0" ] ; then
56                 echo "unable to mount backupdir"
57                 exit 1
58         fi
59         res=$?
60         [ "$res" = "0" ] && b_mounted=1
61 else
62         echo "$configdir or $backupdir (or both) doesn't exist"
63         exit 1
64 fi
65
66 # config:
67 for configfile in /usr/src/linux/.config; do
68         [ -f $configfile ] && configcp $configfile
69 done
70 for onefile in profile network kernel wireless; do
71         configfile="/etc/conf/$onefile"
72         [ -f $configfile ] && configcp $configfile
73 done
74 for configfile in /etc/cron.d/* /var/spool/cron/crontabs/*; do
75         [ -f $configfile ] && configcp $configfile
76 done
77 for configfile in /etc/udev/rules.d/udev.rules /etc/X11/xorg.conf* \
78         /etc/opt/apache2/{httpd,ssl}.conf /etc/cups/cupsd.conf \
79         /etc/ppp/{pppoe.conf,ip-up,ip-down,pap-secrets} ; do
80         [ -f $configfile ] && configcp $configfile
81 done
82 for i in dhcpd.conf fstab hosts host.conf hosts.allow hosts.deny lilo.conf \
83                 profile sendmail.cf resolv.conf exports fb.modes inetd.conf \
84                 xinetd.conf mp3user mp3db.conf modules.conf named.conf \
85                 modprobe.devfs modprobe.conf crontab ethers HOSTNAME; do
86         [ -f /etc/$i ] && configcp /etc/$i
87 done
88 for configfile in /var/named/*; do
89         [ -f $configfile ] && configcp $configfile
90 done
91 for configfile in /home/*/{xinitrc,.Xdefaults,.XHkeys,.directfbrc,.bashrc} \
92         /home/*/{.signature,sp12/*,.licq,.irssi,.ssh/*} ; do
93         [ -f $configfile ] && configcp $configfile
94 done
95 for configfile in `find /tftpboot -type f`; do
96         configcp $configfile
97 done
98
99 umount $configdir
100 umount $backupdir
101
102 echo "done ..."