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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
|
#!/bin/sh
#
# $Source: /cvsroot/bootcd/bootcd/bootcdbackupwizard.src,v $
# $Id: bootcdbackupwizard.src,v 1.70 2007-12-14 21:32:28 bs Exp $
# author: Carsten Dinkelmann <din@foobar-cpa.de>
# start: 20.09.2007
# topic: wizard for bootcddebootstrap and bootcdbackup
#
# Download: the newest version of this wizard can be downloaded with "wget
# ftp://bootcd.alioth.debian.org/pub/bootcd/bootcdbackupwizard"
#
# Version of debian package bootcd with this wizard included in
# /usr/share/doc/bootcd-backup/examples/bootcdbackupwizard
VERSION=##BOOTCD_VERSION## # sources are tagged in cvs with rev=debian_version_${VERSION}
# fixe language problem
export LANG=C
export LC_ALL=C
# used basis directory under the workdir
IMGDIR=bootcd-img
# download from there
BOOTSTRAPPATH="ftp://ftp.de.debian.org/debian/pool/main/d/debootstrap/debootstrap_0.3.3.2etch1_all.deb"
CVSBOOTCD="http://alioth.debian.org/plugins/scmcvs/cvsweb.php/~checkout~/bootcd"
BOOTCDDEBOOTSTRAPPATH="$CVSBOOTCD/bootcddebootstrap?only_with_tag=debian_version_${VERSION};content-type=text%2Fplain;cvsroot=bootcd"
NEWESTBOOTCDBACKUPWIZARDPATH="$CVSBOOTCD/bootcdbackupwizard?rev=HEAD;content-type=text%2Fplain;cvsroot=bootcd"
BOOTCDMK2DISKCONFPATH="$CVSBOOTCD/bootcdmk2diskconf?only_with_tag=debian_version_${VERSION};content-type=text%2Fplain;cvsroot=bootcd"
NEWESTBOOTCDMK2DISKCONFPATH="$CVSBOOTCD/bootcdmk2diskconf?rev=HEAD;content-type=text%2Fplain;cvsroot=bootcd"
NEWESTBOOTCDDEBOOTSTRAPPATH="http://alioth.debian.org/plugins/scmcvs/cvsweb.php/~checkout~/bootcd/bootcddebootstrap?rev=HEAD;content-type=text%2Fplain;cvsroot=bootcd"
# needed tools
TOOLS="wget tar ./bootcddebootstrap"
# exclude from backing up (ending slash includes the dirextory itself!)
EXCLUDE_DIRS="/proc/ /sys/ /dev/"
# subdir to $workdir where the backup tar resists later
BACKUPDIR="backup"
# PATH to bootcdmk2diskconf, under $workdir
BOOTCDMK2DISKCONF="/usr/share/bootcd/bootcdmk2diskconf"
ERRLOG="/var/log/bootcdbackupwizard.log"
# If SCRIPT is not empty, Warnings would be ignored
SCRIPT=""
######################### nothing to configure behind this line ###############
SCRIPTNAME=$(basename $0)
IAHEAD="$SCRIPTNAME $VERSION"
### BOOTCD-RUN_LIB Placeholder ##############
### BOOTCDBACKUP_LIB Placeholder ##############
# function: usage
# get: $1 -- error string
usage()
{
[ "$1" ] && echo >&2 "$1"
echo " $SCRIPTNAME Version $VERSION"
echo ""
echo " $SCRIPTNAME is the wizard for bootcddebootstrap and bootcdbackup. "
echo " bootcddebootstrap build a debian bootcd from scratch and bootcdbackup guess "
echo " the parameters of the running system and the system itself to the"
echo " created image. After that, you can backup your running system to a CD/DVD."
echo ""
echo " syntax: $SCRIPTNAME [-i] [-m <mirror>] [-e <directories>] -d <directory>"
echo ""
echo " -i -- do all things interactive"
echo " -m <mirror> -- debian mirror for debootstrap (e.g. http://ftp.de.debian.org/debian)"
echo " -e <directories> -- space seperated directories exclude from backup"
echo " -c <directory> -- look for bootcd2disk.conf and bootcdwrite.conf in"
echo " this directory and use it if found."
echo " -d <directory> -- create image in this directory (Space needed!)"
echo ""
echo " example: $SCRIPTNAME -e \"/home/data /home/newbie/tmp\" -d /var/spool/bootcd"
echo ""
exit 0
}
# function: realpath -- gives the full path of file or dir
realpath()
{
[ $# -eq 1 ] && echo "$(cd $(dirname $1); /bin/pwd)/$(basename $1)"
}
# function: in_stdout_wget -- in_stdout for wget
# get: $1 -- number
# ret: stdout string in STDOUT<number>
in_stdout_wget()
{
local mm=$1
in_stdout $mm "^--[[:digit:]:]*--.*"
in_stdout $mm "^[[:space:]]*=> .*"
in_stdout $mm "^Resolving .*"
in_stdout $mm "^Connecting .*"
in_stdout $mm "^Logging .*"
in_stdout $mm "^==> SYST .*"
in_stdout $mm "^==> TYPE .*"
in_stdout $mm "^==> PASV .*"
in_stdout $mm "^Length: .*"
in_stdout $mm "^[[:space:]]*OK.*"
in_stdout $mm "^Length .*"
in_stdout $mm "^$"
in_stdout $mm "^[[:digit:]:]* .*"
in_stdout $mm "^HTTP request sent, .* 200 OK[[:space:]]*$"
in_stdout $mm "^==> SIZE "
}
### functions below split tasks in main functions
### - to see what is going on
### - this functions use global variables
# function: create_debian_chroot
# get: $1 -- interactive (optional)
# globals: debootstrapmirror
create_debian_chroot()
{
local interact=""; [ $# -ge 1 ] && interact="$1"
local TODO="" tt="" mm=0
local IAHEAD="$IAHEAD / create_debian_chroot"
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm "^[[:space:]]*check for \"[^[:space:]]*\" ...ok$"
TODO="$TODO \"check_tools $TOOLS # Check if tools are installed\""
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm "Directory.*"
TODO="$TODO \"do_dir $workdir # Create work directories \""
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout_wget $mm
TODO="$TODO \"wget -P $workdir \\\"$BOOTSTRAPPATH\\\" # Get files to create mini debian system \""
# mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
# in_stdout_wget $mm
# TODO="$TODO \"wget -O $workdir/../bootcddebootstrap \\\"$bootcddebootstrappath\\\" # Get script to create mini debian system\""
# link debian files to work directory
for i in $(ls *deb); do
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
TODO="$TODO \"ln -s $(pwd)/$i $workdir/\""
done
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_norun $mm # run the next without run
[ "$debootstrapmirror" ] && tt="-m $debootstrapmirror"
TODO="$TODO \"./bootcddebootstrap <-i> -h \\\"$IAHEAD\\\" $tt -d $workdir/$IMGDIR $workdir\""
[ "$interact" ] && interact="" || interact="-y"
eval "interactive -h \"=== \$IAHEAD ===\" $interact -r $TODO"
}
trapfunc()
{
# Ignore Traps
trap "" 0 2
# We must tell the user to unmount if necessarry
echo >&2 "bootcdbackupwizard trapfunc: checking if filesystems are unmounted in $workdir/$IMGDIR/mnt"
if [ -e $workdir/$IMGDIR/mnt ]; then
if [ "$(/bin/ls $workdir/$IMGDIR/mnt/)" ]; then
BOOTCDMP="$workdir/$IMGDIR/mnt"
$workdir/$IMGDIR/usr/share/bootcd/bootcd2disk -onlyunmount -c /$BACKUPDIR -s -o -r $workdir/$IMGDIR
if [ "$(/bin/ls $workdir/$IMGDIR/mnt/)" ]; then
err "Could not unmount $workdir/$IMGDIR/mnt.
Be sure not to accidently remove $workdir/$IMGDIR before manually unmounting."
fi
fi
fi
exit 1
}
# function: do_backup
# get: $1 -- interactive (optional)
do_backup()
{
local interact=""; [ $# -ge 1 ] && interact="$1"
local TODO=""
local mm=0
local BOOTSTRAP_VERSION="$(chroot $workdir/$IMGDIR sh -c "dpkg-query -W -f='\${Version}\n' bootcd")"
local WIZARD_VERSION="$(echo "$VERSION" | sed "s/_/./")"
local IAHEAD="$IAHEAD / do_backup"
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm "Directory.*"
TODO="$TODO \"do_dir $workdir/$IMGDIR/$BACKUPDIR # Create work directories\""
if [ "$bootcd2diskconf" ]; then
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
TODO="$TODO \"cp $bootcd2diskconf $workdir/$IMGDIR/$BACKUPDIR/ # copy config given on commandline\""
else
# check chroot and file exist
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
TODO="$TODO \"chroot $workdir/$IMGDIR sh -c \\\"chmod 755 $BOOTCDMK2DISKCONF\\\"\""
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm "^ No volume groups found$"
TODO="$TODO \"sh -c \\\"$workdir/$IMGDIR/$BOOTCDMK2DISKCONF -b >$workdir/$IMGDIR/$BACKUPDIR/bootcd2disk.conf\\\" # create config from actual system\""
fi
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_norun $mm
BOOTCDMP="$workdir/$IMGDIR/mnt"
TODO="$TODO \"$workdir/$IMGDIR/usr/share/bootcd/bootcd2disk -onlymount -c /$BACKUPDIR -s -o -r $workdir/$IMGDIR\""
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_norun $mm
TODO="$TODO \"chroot $workdir/$IMGDIR /usr/share/bootcd/bootcdbackup -e \\\"$workdir $extdirs $EXCLUDE_DIRS\\\" -cpiostar \\\"$IAHEAD\\\" /mnt /$BACKUPDIR\""
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_norun $mm
BOOTCDMP="$workdir/$IMGDIR/mnt"
TODO="$TODO \"$workdir/$IMGDIR/usr/share/bootcd/bootcd2disk -onlyunmount -c /$BACKUPDIR -s -o -r $workdir/$IMGDIR\""
[ "$interact" ] && interact="" || interact="-y"
eval "interactive -h \"=== \$IAHEAD ===\" $interact -r $TODO"
# check if filesystems are really umounted
if [ "$(/bin/ls $workdir/$IMGDIR/mnt/)" ]; then
echo >&2 ""
echo >&2 "ATTENTION! Found files in \"$workdir/$IMGDIR/mnt\"!"
echo >&2 "Seems that umount doesn't work, please try it manualy!"
ask_user "Continue [y|N] " "n"
[ $? -eq 0 ] && err "User break after umount of \"$workdir/$IMGDIR/mnt\" failed!"
fi
}
# function: add_info -- add informations to first page
# get: $1 -- bootcd2disk.conf - file
add_info()
{
local ctrlL=""
local white="0f"
local grey="07"
local green="0a"
local yellow="0e"
local bootcdconf=$1
local file=/etc/bootcd/bootcdbackupwizard.txt
echo "${green}" >>$workdir/$IMGDIR/$file
cat >>$workdir/$IMGDIR/$file <<-'END'
_ _ _
| |__ ___ ___ | |_ ___ __| |
| '_ \ / _ \ / _ \| __/ __/ _` |_____
| |_) | (_) | (_) | || (_| (_| |_____|
|_.__/ \___/ \___/ \__\___\__,_|
_ _ _ _
| |__ __ _ ___| | ___ _ _ ____ _(_)______ _ _ __ __| |
| '_ \ / _` |/ __| |/ / | | | '_ \ \ /\ / / |_ / _` | '__/ _` |
| |_) | (_| | (__| <| |_| | |_) \ V V /| |/ / (_| | | | (_| |
|_.__/ \__,_|\___|_|\_\\__,_| .__/ \_/\_/ |_/___\__,_|_| \__,_|
|_|
END
# '
cat >>$workdir/$IMGDIR/$file <<END
${grey}Backup of host ${white}$(hostname) ${grey}from ${white}$(date "+%d. %B %Y, %X")
${white}restore with: ${yellow}bootcd2disk -c /backup
${grey}To select a cdrom specify "hda", "hdb", "hdc", "hdd", "scd0" or "scd1".
END
sed -ie "s|^\(DISPLAY=\"\)[^\"]*\(\"\)|\1${file}\2|" $bootcdconf
}
# function: run_bootcdwrite
# get: $1 -- interactive (optional)
run_bootcdwrite()
{
local interact=""; [ $# -ge 1 ] && interact="$1"
local TODO=""
local mm=0
local i
local IAHEAD="$IAHEAD / run_bootcdwrite"
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm ".*"
TODO="$TODO \"chroot $workdir/$IMGDIR bootcdwrite -s # create cd iso image\""
for i in var/spool/bootcd/cdimage.iso var/log/bootcdwrite.log var/log/bootstrap.log var/log/bootcdbackup.log; do
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
TODO="$TODO \"mv $workdir/$IMGDIR/$i $workdir\""
done
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm ".*"
TODO="$TODO \"rm -rf $workdir/$IMGDIR # cleanup\""
mm=$(($mm+1)); eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
in_stdout $mm ".*"
TODO="$TODO \"rm -f $workdir/bootcddebootstrap $workdir/$(basename $BOOTSTRAPPATH) # cleanup\""
[ "$interact" ] && interact="" || interact="-y"
eval "interactive -h \"=== \$IAHEAD ===\" $interact -r $TODO"
}
#################### the real things #########################################
TODO=""
workdir=""
interact=""
extdirs=""
ownconfdir=""
bootcd2diskconf=""
bootcdwriteconf=""
newestthis=""
debootstrapmirror=""
while [ $# -gt 0 ]; do
case "$1" in
"-d")
shift
workdir="$1"
;;
"-i")
interact="$1"
;;
"-e")
shift
extdirs="$1"
;;
"-c")
shift
ownconfdir="$1"
;;
"-m")
shift
debootstrapmirror="$1"
;;
"-N")
# undocumented Option only for developement
newestthis="$1"
;;
--help|-h)
usage
;;
*)
usage "parameter \"$1\" unknown!"
;;
esac
shift
done
if [ "$newestthis" ]; then
echo "Trying to load newer Backup"
[ -f $0.old ] || cp $0 $0.old
wget -O $0 "$NEWESTBOOTCDBACKUPWIZARDPATH"
exit 0
fi
[ ! "$workdir" ] && usage "Mandatory parameter \"workdir\" not found!"
workdir=$(realpath $workdir)
bootcddebootstrappath="$BOOTCDDEBOOTSTRAPPATH"
if [ "$ownconfdir" ]; then
ownconfdir=$(realpath $ownconfdir)
[ -e "$ownconfdir/bootcd2disk.conf" ] && bootcd2diskconf="$ownconfdir/bootcd2disk.conf"
[ -e "$ownconfdir/bootcdwrite.conf" ] && bootcdwriteconf="$ownconfdir/bootcdwrite.conf"
fi
trap trapfunc 0 2
TODO="$TODO \"create_debian_chroot <-i> # using $(basename $BOOTSTRAPPATH)\""
TODO="$TODO \"do_backup <-i> # including filesystem layout\""
if [ "$bootcdwriteconf" ]; then
TODO="$TODO \"cp $bootcdwriteconf $workdir/$IMGDIR/etc/bootcd/ # use bootcd config from commandline\""
else
TODO="$TODO \"add_info $workdir/$IMGDIR/etc/bootcd/bootcdwrite.conf\""
TODO="$TODO \"# change $workdir/$IMGDIR/etc/bootcd/bootcdwrite.conf if needed\""
fi
TODO="$TODO \"run_bootcdwrite <-i> # to create the iso image\""
TODO="$TODO \"mv $ERRLOG $workdir\""
TODO="$TODO \"mv /var/log/bootcddebootstrap.log $workdir\""
[ "$interact" ] && interact="" || interact="-y"
eval "interactive -h \"=== \$IAHEAD\" $interact $TODO"
echo "The result cdimage.iso plus logfiles are in $workdir"
|