added dns config stuff for backup
[scripts/scripts.git] / backup.sh
1 #!/bin/bash
2
3
4 # initializing some variables
5 backup_date=`date | awk '{ print $3"."$2"."$6 }'`
6 host=`hostname`
7
8 [ ! -d /mnt/nfs ] && mkdir -p /mnt/nfs
9
10 # set the backup directory
11 if [ "$host" = "gate" ] ; then
12         mount -tnfs hackstation:/mnt/lfs/backup /mnt/nfs
13         backup_dir="/mnt/nfs"
14 elif [ "$host" = "sparc" ] ; then
15         mount -tnfs hackstation:/mnt/lfs/backup /mnt/nfs
16         backup_dir="/mnt/nfs"
17 elif [ "$host" = "mobile" ] ; then
18         mount -tnfs hackstation:/mnt/lfs/backup /mnt/nfs
19         backup_dir="/mnt/nfs"
20 elif [ "$host" = "right-hand" ] ; then
21         mount -tnfs hackstation:/mnt/lfs/backup /mnt/nfs
22         backup_dir="/mnt/nfs"
23 elif [ "$host" = "hackstation" ] ; then 
24         backup_dir="/mnt/lfs/backup"
25 elif [ "$host" = "hdw" ] ; then
26         mount -tnfs hackstation:/mnt/lfs/backup /mnt/nfs
27         backup_dir="/mnt/nfs"
28 elif [ "$host" = "compaq" ] ; then
29         mount -tnfs hackstation:/mnt/lfs/backup /mnt/nfs
30         backup_dir="/mnt/nfs"
31 else
32         echo "pls adept the script for $host ..."
33         exit 1
34 fi
35
36 if [ ! -z "$2" ] ; then
37 if [ "$2" = "-backup_dir" -a -d $3 ] ; then
38         echo "using $3 as a backup directory ..."
39         backup_dir=$3
40 fi
41 fi
42
43 # set kernel version(s) to store their .config
44 if [ -d /usr/src/linux ] ; then
45         kernel_num=`ls /usr/src/ | grep '^linux-' | sed 's/linux-//g'`
46 fi
47
48
49 # which method to use?
50 if [ "$1" = "tar" ] ; then
51         method="tar"
52 elif [ "$1" = "dir" ] ; then 
53         method="dir"
54 elif [ -z "$1" ] ; then
55         method="tar"
56 else
57         echo "aborting!"
58         echo "usage: $0 [tar|dir] (-backup_dir /foo/bar)"
59         echo 
60         echo "tar: creates an archive called backup_${backup_date}.tar.bz2"
61         echo "dir: creates just the directory backup_${backup_date}"
62         exit 0
63 fi
64
65
66 # creating backup
67 if [ -d ${backup_dir}/${host}-backup-${backup_date} ] ; then
68         echo "u already did a backup today! remove it manually first!"
69         [ ! "$host" = "hackstation" ] && umount /mnt/nfs
70         exit 0
71 fi
72
73 mkdir $backup_dir/${host}-backup-${backup_date} && cd ${backup_dir}/${host}-backup-${backup_date}
74
75
76 #config stuff
77 echo "config stuff:"
78 mkdir ./${host}-conf && cd ./${host}-conf 
79
80 for i in $kernel_num; do
81         if [ -f /usr/src/linux-${i}/.config ] ; then
82                 echo "copying /usr/src/linux/.config"
83                 cp /usr/src/linux-${i}/.config ./$host-kernel-${i}-config
84         fi
85 done
86
87 mkdir ./etc
88 for i in init.d conf opt ppp cups; do
89         if [ -d /etc/$i ] ; then
90                 echo "copying /etc/$i"
91                 cp -r /etc/$i ./etc
92         fi
93 done
94
95 for i in dhcpd.conf fstab hosts host.conf hosts.allow hosts.deny lilo.conf \
96                 profile sendmail.cf resolv.conf exports fb.modes inetd.conf \
97                 xinetd.conf mp3user mp3db.conf modules.conf named.conf; do
98         if [ -f /etc/$i ] ; then
99         echo "copying /etc/$i"
100         cp /etc/$i ./etc
101         fi
102 done
103
104 if [ -f /etc/X11/XF86Config ] ; then
105         mkdir -p ./etc/X11
106         echo "copying /etc/X11/XF86Config*"
107         cp /etc/X11/XF86Config* ./etc/X11
108 fi
109
110
111 # specific config stuff
112
113 # gate specific config stuff!
114 if [ "$host" = "gate" ] ; then
115         
116         # mail config stuff
117         if [ -d /etc/mail ] ; then
118                 echo "copying /etc/mail directory"
119                 cp -r /etc/mail ./etc
120         fi
121
122         # irc stuff 
123         mkdir -p ./ircd
124         [ -f /etc/opt/unrealircd/unrealircd.conf ] && \
125                 cp /etc/opt/unrealircd/unrealircd.conf ./ircd
126 fi
127
128 # data stuff
129 echo "data stuff:"
130
131 # data backup (specific)
132 cd ${backup_dir}/${host}-backup-${backup_date}
133
134 # gate specific data 
135 if [ "$host" = "gate" ] ; then
136         
137         # mail stuff
138         for i in `ls -A /var/mail`; do
139                 mkdir -p mail_$i
140                 echo "copying mail stuff"
141                 cp /var/mail/$i ./mail_$i
142         done
143 fi
144
145 # right-hand data
146 if [ "$host" = "right-hand" ] ; then
147         mkdir ./chroot
148         for i in www cvs hdw; do
149                 if [ -d /chroot/$i ] ; then
150                         echo "copying /chroot/$i"
151                         tar -cf ./chroot/$i.tar /chroot/$i
152                 fi
153         done
154         
155         mkdir ./named
156         if [ -d /var/named ] ; then
157                 echo "copying dns data"
158                 cp -r /var/named/* ./named
159         fi
160 fi
161
162 # hackstation / mobile / hdw / sparc specific data
163 if [ "$host" = "hackstation" -o "$host" = "mobile" -o "$host" = "hdw" -o "$host" = "sparc" -o "$host" = "compaq" ] ; then
164
165         # home of hackbard
166         mkdir -p ./home/hackbard
167         echo "copying home"
168         for i in software store; do
169                 [ -d /home/hackbard/$i ] && \
170                         cp -r /home/hackbard/$i ./home/hackbard
171         done
172         if [ "$host" = "hackstation" ]; then
173                 [ -d /home/hackbard/projects ] && \
174                         cp -r /home/hackbard/projects ./home/hackbard
175         fi
176         for i in xinitrc_evil xinitrc_wm .xinitrc GNUstep .Xauthority \
177                         .Xdefaults .signature .directfbrc .bashrc; do
178                 [ -f /home/hackbard/$i ] && \
179                         cp -r /home/hackbard/$i ./home/hackbard
180         done
181         [ -d /home/hackbard/.ssh ] && cp -r /home/hackbard/.ssh ./home/hackbard
182         
183         # tftpboot
184         if [ -d /tftpboot ] ; then
185                 mkdir -p ./tftpboot
186                 echo "copyinf tftpboot stuff"
187                 cp -r /tftpboot/* ./tftpboot
188         fi
189
190         # hunz config
191         for i in prism lucent; do
192                 if [ -f /root/hunz_${i}.sh ]; then
193                         mkdir -p ./root
194                         cp /root/hunz_${i}.sh ./root
195                 fi
196         done
197
198 fi
199
200
201 # data stuff (none specific)
202
203 # backing up myself
204 cp -r $HOME/scripts ./
205
206
207 # finished copying stuff, entering last backup procedure now :)))
208
209 cd $backup_dir
210
211 if [ "$method" = "tar" ] ; then
212         echo "creating tar"
213         tar cf ./${host}-backup-${backup_date}.tar \
214                                 ./${host}-backup-${backup_date}
215         rm -r ./${host}-backup-${backup_date}
216         bzip2 ./${host}-backup-${backup_date}.tar
217 fi
218
219
220 # end! umounting nfs shared backup directory
221 if [ "$host" != "hackstation" ] ; then
222         echo "umounting nfs backup - dir"
223         cd $HOME && umount /mnt/nfs
224 fi
225
226 echo "done ..."