Handle sparse files efficiently.
[backups/.git] / scripts / restore-script.sh
old mode 100644 (file)
new mode 100755 (executable)
index 402bb84..6592d72
@@ -1,24 +1,53 @@
 #!/bin/sh
 
-if [ $# != 1 ]; then
-  echo >&2 "Usage: $0 <target-directory>"
-  echo >&2 "Example: $0 /"
+if [ -z "$mountdir" ]; then
+  echo >&2 '$mountdir must be set'
   exit 1
 fi
 
-tmpdir=/tmp/restore-$(date +%Y%m%d%H%M%S)
+if [ -z "$rundir" ]; then
+  echo >&2 '$rundir must be set'
+  exit 1
+fi
+
+export PATH=${rundir%%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin
+
+if [ $# != 2 -o ! -d "$1" -o ! -d "$2" ]; then
+  echo >&2 "Usage: $0 <source-directory> <target-directory>"
+  echo >&2 "Example: $0 / /"
+  exit 1
+fi
+
+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
+    echo >&2 "Please insert backup disk:  $date"
+    read bogus
+    eject -t $device
 
-export PATH=$tmpdir:/bin:/usr/bin
+    # Mount the media
+    mount -t ext2 $device ${mountdir%%/}
 
-# Get the device with the CD in it here
-device=/dev/hdc
+    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
 
-for date in $(cat $dbfile | list-dates.sh); do
-  eject $device
-  echo >&2 "Please insert backup disk:  $date"
-  echo >&2 "Then press any key"
-  read bogus
-  # Mount the media
-  # rsync-cmd.sh won't work here in its current encarnation
-  cat $dbfile | files-from-date.sh | rsync-cmd.sh $1
+  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%%/}/
 done