File: bootcdbackup

package info (click to toggle)
bootcd 3.10%2Bnmu1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 508 kB
  • ctags: 128
  • sloc: sh: 3,935; makefile: 117
file content (295 lines) | stat: -rwxr-xr-x 8,491 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/sh
#
# bootcdbackup
#
#  bootcdbackup /dev/VolGroup00/LogVol00 otherdist /mnt/tmp/space [-nomount] [-2diskconf <file>] <$*>
#  1. mkdir /tmp/backup
#  2. [ -2diskconf ] || bootcdmk2diskconf -b -f /dev/VolGroup00/LogVol00 >/tmp/backup/bootcd2disk.conf
#  3. [ -nomount ] || bootcd2disk -onlymount -c /tmp/backup 
#  4. bootcd2disk -mkchroot /mnt/tmp/space <$*>
#  5. tar /mnt/tmp/space/chroot
#     chroot /mnt/tmp/space/chroot bootcdwrite
#     cp cdimage.iso 
#  6. [ -nomount ] || bootcd2disk -onlyunmount -c /tmp/backup 

CONFVARS="ERRLOG"
# directory created in builddir
BOOTCDDIR="bootcd"

TODOY="-y"
TODO=""
ENV_IMAGEURL=""
VERBOSE=""
SCRIPT=""
CONFDIR="/etc/bootcd"
NOMOUNT=""
DISKCONF2=""
BACKUPDIR=""
BACKUPNAME=""
COPYDEST="/mnt"

# temporary directory
TMPDIR="/tmp/bootcdbackup"

# must be empty for run_cpio
IMGDIR=""

##################### nothing to configure behind this line ##################

cleanup()
{
  local TODO=""
  trap "" 2 EXIT
  TODO="$TODO \"rm -rf $TMPDIR\""
  [ "$CLEANCHROOT" ] && TODO="$TODO \"$CLEANCHROOT\""
  [ "$CLEANUMNT" ] && TODO="$TODO \"$CLEANUMNT\""
  [ "$TODO" ] && eval "interactive $TODOY $TODO"
}

unset $CONFVARS

[ -f /etc/bootcd/bootcdbackup.conf ] && . /etc/bootcd/bootcdbackup.conf

# read bootcd-run.lib
if [ -f ./bootcd-run.lib ]; then
  echo "Using local ./bootcd-run.lib" >&2
  . ./bootcd-run.lib
elif [ -f /usr/share/bootcd/bootcd-run.lib ]; then
  . /usr/share/bootcd/bootcd-run.lib 
else
  echo "Error: Mandatory lib bootcd-run.lib not found! ABORT!"
  exit 1
fi

# read bootcdbackup.lib
if [ -f ./bootcdbackup.lib ]; then
  echo "Using local ./bootcd-backuplib" >&2
  . ./bootcdbackup.lib
elif [ -f /usr/share/bootcd/bootcdbackup.lib ]; then
  . /usr/share/bootcd/bootcdbackup.lib 
else
  echo "Error: Mandatory lib bootcdbackup.lib not found! ABORT!"
  exit 1
fi

for i in $CONFVARS; do
  [ "`set | grep ^$i=`" ] || err "$i is not set in $CONFDIR/bootcdbackup.conf"
done

# ignore this output from bootcdwrite
bootcd2disk_ignore()
{
  local mm=$1

  in_stdout $mm "^--- copying CD and RAM to"
  in_stdout $mm "^--- handling udev ---$"
  in_stdout $mm "^--- deleting NOT_TO_RAM symlinks ---$"
  in_stdout $mm "^--- Building fstab ---$"
  in_stdout $mm "^--- Resetting mtab ---$"
  in_stdout $mm "^--- Building grub/menu.lst ---$"
  in_stdout $mm "^--- Enabling turned off stuff ---$"
  in_ignore $mm "^Please Reboot now !$"
}  

# function: usage
# get: $1 -- error string
usage()
{
  [ "$1" ] && echo  >&2 "$1"
  echo  >&2 "[-i] [-v] [-s] [-c <confdir>] [-url <url] [-e <directories>] [-nomount] [-2diskconf <file>] <dev> <name> <builddir>"
  echo  >&2 " $(basename $0) make an offline backup."
  echo  >&2 " syntax:  -i           -- interactiv operation"
  echo  >&2 "          -v           -- be noisy"
  echo  >&2 "          -s           -- be silent and no interaction"
  echo  >&2  "     -e <directories> -- space seperated directories exclude from backup"
  echo  >&2 "          -c <confdir> -- use another configuration directory"
  echo  >&2 "          -url <url>   -- url from imageserver"
  echo  >&2 "                          (overwrite IMAGEURL and USEIMAGESERVER)"
  echo  >&2 "     -2diskconf <file> -- add your own bootcd2disk.conf for target system"
  echo  >&2 "                          (may be created with \"bootcdmk2diskconf\" on target disk)"
  echo  >&2 "          -nomount     -- don't mount target disk\n"
  echo  >&2 "          <dev>        -- device where to find the file \"fstab\" for the target disk"
  echo  >&2 "          <name>       -- name of the backup (no blanks!)"
  echo  >&2 "                          (used as directory /<name> where to find the tarball of the target disk)"
  echo  >&2 "                          (also used on bootcd2disk -c <name> to restore the backup)"
  echo  >&2 "          <builddir>   -- build the backup CD/DVD on this directory (need lot of space!)"
  echo  >&2 ""
  exit 1
}

############################## now the real things ###########################

cpiostar=""
excludes=""

# get options
while [ $# -gt 3 ]; do
  case "$1" in
     "-h"|"--help")
        usage
        ;;
     "-i")
        TODOY=""
        shift
        ;;
   "-url")
        ENV_IMAGEURL="$2"
        shift 2
        ;;
     "-v")
        VERBOSE="$1"
        shift
        ;;
     "-e")
        excludes="$2"
        shift 2
        ;;
     "-c")
        CONFDIR="$2"
        shift 2
        ;;
     "-s")
        SCRIPT="$1"
	shift
        ;;
     "-nomount")
        NOMOUNT="$1"
	shift
        ;;
     "-2diskconf")
        DISKCONF2="$2"
        shift 2
        ;;
# internal option, called from bootcdbackupwizard
# bootcdbackup [-i] [-e <dirs>] -cpiostar <head> <dir (write backup to)> <dir (get backup from)>
     "-cpiostar")
        cpiostar="yes"
        shift 1
        ;;
        *)
        usage "ERROR: option \"$1\" unknown!"
        ;;
  esac
done

# special for cpiostar
if [ "$cpiostar" ]; then
  RCPIO_EXCLUDE_DIRS="$excludes"
  IAHEAD="$1"
  run_cpiostar -d $2 $3
  exit 0
fi


if [ $# -ne 3 ]; then
  usage "Wrong number of parameters"
fi

BACKUPDEV="$1"
BACKUPNAME="$2"
BACKUPDIR="$3/$BOOTCDDIR"
COPYDEST="$BACKUPDIR/chroot"

### Main ###

A=""
while [ "$A" != "y" -a "$A" != "n" ]
do
  echo "Directory $BACKUPDIR will be removed and created again!(y|n) " | tee -a $ERRLOG >&2
  if [ "$SCRIPT" ]; then
    A="y"
  else
    read A
  fi
  echo "$A" >> $ERRLOG >&2
done
if [ "$A" = "n" ]; then
  exit 1
fi

CLEANTMP=""
CLEANUMNT=""
CLEANCHROOT=""
trap cleanup 2 EXIT

BOOTCD2DISK="bootcd2disk"
if [ -f ./bootcd2disk ]; then
  echo "using local ./bootcd2disk" | 
    if [ "$SCRIPT" ]; then cat >> $ERRLOG; else tee -a $ERRLOG >&2; fi
  BOOTCD2DISK="./bootcd2disk"
fi

BOOTCDMK2DISKCONF="bootcdmk2diskconf"
if [ -f ./bootcdmk2diskconf ]; then
  echo "using local ./bootcdmk2diskconf" | 
    if [ "$SCRIPT" ]; then cat >> $ERRLOG; else tee -a $ERRLOG >&2; fi
  BOOTCDMK2DISKCONF="./bootcdmk2diskconf"
fi

TODO=""
mm=0

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
in_stdout $mm "Directory.*"
TODO="$TODO \"do_dir $TMPDIR # Create tmp directory \""


mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
if [ "$DISKCONF2" ]; then
  TODO="$TODO \"cp $DISKCONF2 $TMPDIR/\""
else
  [ "$VERBOSE" ] && echo "--- Creating backup bootcd2disk.conf ---" | tee -a $ERRLOG >&2
  TODO="$TODO \"$BOOTCDMK2DISKCONF -b -f $BACKUPDEV > $TMPDIR/bootcd2disk.conf\""
fi

if [ ! "$NOMOUNT" ]; then
  mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
  TODO="$TODO \"$BOOTCD2DISK -onlymount -c $TMPDIR -s\""
  mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
  TODO="$TODO CLEANUMNT=\\\"$BOOTCD2DISK -onlyunmount -c $TMPDIR -s\\\"\""
fi

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"  
bootcd2disk_ignore $mm
TODO="$TODO \"$BOOTCD2DISK"
[ "$CONFDIR" = "/etc/bootcd" ] || TODO="$TODO -c $CONFDIR"
[ "$ENV_IMAGEURL" ] && TODO="$TODO -url $ENV_IMAGEURL"
TODO="$TODO -mkchroot $BACKUPDIR -s\""

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
TODO="$TODO CLEANCHROOT=\"rm -rf $BACKUPDIR\""

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
TODO="$TODO \"mkdir -p $COPYDEST/$BACKUPNAME\""

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
in_stdout $mm "^backup to .*"
in_ignore $mm "^find: WARNING: Hard link count is wrong for ./proc: .*"
in_stdout $mm "Permission denied$"
in_stdout $mm "^find: \./proc/.*"
in_stdout $mm "^cpio.*truncating inode number"
local RCPIO_EXCLUDE_DIRS="$(echo "$COPYDEST" | sed "s|^/mnt||") $EXCLUDE"
TODO="$TODO \"run_cpio $COPYDEST $BACKUPNAME\" # copy files to backup\""

# EXCLUDE=".$(echo "$COPYDEST" | sed "s|^/mnt||")"
# TODO="$TODO \"tar_ignore\""
# TODO="$TODO \"run \\\"(cd /mnt; tar c -z --exclude $EXCLUDE -f $COPYDEST/$BACKUPNAME/backup.tgz .)\\\"\""
mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
TODO="$TODO \"cp $TMPDIR/bootcd2disk.conf $COPYDEST/etc/bootcd/$BACKUPNAME\""

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
in_norun $mm # run the next without run 
TODO="$TODO \"chroot $COPYDEST bootcdwrite -s\""

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
TODO="$TODO \"mv $COPYDEST/var/spool/bootcd/cdimage.iso $BACKUPDIR/\""

mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
TODO="$TODO \"rm -r $COPYDEST\""

if [ ! "$NOMOUNT" ]; then
  mm=$(($mm+1)); eval IGNORE${mm}=\"\"; eval STDOUT${mm}=\"\"
  TODO="$TODO \"$BOOTCD2DISK -onlyunmount -c $TMPDIR -s\""
fi

eval "interactive -r $TODOY $TODO"