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