X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=blobdiff_plain;f=scripts%2Frestore-script.sh;h=daff5e571c414660f82e3e6d4da1c0e9de91cabd;hb=630a0aa5bb68026faa94652f9165ba593b084771;hp=fa16130323f4a2997a6eddfa3949a4997e585dd4;hpb=dcc0124d9ce7b2d6ee2230425e61446f9cc86a2d;p=backups%2F.git diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh index fa16130..daff5e5 100755 --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -1,29 +1,35 @@ #!/bin/sh -if [ -z "$mountdir" ]; then - echo >&2 '$mountdir must be set' +function err() { + echo >&2 "-E- $1" exit 1 -fi +} -if [ -z "$rundir" ]; then - echo >&2 '$rundir must be set' - exit 1 -fi +[ -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 [ $# != 2 -o ! -d "$1" -o ! -d "$2" ]; then - echo >&2 "Usage: $0 " - echo >&2 "Example: $0 / /" - exit 1 +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 device=$(mount | grep "on ${mountdir%%/} " | awk '{print$1}') -if [ -z "$device" ]; then - echo >&2 "Cannot determine cdrom device" - exit 1 -fi +[ -z "$device" ] && err "Cannot determine cdrom device" cp ${mountdir%%/}/backups.db ${mountdir%%/}/backup-status.txt $rundir dbfile=${rundir%%/}/backups.db @@ -31,23 +37,33 @@ dbfile=${rundir%%/}/backups.db dates=$(cat $dbfile | list-dates.sh) for date in $dates; do - success=false - while ! $success; do - eject $device - echo >&2 "Please insert backup disk: $date" - read bogus - eject -t $device - - # Mount the media - mount -t ext2 $device ${mountdir%%/} - - if grep -q $date ${mountdir%%/}/backup-status.txt; then - success=true - else - echo >&2 "This doesn't seem to be the right disk." - fi - done - - rsyncopts="-W -H -l -p -t -g -o -0 --files-from=- --stats --progress" - cat $dbfile | files-from-date.sh $date | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/ + filelist=$(tempfile) + # Check to see if files are actually needed from the current disk before requesting it. + cat $dbfile | files-from-date.sh $date | grep -z -Z -e "^${1%%/}/" > $filelist + if [ -s $filelist ]; then + 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 + + # Mount the media + mount -t ext2 $device ${mountdir%%/} + + if grep -q $date ${mountdir%%/}/backup-status.txt; then + success=true + else + echo "This doesn't seem to be the right disk." + fi + done + + rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress" + cat $filelist | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/ + else + echo "No files are needed from disk: $date. Skipping it." + fi + rm -f $filelist done