X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=blobdiff_plain;f=scripts%2Frestore-script.sh;h=0796bef2d9155e5d1e99e1a52f66f4bd97710af0;hb=91a649790f76170c3d1a84bd4e18af005c7843c1;hp=402bb840cb7084966f1ad7522420d5d2d3547e7e;hpb=cb9371796a05c3ab8e74310e78a8d75e980a7b19;p=backups%2F.git diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh old mode 100644 new mode 100755 index 402bb84..0796bef --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -1,24 +1,61 @@ #!/bin/sh -if [ $# != 1 ]; then - echo >&2 "Usage: $0 " - echo >&2 "Example: $0 /" +function err() { + echo >&2 "-E- $1" exit 1 +} + +[ -n "$3" ] && mountdir=$3 + +[ -z "$mountdir" ] && err '$mountdir must be set' +[ -z "$rundir" ] && err '$rundir must be set' + +export PATH=${rundir%%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin + +if [ ! -z "$1" -o ! -d "$2" ]; then + err " +Usage: $0 [] + source-dir - directory on backup disks to restore from (relative to $mountdir) + relocate-dir - base directory to restore files to (usually /) + mnt-dir - directory where backup disk is mounted (optional) + + Examples: + % $0 / / /mnt/cdrom # Restore everything from disks (explicitly specifying dvd mount point.) + % $0 / / # Restore everything from disks + % $0 /home / # Restore only files under /home on disks to /home on the system + % $0 /home /home # Restore files under /home on disks to /home/home on the system (probably not what you want.) +" fi -tmpdir=/tmp/restore-$(date +%Y%m%d%H%M%S) +device=$(mount | grep "on ${mountdir%%/} " | awk '{print$1}') + +[ -z "$device" ] && err "Cannot determine cdrom device" + +cp ${mountdir%%/}/backups.db ${mountdir%%/}/backup-status.txt $rundir +dbfile=${rundir%%/}/backups.db + +dates=$(cat $dbfile | list-dates.sh) + +for date in $dates; do + success=false + while ! $success; do + eject $device + [ $? != 0 ] && err "Cannot eject the disk. Drive is busy. Run lsof $mountdir to see why." + echo "Please insert backup disk: $date" + echo "Press Enter to continue" + read bogus + eject -t $device -export PATH=$tmpdir:/bin:/usr/bin + # Mount the media + mount -t ext2 $device ${mountdir%%/} -# Get the device with the CD in it here -device=/dev/hdc + if grep -q $date ${mountdir%%/}/backup-status.txt; then + success=true + else + echo "This doesn't seem to be the right disk." + fi + done -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 + rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress" + cat $dbfile | files-from-date.sh $date | grep -z -Z -e "^${1%/}/" | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/ done