Index: trunk/tools/neb_rawOTA_host_scan.pl
===================================================================
--- trunk/tools/neb_rawOTA_host_scan.pl	(revision 36313)
+++ trunk/tools/neb_rawOTA_host_scan.pl	(revision 36337)
@@ -21,8 +21,9 @@
     ) or die "Unable to connect to database $DBI::errstr\n";
 
-my ($host,$min_ins_id,$verbose,$limit);
+my ($host,$min_ins_id,$verbose,$limit,$continue);
 $min_ins_id = 0;
 $verbose = 0;
 $limit = 10000;
+$continue = 0;
 
 GetOptions(
@@ -31,4 +32,5 @@
     'verbose|v'     => \$verbose,
     'limit|l=s'     => \$limit,
+    'continue|c'    => \$continue,
     ) or pod2usage( 2 );
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
@@ -66,63 +68,73 @@
 
 # Get the files on this host
-
-my $ins_id_sth = "SELECT ins_id,so_id,uri FROM instance WHERE vol_id = ${vol_id} AND ins_id > $min_ins_id LIMIT $limit";
-my $r_ins      = $db->selectall_arrayref( $ins_id_sth );
-my $last_ins_id = 0;
-foreach $rr (@{ $r_ins }) {
-    my ($ins_id,$so_id,$uri) = @{ $rr };
-    if ($verbose) {
+my $number = 0;
+do {
+    my $ins_id_sth = "SELECT ins_id,so_id,uri FROM instance WHERE vol_id = ${vol_id} AND ins_id > $min_ins_id LIMIT $limit";
+    my $r_ins      = $db->selectall_arrayref( $ins_id_sth );
+    my $last_ins_id = 0;
+    $number = 0;
+    foreach $rr (@{ $r_ins }) {
+	my ($ins_id,$so_id,$uri) = @{ $rr };
+	if ($verbose) {
 #	print ("  $ins_id $so_id $uri\n");
-    }
-    if ($uri !~ /ota...fits/) { next; }
-    my $have_b_node = 0;
-    my ($ext_id,$occ_id,$oth_id,$name,$value) = ('',0,0,'','');
-    my $rr2;
-
-    my $so_id_sth = "SELECT ext_id,so_id,vol_id,ins_id,name,value FROM storage_object JOIN instance USING(so_id) LEFT JOIN storage_object_xattr USING(so_id) WHERE so_id = ${so_id} AND ins_id != ${ins_id} AND (name IS NULL OR name = 'user.copies')";
-
-    my $r_so      = $db->selectall_arrayref( $so_id_sth );
-
-    foreach $rr2 (@{ $r_so }) {
-	($ext_id,$so_id,$occ_id,$oth_id,$name,$value) = @{ $rr2 };
+	}
+	$number++;
+	$last_ins_id = $ins_id;
+	if ($uri !~ /ota...fits/) { next; }
+	my $have_b_node = 0;
+	my ($ext_id,$occ_id,$oth_id,$name,$value) = ('',0,0,'','');
+	my $rr2;
 	
-	unless(defined($name)) {
-	    $name = 'UNDEF';
-	    $value = 1;
-	}
-
-	if ($name eq 'user.copies') {
-	    if ($value == 1) {
+	my $so_id_sth = "SELECT ext_id,so_id,vol_id,ins_id,name,value FROM storage_object JOIN instance USING(so_id) LEFT JOIN storage_object_xattr USING(so_id) WHERE so_id = ${so_id} AND ins_id != ${ins_id} AND (name IS NULL OR name = 'user.copies')";
+	
+	my $r_so      = $db->selectall_arrayref( $so_id_sth );
+	
+	foreach $rr2 (@{ $r_so }) {
+	    ($ext_id,$so_id,$occ_id,$oth_id,$name,$value) = @{ $rr2 };
+	    
+	    unless(defined($name)) {
+		$name = 'UNDEF';
+		$value = 1;
+	    }
+	    
+	    if ($name eq 'user.copies') {
+		if ($value == 1) {
+		    $have_b_node = 1;
+		}
+	    }
+	    else {
 		$have_b_node = 1;
 	    }
+	    
+	    if (defined($b_nodes{$occ_id})) {
+		$have_b_node = 1;
+	    }
+	    if ($verbose) {
+		print("   $number $ext_id $so_id $occ_id $oth_id $have_b_node $name $value\n");
+	    }
+	    
+	    if ($have_b_node == 1) {
+		last;
+	    }
 	}
-	else {
-	    $have_b_node = 1;
+	if ($oth_id) {
+	    if ($have_b_node != 1) {
+		my $rep_host = int(rand() + 0.5) + 4;
+		my $rep_part = int(rand(3));
+		my $rep_vol  = "ippb0" . $rep_host . "." . $rep_part;
+		
+		print("neb-replicate --volume $rep_vol $ext_id\n");
+		system("neb-replicate --volume $rep_vol $ext_id");
+	    }
 	}
-
-	if (defined($b_nodes{$occ_id})) {
-	    $have_b_node = 1;
+	$last_ins_id = $ins_id;
+    }
+    print "## LAST: $last_ins_id $number\n";
+    print "## TRY:  neb_rawOTA_host_scan.pl --host $host --limit $limit --min $last_ins_id\n";
+    if ($continue) {
+	if ($verbose) {
+	    print("RESET $min_ins_id -> $last_ins_id $number\n");
 	}
-	if ($verbose) {
-	    print("   $ext_id $so_id $occ_id $oth_id $have_b_node $name $value\n");
-	}
-
-	if ($have_b_node == 1) {
-	    last;
-	}
+	$min_ins_id = $last_ins_id;
     }
-    if ($oth_id) {
-	if ($have_b_node != 1) {
-	    my $rep_host = int(rand() + 0.5) + 4;
-	    my $rep_part = int(rand(3));
-	    my $rep_vol  = "ippb0" . $rep_host . "." . $rep_part;
-
-	    print("neb-replicate --volume $rep_vol $ext_id\n");
-	    system("neb-replicate --volume $rep_vol $ext_id");
-	}
-    }
-    $last_ins_id = $ins_id;
-}
-print "## LAST: $last_ins_id\n";
-print "## TRY:  neb_rawOTA_host_scan.pl --host $host --limit $limit --min $last_ins_id\n";
-
+} while ($continue && $number != 0);
