dates=$(cat $dbfile | list-dates.sh)
for date in $dates; do
- 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 $dbfile | files-from-date.sh $date | grep -z -Z -e "^${1%/}/" | 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