From: Carl Baldwin Date: Tue, 29 Nov 2005 17:00:16 +0000 (-0700) Subject: Misc fixes to restore script. X-Git-Tag: release-0.4~10 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/%7Bdelete%7D?a=commitdiff_plain;h=2b19c613bbb418da0fff6cddaa01a21b87271cb1;p=backups%2F.git Misc fixes to restore script. - Fix err function to output to standard err. - Use err function throughout script to make it more concise. - Add some more verbosity and examples to the Usage message to make it more clear how to use this script. - Don't output non-error messages to std-err. - Use -Z option to grep (Is this really necessary? I'm not sure) - Start grep pattern with ^ to only match the pattern at the beginning of the line --- diff --git a/scripts/restore-script.sh b/scripts/restore-script.sh index 66ac4fb..9d9baab 100755 --- a/scripts/restore-script.sh +++ b/scripts/restore-script.sh @@ -1,41 +1,35 @@ #!/bin/sh function err() { - echo 2>&1 "-E- $1" + echo >&2 "-E- $1" exit 1 } -if [ ! -z "$3" ]; then - mountdir=$3 -fi +[ -n "$3" ] && mountdir=$3 -if [ -z "$mountdir" ]; then - echo >&2 '$mountdir must be set' - exit 1 -fi - -if [ -z "$rundir" ]; then - echo >&2 '$rundir must be set' - exit 1 -fi +[ -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 [ ! -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 +if [ ! -d "$mountdir$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 @@ -47,8 +41,8 @@ for date in $dates; do 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" + echo "Please insert backup disk: $date" + echo "Press Enter to continue" read bogus eject -t $device @@ -63,5 +57,5 @@ for date in $dates; do done 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%%/}/ + cat $dbfile | files-from-date.sh $date | grep -z -Z -e "^${1}" | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/ done