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