a47b3a19e5ed74f636ba7f85eb7e484e0cfba68f
[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 inetd.conf \
99                 xinetd.conf; do
100         if [ -f /etc/$i ] ; then
101         echo "copying /etc/$i"
102         cp /etc/$i ./etc
103         fi
104 done
105
106 if [ -f /etc/X11/XF86Config ] ; then
107         mkdir -p ./etc/X11
108         echo "copying /etc/X11/XF86Config*"
109         cp /etc/X11/XF86Config* ./etc/X11
110 fi
111
112
113 # specific config stuff
114
115 # gate specific config stuff!
116 if [ "$host" = "gate" ] ; then
117         
118         # mail config stuff
119         if [ -d /etc/mail ] ; then
120                 echo "copying /etc/mail directory"
121                 cp -r /etc/mail ./etc
122         fi
123
124         # irc stuff 
125         mkdir -p ./irc/networks
126         [ -f /opt/unreal/etc/unrealircd.conf ] && \
127                 cp /opt/unreal/etc/unrealircd.conf ./irc/unrealircd_new.conf
128         for i in ircd.conf networks/hackdaworld.network \
129                         networks/unrealircd.conf; do
130                 [ -f /home/irc/Unreal3.1.1/$i ] && \
131                         cp /home/irc/Unreal3.1.1/$i ./irc/$i
132         done
133         [ -f /home/irc/services_new/services.conf ] && \
134                 cp /home/irc/services_new/services.conf ./irc
135         for i in rebecka defcon_one elin; do
136                 [ -f /home/irc/eggdrop/$i ] && cp /home/irc/eggdrop/$i* ./irc
137         done
138
139 fi
140
141 # data stuff
142 echo "data stuff:"
143
144 # data backup (specific)
145 cd ${backup_dir}/${host}-backup-${backup_date}
146
147 # gate specific data 
148 if [ "$host" = "gate" ] ; then
149         
150         # minimalist and mail stuff
151         mkdir -p minimalist_spool mail_admin mail_hackbard mail_mlist
152         echo "copying minimalist and mail stuff"
153         cp -r /opt/minimalist/spool/* ./minimalist_spool
154         cp -r /home/hackbard/* ./mail_hackbard
155         cp -r /home/admin/* ./mail_admin
156         cp /var/mail/mlist ./mail_mlist
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         tar -cf ./mlist-archive.tar /home/mlist/public_html
165
166 fi
167
168 # hackstation specific data
169 if [ "$host" = "hackstation" -o "$host" = "mobile" -o "$host" = "hdw" -o "$host" = "sparc" ] ; then
170
171         # home of hackbard
172         mkdir -p ./home/hackbard
173         echo "copying home"
174         for i in projects software store; do
175                 [ -d /home/hackbard/$i ] && \
176                         cp -r /home/hackbard/$i ./home/hackbard
177         done
178         for i in xinitrc_evil xinitrc_wm .xinitrc GNUstep .Xauthority \
179                         .Xdefaults .signature; do
180                 [ -f /home/hackbard/$i ] && \
181                         cp -r /home/hackbard/$i ./home/hackbard
182         done
183         cp -r /home/hackbard/.ssh ./home/hackbard
184
185 fi
186
187
188 # data stuff (none specific)
189
190 # extensions, stored on root 
191 if [ -d /root/${host}_exts ] ; then 
192         echo "copying ${host}_exts"
193         cp -r /root/${host}_exts ./
194 fi
195
196 # dying software
197 if [ -d /root/${host}_bunker ] ; then
198         echo "copying ${host}_bunker"
199         cp -r /root/${host}_bunker ./
200 fi
201
202 # backing up myself
203 cp -r $HOME/scripts ./
204
205
206 # finished copying stuff, entering last backup procedure now :)))
207
208 cd $backup_dir
209
210 if [ "$method" = "tar" ] ; then
211         echo "creating tar"
212         tar cf ./${host}-backup-${backup_date}.tar \
213                                 ./${host}-backup-${backup_date}
214         rm -r ./${host}-backup-${backup_date}
215         bzip2 ./${host}-backup-${backup_date}.tar
216 fi
217
218
219 # end! umounting nfs shared backup directory
220 if [ "$host" != "hackstation" ] ; then
221         echo "umounting nfs backup - dir"
222         #cd $HOME && umount /mnt/nfs
223 fi
224
225 echo "done ..."