This logic should bypass asking for a disk if no files are going to be copied from...
[backups/.git] / scripts / restore-script.sh
index 9d9baabc9389a496e5a0db8771844331befe7f6b..62042d570263fb9d5adbce2f3d5a691e80a4827f 100755 (executable)
@@ -12,7 +12,7 @@ function err() {
 
 export PATH=${rundir%%/}:/bin:/usr/bin:/sbin:/usr/sbin:/sw/bin
 
-if [ ! -d "$mountdir$1" -o ! -d "$2" ]; then
+if [ ! -z "$1" -o ! -d "$2" ]; then
   err "
 Usage: $0 <source-dir> <relocate-dir> [<mnt-dir>]
        source-dir   - directory on backup disks to restore from (relative to $mountdir)
@@ -37,6 +37,10 @@ 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
+  if [ -s $filelist ]; then
   success=false
   while ! $success; do
     eject $device
@@ -57,5 +61,9 @@ 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 -Z -e "^${1}" | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/
+  cat $filelist | rsync $rsyncopts ${mountdir%%/}/ ${2%%/}/
+  else
+    echo "No files are needed from disk: $date.  Skipping it."
+  fi
+  rm -f $filelist
 done