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