From: Carl N Baldwin Date: Tue, 25 Oct 2005 22:14:53 +0000 (-0600) Subject: Merge branch 'master' of home:dvl/backup X-Git-Tag: release-0.4~65 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=commitdiff_plain;h=332895f51c79faba592e57ae32363d8c597eb0e1;hp=b7347b04b24941f3b0a52471daa72597d1ed4645;p=backups%2F.git Merge branch 'master' of home:dvl/backup --- diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 2afda87..ba618aa 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,9 +1,22 @@ bin_SCRIPTS = \ drive.sh \ files-from-date.sh \ - find-cmd.sh \ list-dates.sh \ restore-script.sh \ - rsync-cmd.sh + restore.sh -EXTRA_DIST = $(bin_SCRIPTS) +EXTRA_DIST = $(bin_SCRIPTS) restore-header.sh + +restore_scripts = \ + files-from-date.sh \ + list-dates.sh \ + restore-script.sh + +restore_tar = restore.tgz + +restore.sh : restore-header.sh $(restore_tar) + { cat $<; cat $(restore_tar); } > $@ + chmod +x $@ + +$(restore_tar) : $(restore_scripts) + tar cf - $^ | gzip > $@ diff --git a/scripts/drive.sh b/scripts/drive.sh index 1693212..0b02689 100755 --- a/scripts/drive.sh +++ b/scripts/drive.sh @@ -15,6 +15,7 @@ backups="$tmpdir/backup-list.db" statusfile="$tmpdir/backup-status.txt" isomountdir="/backup/iso-mount" isoimage="/backup/iso-mount.iso" +restorescript="$scriptsdir/restore.sh" echo "Creating the iso image in $isoimage" touch $isoimage @@ -34,7 +35,12 @@ chmod 700 $tmpdir touch $currentfiles chmod 600 $currentfiles echo "Running find to get the status of files" -find-cmd.sh /home > $currentfiles +{ + for type in d f l; do + findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0" + find /home -type $type -printf "$findformat" + done +} > $currentfiles echo "Determining list of files to backup with lsbackups" { @@ -44,10 +50,11 @@ echo "Determining list of files to backup with lsbackups" } | lsbackups > $backups 2>$statusfile echo "Running rsync to pack the image" -cat $backups | rsync-cmd.sh $isomountdir +rsyncopts="-l -p -t -g -o -0 --files-from=- --stats --progress" +cat $backups | rsync $rsyncopts / $isomountdir echo "Copying over database and status file" -cp $statusfile $backupdb $isomountdir +cp $statusfile $backupdb $restorescript $isomountdir # umount $isomountdir diff --git a/scripts/find-cmd.sh b/scripts/find-cmd.sh deleted file mode 100755 index 51a3749..0000000 --- a/scripts/find-cmd.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -[ $# == 1 ] || exit 1 - -{ - for type in d f l; do - find $1 -type $type -printf "$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0" - done -} diff --git a/scripts/restore-header.sh b/scripts/restore-header.sh new file mode 100755 index 0000000..a147c62 --- /dev/null +++ b/scripts/restore-header.sh @@ -0,0 +1,18 @@ +#!/bin/sh +export rundir=/tmp/restore-$(date +%Y%m%d%H%M%S) +if ! mkdir $rundir; then + echo >&2 "Cannot create temp dir" + exit 1 +fi + +unset CDPATH +export mountdir=$(cd $(dirname $0) && pwd) + +SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0` + +# take the archive portion of this file and pipe it to tar +tail +$SKIP $0 | tar xzf - -C $rundir + +exec $rundir/restore-script.sh ${1+"$@"} + +__ARCHIVE_FOLLOWS__ diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh old mode 100644 new mode 100755 index 402bb84..1bf8dcc --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -1,24 +1,34 @@ #!/bin/sh +export PATH=$rundir:/bin:/usr/bin + if [ $# != 1 ]; then - echo >&2 "Usage: $0 " - echo >&2 "Example: $0 /" + echo >&2 "Usage: $0 " + echo >&2 "Example: $0 / /" exit 1 fi -tmpdir=/tmp/restore-$(date +%Y%m%d%H%M%S) - -export PATH=$tmpdir:/bin:/usr/bin +device=$(mount | grep "on $mountdir " | awk '{print$1}') -# Get the device with the CD in it here -device=/dev/hdc +cp $mountdir/backups.db $mountdir/backup-status.txt $rundir +dbfile=$rundir/backups.db for date in $(cat $dbfile | list-dates.sh); do - eject $device - echo >&2 "Please insert backup disk: $date" - echo >&2 "Then press any key" - read bogus - # Mount the media - # rsync-cmd.sh won't work here in its current encarnation - cat $dbfile | files-from-date.sh | rsync-cmd.sh $1 + success=false + while ! $success; do + eject $device + echo >&2 "Please insert backup disk: $date" + read bogus + + # Mount the media + mount -t ext2 $device $mountdir + if [ "" != "$(grep -l $date $mountdir/backup-status.txt)" ]; then + success=true + else + echo >&2 "This doesn't seem to be the right disk." + fi + done + + rsyncopts="-l -p -t -g -o -0 --files-from=- --stats --progress " + cat $dbfile | files-from-date.sh | rsync $rsyncopts $1 $2 done diff --git a/scripts/rsync-cmd.sh b/scripts/rsync-cmd.sh deleted file mode 100755 index aa7e9f7..0000000 --- a/scripts/rsync-cmd.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# This file just has some ideas about how to do the rsync command with the list -# of file produced by lsbackups - -[ $# == 1 ] || exit 1 -[ -d $1 ] || exit 1 - -# -H ? -W ? -rsync_opts='-W -H -l -p -t -g -o -0 --files-from=-' - -other_opts='--stats --progress' - -# Should also include directories in there -rsync $rsync_opts $other_opts / $1