X-Git-Url: http://git.pippins.net/embedvideo/.git/static/gitweb.js?a=blobdiff_plain;f=scripts%2Frestore-script.sh;h=c95b8400fbc9496f57f9b8c34dc6a852a7acf201;hb=585cc3075e523dabd02a5762188524ba3a530ebd;hp=62042d570263fb9d5adbce2f3d5a691e80a4827f;hpb=575a6caced28aeb051f876d1c3db1a8188164685;p=backups%2F.git diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh index 62042d5..c95b840 100755 --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -10,58 +10,68 @@ function err() { [ -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 +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) [] + 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 -device=$(mount | grep "on ${mountdir%%/} " | awk '{print$1}') +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 +cp ${mountdir%/}/backups.db ${mountdir%/}/backup-status.txt $rundir +dbfile=${rundir%/}/backups.db dates=$(cat $dbfile | list-dates.sh) for date in $dates; do 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 + 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%%/}/ + 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