Merging release-0.2.1 release-0.3.1
authorCarl N. Baldwin <carl@ecbaldwin.net>
Tue, 13 Dec 2005 16:53:05 +0000 (09:53 -0700)
committerCarl N. Baldwin <carl@ecbaldwin.net>
Tue, 13 Dec 2005 16:53:05 +0000 (09:53 -0700)
scripts/files-from-date.sh
scripts/restore-header.sh
scripts/restore-script.sh

index 2db6fc228c378165e316fb3a00236dbd464360b7..de98d4366d46250cce9eec3d93f7b7b83f5269fb 100755 (executable)
@@ -2,4 +2,4 @@
 
 [ $# == 1 ] || exit 1
 
-gawk --posix 'BEGIN { RS="\0" } { d=$7; gsub( /^([^ ]*[ ]){7,7}/, "" ); if ( date == d ) printf "%s\0",$0 }' date=$1
+awk 'BEGIN { RS="\0" } { d=$7; sub( /^([^ ]*[ ])([^ ]*[ ])([^ ]*[ ])([^ ]*[ ])([^ ]*[ ])([^ ]*[ ])([^ ]*[ ])/, "" ); if ( date == d ) printf "%s\0",$0 }' date=$1
index 8374076c69134d8cf085f70f14ea56af919b1b05..b05d19c38314e2c73adf6fe6dd00749c0f9bc427 100755 (executable)
@@ -8,7 +8,9 @@ if ! mkdir $rundir; then
 fi
 
 unset CDPATH
-export mountdir=$(cd $(dirname $0) && pwd)
+if [ -z "$3" ]; then
+  export mountdir=$(cd $(dirname $0) && pwd -P)
+fi
 
 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`
 
index 6592d72a612f8360d74e473bbd916387637931d4..e4fba472fb79803735f4032fc5b131c631e02c01 100755 (executable)
@@ -1,53 +1,80 @@
 #!/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
 
-export PATH=${rundir%%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin
+[ -z "$mountdir" ] && err '$mountdir must be set'
 
-if [ $# != 2 -o ! -d "$1" -o ! -d "$2" ]; then
-  echo >&2 "Usage: $0 <source-directory> <target-directory>"
-  echo >&2 "Example: $0 / /"
-  exit 1
-fi
+rundir=${rundir:-$(dirname $0)}
 
-device=$(mount | grep "on ${mountdir%%/} " | awk '{print$1}')
+export PATH=${rundir%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin
 
-if [ -z "$device" ]; then
-  echo >&2 "Cannot determine cdrom device"
-  exit 1
+if [ -z "$1" -o ! -d "$2" ]; then
+  err "
+
+Usage: $(basename $0) <source-dir> <relocate-dir> [<mnt-dir>]
+  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
 
-cp ${mountdir%%/}/backups.db ${mountdir%%/}/backup-status.txt $rundir
-dbfile=${rundir%%/}/backups.db
+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
 
 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 -S -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