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