--- trunk/scripts/estcp.pl 2006/01/17 00:17:50 82 +++ trunk/scripts/estcp.pl 2006/01/17 15:00:50 85 @@ -17,6 +17,7 @@ die "usage: $0 http://localhost:1978/node/from http://remote.example.com:1978/node/to\n" unless ($from && $to); my $debug = 0; +my $max = 256; # create and configure node my $from_n = new Search::Estraier::Node( @@ -30,26 +31,49 @@ debug => $debug, ); +unless(eval{ $to_n->name }) { + if ($to =~ m#^(http://.+)/node/(\w+)$#) { + my ($url,$name) = ($1,$2); + print "Creating '$name' on $url\n"; + $to_n->shuttle_url( $url . '/master?action=nodeadd', + 'application/x-www-form-urlencoded', + 'name=' . uri_escape($name) . '&label=' . uri_escape( $name ), + undef, + ); + } else { + die "can't extract node name from $to\n"; + } +} + print "Copy from ",$from_n->name," (",$from_n->label,") to ",$to_n->name," (",$to_n->label,") - ",$from_n->doc_num," documents (",$from_n->word_num," words, ",$from_n->size," bytes)\n"; my $doc_num = $from_n->doc_num || 1; -my $res; my $prev; -my $i = 1; +my $i = 0; +my $more = 1; my $t = time(); -do { +while($more) { + my $res; $from_n->shuttle_url( $from_n->{url} . '/list', 'application/x-www-form-urlencoded', - 'max=256' . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ), + 'max=' . $max . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ), \$res, ); - last unless ($res); + if (! $res || $res eq '') { + $more = 0; + last; + } foreach my $l (split(/\n/,$res)) { (my $id, $prev) = split(/\t/,$l, 2); - $to_n->put_doc( $from_n->get_doc( $id )); + + #$to_n->put_doc( $from_n->get_doc( $id )); + + my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 ); + $to_n->shuttle_url( $to_n->{url} . '/put_doc', 'text/x-estraier-draft', $doc_draft, undef) == 200 or die "can't insert $doc_draft\n"; + $i++; } warn "$prev\n"; @@ -62,5 +86,7 @@ strftime("%Y-%m-%d %H:%M:%S", localtime( time() + int(($doc_num-$i) / $rate))), ); -} while ($res); +} + +print "Copy completed.\n";