/[Search-Estraier]/trunk/scripts/estcp.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/scripts/estcp.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 80 by dpavlin, Mon Jan 16 23:08:07 2006 UTC revision 84 by dpavlin, Tue Jan 17 11:43:38 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use Search::Estraier;  use Search::Estraier;
5  use URI::Escape qw/uri_escape/;  use URI::Escape qw/uri_escape/;
6    use Time::HiRes;
7    use POSIX qw/strftime/;
8    
9  =head1 NAME  =head1 NAME
10    
# Line 15  my ($from,$to) = @ARGV; Line 17  my ($from,$to) = @ARGV;
17  die "usage: $0 http://localhost:1978/node/from http://remote.example.com:1978/node/to\n" unless ($from && $to);  die "usage: $0 http://localhost:1978/node/from http://remote.example.com:1978/node/to\n" unless ($from && $to);
18    
19  my $debug = 0;  my $debug = 0;
20    my $max = 256;
21    
22  # create and configure node  # create and configure node
23  my $from_n = new Search::Estraier::Node(  my $from_n = new Search::Estraier::Node(
# Line 30  my $to_n = new Search::Estraier::Node( Line 33  my $to_n = new Search::Estraier::Node(
33    
34  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";  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";
35    
36  my $tick = int($from_n->doc_num / 78);  my $doc_num = $from_n->doc_num || 1;
37    
 print "[";  
 my $res;  
38  my $prev;  my $prev;
39  my $i = 0;  my $i = 0;
40    my $more = 1;
41    
42  do {  my $t = time();
43    
44    while($more) {
45            my $res;
46          $from_n->shuttle_url( $from_n->{url} . '/list',          $from_n->shuttle_url( $from_n->{url} . '/list',
47                  'application/x-www-form-urlencoded',                  'application/x-www-form-urlencoded',
48                  'max=256' . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ),                  'max=' . $max . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ),
49                  \$res,                  \$res,
50          );          );
51          last unless ($res);          if (! $res || $res eq '') {
52                    $more = 0;
53                    last;
54            }
55          foreach my $l (split(/\n/,$res)) {          foreach my $l (split(/\n/,$res)) {
56                  (my $id, $prev) = split(/\t/,$l, 2);                  (my $id, $prev) = split(/\t/,$l, 2);
57                  $to_n->put_doc( $from_n->get_doc( $id ));  
58                    #$to_n->put_doc( $from_n->get_doc( $id ));
59    
60                    my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );
61                    $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";
62    
63                    $i++;
64          }          }
65          print "$prev\n";          warn "$prev\n";
66          print "." if ($i++ % $tick == 0);  
67  } while ($res);          my $rate = ( $i / (time() - $t) );
68            printf("%d records, %1.2f%% [%1.2f rec/s] estimated finish: %s\n",
69                    $i,
70                    ($i * 100 / $doc_num),
71                    $rate,
72                    strftime("%Y-%m-%d %H:%M:%S", localtime( time() + int(($doc_num-$i) / $rate))),
73            );
74    
75    }
76    
77    print "Copy completed.\n";
78    
 print "]\n";  

Legend:
Removed from v.80  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26