Index: trunk/tools/eam/rebalance/rebalance.mana
===================================================================
--- trunk/tools/eam/rebalance/rebalance.mana	(revision 41385)
+++ trunk/tools/eam/rebalance/rebalance.mana	(revision 41406)
@@ -158,5 +158,5 @@
     sprintf movelist %s/rebalance/movefiles.%s.txt $srcdir $VERSION
     sprintf movelog  %s/rebalance/movefiles.%s.log $srcdir $VERSION
-    sprintf subdirset "%s/0?" $srcdir
+    sprintf subdirset "%s/??" $srcdir
     exec find $subdirset -size +$BIGSIZE > $filelist
     list files -x "/bin/ls -l `cat $filelist` | sort -k 5nr"
@@ -228,4 +228,39 @@
 end
 
+macro run.rsync.check
+  if ($0 != 7)
+    echo "USAGE: run.rsync.check (srchost) (srcvol) (tgthost) (tgtvol) (VERSION) (OUTVER)"
+    echo "srchost, tgthost : e.g., ipp070"
+    echo "srcvol, tgtvol   : e.g., 0 (for /data/ipp070.0/nebulous)"
+    break
+  end
+
+  local srchost srcvol tgthost tgtvol
+
+  $srchost = $1
+  $srcvol = $2
+  $tgthost = $3
+  $tgtvol = $4
+  $VERSION = $5
+  $OUTVER  = $6
+
+  # generate the full paths:
+  $source = /data/$srchost.$srcvol/nebulous
+  $target = /data/$tgthost.$tgtvol/rebalance/$srchost.$srcvol/nebulous
+
+  for i 0 $NSUBDIR
+    sprintf srcdir "%s/%02x" $source $i
+    sprintf tgtdir "%s/%02x" $target $i
+    # echo $srcdir
+
+    # generate initial file list (all big files)
+    sprintf movelist %s/rebalance/movefiles.%s.txt $srcdir $VERSION
+    sprintf movelog  %s/rebalance/movefiles.%s.log $srcdir $OUTVER
+
+    echo "rsyncing $srcdir/ to $tgtdir/ : $movelog"
+    exec rsync -auv --files-from=$movelist $srcdir/ $tgtdir/ >& $movelog
+  end
+end
+
 # names are defined for a single src & tgt pair
 macro run.insert
@@ -287,7 +322,7 @@
 
 # names are defined for a single src & tgt pair
-macro run.check
+macro run.insert.check
   if ($0 != 6)
-    echo "USAGE: run.check (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
+    echo "USAGE: run.insert.check (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
     echo "srchost, tgthost : e.g., ipp070"
     echo "srcvol, tgtvol   : e.g., 0 (for /data/ipp070.0/nebulous)"
@@ -384,7 +419,7 @@
 end
 
-macro run.check.trash
+macro run.trash.check
   if ($0 != 6)
-    echo "USAGE: run.check.trash (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
+    echo "USAGE: run.trash.check (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
     echo "srchost, tgthost : e.g., ipp070"
     echo "srcvol, tgtvol   : e.g., 0 (for /data/ipp070.0/nebulous)"
@@ -407,8 +442,9 @@
   for i 0 $NSUBDIR
     sprintf trashdir "/data/%s.%s/nebulous/%02x/trash" $srchost $srcvol $i
+    sprintf savedir  "/data/%s.%s/nebulous/%02x/save" $srchost $srcvol $i
     sprintf trashlog "/data/%s.%s/nebulous/%02x/rebalance/check.trash.%s.log" $srchost $srcvol $i $VERSION
 
-     echo ./neb_check_trash.pl --srchost $srchost --trashdir $trashdir > $trashlog
-    $EXEC ./neb_check_trash.pl --srchost $srchost --trashdir $trashdir > $trashlog
+     echo ./neb_check_trash.pl --srchost $srchost --trashdir $trashdir --savedir $savedir > $trashlog
+    $EXEC ./neb_check_trash.pl --srchost $srchost --trashdir $trashdir --savedir $savedir > $trashlog
   end
 
@@ -455,13 +491,16 @@
 
     # list of files which have been moved & checked
-    sprintf movelist /data/%s.%s/nebulous/%02x/rebalance/movefiles.%s.txt $srchost $srcvol $i $VERSION
-
-    list files -x "cat $movelist"
+#   sprintf movelist /data/%s.%s/nebulous/%02x/rebalance/movefiles.%s.txt $srchost $srcvol $i $VERSION
+
+    list files -glob $trashdir/*
     for j 0 $files:n
-      basename $files:$j -var myfile
-
+      file $files:$j -can-write canWrite
+      if (not($canWrite))
+        echo "SKIP write-protected file : $files:$j"
+        next
+      end    
       # remove the file from the trash directory
-      echo rm $trashdir/$myfile
-      exec rm $trashdir/$myfile
+      echo rm $files:$j
+      exec rm $files:$j
     end
   end
@@ -469,8 +508,8 @@
 
 if ($SCRIPT) 
-  if ($argv:n < 6) 
+  if ($argv:n < 1) 
     echo "USAGE: rebalance.mana (MODE) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION) [options]"
     echo ""
-    echo "MODE: find.test, find, rsync, insert, check, trash, check.trash, empty.trash"
+    echo "MODE: find.test, find, rsync, rsync.check, insert, insert.check, trash, trash.check, empty.trash"
     echo ""
     echo "srchost, tgthost : e.g., ipp070"
@@ -513,4 +552,14 @@
   end
 
+  #### rsync.check ####
+  if ("$argv:0" == "rsync.check")
+    if ($argv:n != 7)
+      echo "USAGE: rebalance.mana (rsync.check) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION) (OUTVER)"
+      break
+    end
+    run.rsync.check $argv:1 $argv:2 $argv:3 $argv:4 $argv:5 $argv:6
+    exit 0
+  end
+
   #### insert ####
   if ("$argv:0" == "insert")
@@ -523,11 +572,11 @@
   end
 
-  #### check ####
-  if ("$argv:0" == "check")
+  #### insert.check ####
+  if ("$argv:0" == "insert.check")
     if ($argv:n != 6)
-      echo "USAGE: rebalance.mana (check) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
-      break
-    end
-    run.check $argv:1 $argv:2 $argv:3 $argv:4 $argv:5
+      echo "USAGE: rebalance.mana (insert.check) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
+      break
+    end
+    run.insert.check $argv:1 $argv:2 $argv:3 $argv:4 $argv:5
     exit 0
   end
@@ -543,11 +592,11 @@
   end
 
-  #### check.trash ####
-  if ("$argv:0" == "check.trash")
+  #### trash.check ####
+  if ("$argv:0" == "trash.check")
     if ($argv:n != 6)
-      echo "USAGE: rebalance.mana (check.trash) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
-      break
-    end
-    run.check.trash $argv:1 $argv:2 $argv:3 $argv:4 $argv:5
+      echo "USAGE: rebalance.mana (trash.check) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
+      break
+    end
+    run.trash.check $argv:1 $argv:2 $argv:3 $argv:4 $argv:5
     exit 0
   end
@@ -556,5 +605,5 @@
   if ("$argv:0" == "empty.trash")
     if ($argv:n != 6)
-      echo "USAGE: rebalance.mana (check.trash) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
+      echo "USAGE: rebalance.mana (empty.trash) (srchost) (srcvol) (tgthost) (tgtvol) (VERSION)"
       break
     end
@@ -563,4 +612,5 @@
   end
 
-  exit 0
-end
+  echo "ERROR: unknown mode $argv:0"
+  exit 1
+end
