Index: trunk/tools/eam/rebalance/rebalance.mana
===================================================================
--- trunk/tools/eam/rebalance/rebalance.mana	(revision 41407)
+++ trunk/tools/eam/rebalance/rebalance.mana	(revision 41456)
@@ -40,8 +40,8 @@
   # generate the full paths:
   $source = /data/$srchost.$srcvol/nebulous
-  $target = /data/$tgthost.$tgtvol/rebalance/$srchost.$srcvol/nebulous
+  # $target = /data/$tgthost.$tgtvol/rebalance/$srchost.$srcvol/nebulous
 
   ## make sure target exists
-  mkdir $target
+  # mkdir $target
 
   ## this script must be run on the same machine as the source
@@ -106,5 +106,5 @@
 
   ## make sure target exists
-  mkdir $target
+  # mkdir $target
 
   ## this script must be run on the same machine as the source
@@ -159,4 +159,9 @@
     sprintf movelog  %s/rebalance/movefiles.%s.log $srcdir $VERSION
     sprintf subdirset "%s/??" $srcdir
+
+    local isFound
+    file $movelist isFound
+    if ($isFound) continue
+
     exec find $subdirset -size +$BIGSIZE > $filelist
 
@@ -216,4 +221,17 @@
   $target = /data/$tgthost.$tgtvol/rebalance/$srchost.$srcvol/nebulous
 
+  ## make sure target exists
+  mkdir $target
+
+  $TIMEFORMAT = mjd
+  $TIMEREF = 2000/01/01,00:00:00; # this is not used but required to exist for ctimes
+  
+  # give the start of the night in HST hours:
+  $HSTNightStart = 18.5
+  $HSTNightEnd   =  7.5
+
+  $UTNightStart = ($HSTNightStart + 10) / 24; $UTNightStart = $UTNightStart - int($UTNightStart)
+  $UTNightEnd   = ($HSTNightEnd   + 10) / 24; $UTNightEnd   = $UTNightEnd   - int($UTNightEnd)
+
   for i 0 $NSUBDIR
     sprintf srcdir "%s/%02x" $source $i
@@ -226,5 +244,19 @@
 
     echo "rsyncing $srcdir/ to $tgtdir/ : $movelog"
+    break -auto off
     exec rsync -auv --files-from=$movelist $srcdir/ $tgtdir/ >& $movelog
+    break -auto on
+
+    # check the time: is it night time (sleep and restart later)
+    $isNight = 1
+    while ($isNight)
+      ctimes -abs now -var tnow
+      $tfrac = $tnow - int($tnow)
+      $isNight = (($tfrac > $UTNightStart) && ($tfrac < $UTNightEnd))
+      if ($isNight) 
+        echo "it is night time, sleeping until the morning"
+        sleep 600
+      end
+    end
   end
 end
