X-Git-Url: http://git.pippins.net/embedvideo/.git/static/gitweb.js?a=blobdiff_plain;f=scripts%2Frestore-script.sh;h=66ac4fb5b4da27c64842c96444daf04313059a71;hb=9c5abcc59e83fa16bfeb810cc4d51960f8586a4e;hp=42fe9000e60ccb06d15fecd529eb5ad336fdc29f;hpb=f68576bb8ca6dc3fb5457925ae039e623b95bd45;p=backups%2F.git diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh index 42fe900..66ac4fb 100755 --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -1,35 +1,67 @@ #!/bin/sh -export PATH=$rundir:/bin:/usr/bin +function err() { + echo 2>&1 "-E- $1" + exit 1 +} + +if [ ! -z "$3" ]; then + mountdir=$3 +fi + +if [ -z "$mountdir" ]; then + echo >&2 '$mountdir must be set' + exit 1 +fi -if [ $# != 1 ]; then - echo >&2 "Usage: $0 " - echo >&2 "Example: $0 / /" +if [ -z "$rundir" ]; then + echo >&2 '$rundir must be set' exit 1 fi -device=$(mount | grep "on $mountdir " | awk '{print$1}') +export PATH=${rundir%%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin -cp $mountdir/backups.db $mountdir/backup-status.txt $rundir -dbfile=$rundir/backups.db +if [ ! -d "$1" -o ! -d "$2" ]; then + echo >&2 "Usage: $0 []" + echo >&2 " source-dir - directory on backup disks to restore from" + echo >&2 " target-dir - directory to restore files to" + echo >&2 " mnt-dir - directory where backup disk is mounted (optional)" + echo >&2 "Example: $0 / / /mnt/cdrom" + exit 1 +fi -for date in $(cat $dbfile | list-dates.sh); do +device=$(mount | grep "on ${mountdir%%/} " | awk '{print$1}') + +if [ -z "$device" ]; then + echo >&2 "Cannot determine cdrom device" + exit 1 +fi + +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 >&2 "Please insert backup disk: $date" + echo >&2 "Press Enter to continue" read bogus eject -t $device # Mount the media - mount -t ext2 $device $mountdir - if [ "" != "$(grep -l $date $mountdir/backup-status.txt)" ]; then + 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." + echo "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 $mountdir $2 + rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress" + cat $dbfile | files-from-date.sh $date | grep -z -e "${1}" | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/ done