X-Git-Url: http://git.pippins.net/embedvideo/.git/?a=blobdiff_plain;f=scripts%2Frestore-script.sh;h=af5a80cd684deee617c8cc4cedd522f6d6e3cca6;hb=200a6dda1a8381f3c83753156d6248ba7ff8836b;hp=ed42a96bd700f00108b1ba99a6b3026b1afd83a0;hpb=00cc94878d3cf4de6b6739e22e49d3c568388b89;p=backups%2F.git diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh index ed42a96..af5a80c 100755 --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -8,22 +8,33 @@ function err() { [ -n "$3" ] && mountdir=$3 [ -z "$mountdir" ] && err '$mountdir must be set' -[ -z "$rundir" ] && err '$rundir must be set' + +rundir=${rundir:-$(dirname $0)} export PATH=${rundir%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin -if [ ! -z "$1" -o ! -d "$2" ]; then +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.) + +Usage: $(basename $0) [ [remote_user@remote_host]] + source-dir - Directory on backup disks to restore (relative to + $mountdir) + relocate-dir - Base directory to restore files into (usually /) + mnt-dir - Directory where backup disk is mounted (optional) + +Examples: + # Restore everything from disks (explicitly specifying dvd mount point.) + % $(basename $0) / / /mnt/cdrom + + # Restore everything from disks + % $(basename $0) / / + + # Restore only files under /home on disks to /home on the system + % $(basename $0) /home / + + # Restore files under /home on disks to /home/home on the system + # (this is usually not what you want.) + % $(basename $0) /home /home " fi @@ -42,6 +53,7 @@ for date in $dates; do cat $dbfile | files-from-date.sh $date | grep -z -Z -e "^${1%/}/" > $filelist if [ -s $filelist ]; then success=false + loop=0 while ! $success; do eject $device [ $? != 0 ] && err "Cannot eject the disk. Drive is busy. Run lsof $mountdir to see why." @@ -55,13 +67,23 @@ for date in $dates; do if grep -q $date ${mountdir%/}/backup-status.txt; then success=true - else + elif e2label $device | grep -q $date; then + success=true + elif [ $loop -gt 2 ]; then + echo "I still can't verify the identity of the disk." + echo "If you are sure it is correct, press Enter to continue." + echo "Otherwise, press CTRL-C to abort." + read bogus + success=true + else echo "This doesn't seem to be the right disk." + loop=$((loop+1)) fi done rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress" - cat $filelist | rsync $rsyncopts ${mountdir%/}/ ${2%/}/ + [ -z "$4" ] && cat $filelist | rsync $rsyncopts ${mountdir%/}/ ${2%/}/ + [ -n "$4" ] && cat $filelist | rsync $rsyncopts -e ssh ${mountdir%/}/ ${4}:${2%/}/ else echo "No files are needed from disk: $date. Skipping it." fi