From: Alan Jack Pippin Date: Tue, 10 Jan 2006 06:46:12 +0000 (-0700) Subject: New script that will recreate a given disk image. X-Git-Tag: release-0.5~1 X-Git-Url: http://git.pippins.net/embedvideo/images/%3C?a=commitdiff_plain;h=3d773d9ad75c6f51dff6b317071be749b67393cb;p=backups%2F.git New script that will recreate a given disk image. --- diff --git a/scripts/repack-image.sh b/scripts/repack-image.sh new file mode 100755 index 0000000..a46a8df --- /dev/null +++ b/scripts/repack-image.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# One must supply the disk name as an argument to this script +[ $# == 1 ] || exit 1 + +scriptsdir=$(dirname $0) + +export PATH=$scriptsdir:/bin:/usr/bin:/sbin:/usr/sbin + +# source the default configuration +. config.sh + +# source the system specific configuration +[ -f /etc/lsbackups.conf ] && . /etc/lsbackups.conf + +isoimage="$imagedir/$1.iso" +isomountdir="$isoimage.mnt" + +echo "-> Checking for available disk space on $imagedir" +available=$(df $imagedir | awk '{print$4}' | grep -E "[0-9]+") +required=$((imagesizemb*1024)) +[ $required -gt $available ] && err "Not enough space for the backup image on $imagedir" + +echo "-> Creating directories" +mkdir --mode=700 -p $datadir $imagedir $isomountdir $tmpdir +if [ $? != 0 ]; then + test -d $isomountdir && rm -rf $isomountdir + err "Unable to create the following directories: + $datadir $imagedir $isomountdir $tmpdir" +fi + +echo "-> Creating the iso image in $isoimage" +dd of=$isoimage bs=1M count=0 seek=$imagesizemb + +[ $? != 0 ] && err "dd failed to create $isoimage" + +mke2fs -b $blocksize -F $isoimage +if [ $? != 0 ]; then + rm -rf $isomountdir $isoimage + err "Unable to create the iso image: $isoimage" +fi + +e2label $isoimage $today +if [ $? != 0 ]; then + rm -rf $isomountdir $isoimage + err "Unable to label the iso image: $isoimage" +fi + +echo "-> Mounting the iso image" +mount -t ext2 -o loop $isoimage $isomountdir +if [ $? != 0 ]; then + rm -rf $isomountdir $isoimage + err "Unable to mount the iso image: $isoimage -> $isomountdir" +fi + +echo "-> Querying backupdb for files originally placed on disk $1" +cat $backupdb | files-from-date.sh $1 > $1.filelist + +echo "-> Repacking backup image for disk $1" +cat $1.filelist | rsync -W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress / $isomountdir +umount $isomountdir +rm $1.filelist +md5sum $isoimage | awk '{print$1}' > $isoimage.md5sum + + + + + + + +