/[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 82 by dpavlin, Tue Jan 17 00:17:50 2006 UTC revision 133 by dpavlin, Mon May 8 21:34:00 2006 UTC
# Line 17  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(
24          url => $from,          url => $from,
25          croak_on_error => 1,          croak_on_error => 1,
26          debug => $debug,          debug => $debug,
27            user => 'admin',
28            passwd => 'admin',
29  );  );
30  my $to_n = new Search::Estraier::Node(  my $to_n = new Search::Estraier::Node(
31          url => $to,          url => $to,
32          croak_on_error => 1,          croak_on_error => 1,
33          debug => $debug,          debug => $debug,
34            user => 'admin',
35            passwd => 'admin',
36  );  );
37    
38    unless(eval{ $to_n->name }) {
39            if ($to =~ m#^(http://.+)/node/([^/]+)$#) {
40                    my ($url,$name) = ($1,$2);
41                    print "Creating '$name' on $url\n";
42                    $to_n->shuttle_url( $url . '/master?action=nodeadd',
43                            'application/x-www-form-urlencoded',
44                            'name=' . uri_escape($name) . '&label=' . uri_escape( $name ),
45                            undef,
46                    );
47            } else {
48                    die "can't extract node name from $to\n";
49            }
50    }
51    
52  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";
53    
54  my $doc_num = $from_n->doc_num || 1;  my $doc_num = $from_n->doc_num || 1;
55    
 my $res;  
56  my $prev;  my $prev;
57  my $i = 1;  my $i = 0;
58    my $more = 1;
59    
60  my $t = time();  my $t = time();
61    
62  do {  while($more) {
63            my $res;
64          $from_n->shuttle_url( $from_n->{url} . '/list',          $from_n->shuttle_url( $from_n->{url} . '/list',
65                  'application/x-www-form-urlencoded',                  'application/x-www-form-urlencoded',
66                  'max=256' . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ),                  'max=' . $max . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ),
67                  \$res,                  \$res,
68          );          );
69          last unless ($res);          if (! $res || $res eq '') {
70                    $more = 0;
71                    last;
72            }
73          foreach my $l (split(/\n/,$res)) {          foreach my $l (split(/\n/,$res)) {
74                  (my $id, $prev) = split(/\t/,$l, 2);                  (my $id, $prev) = split(/\t/,$l, 2);
75                  $to_n->put_doc( $from_n->get_doc( $id ));  
76                    #$to_n->put_doc( $from_n->get_doc( $id ));
77    
78                    my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 );
79                    $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";
80    
81                  $i++;                  $i++;
82          }          }
83          warn "$prev\n";          warn "$prev\n" if ($debug);
84    
85          my $rate = ( $i / (time() - $t) );          my $rate = ( $i / (time() - $t) );
86          printf("%d records, %1.2f%% [%1.2f rec/s] estimated finish: %s\n",          printf("%d records, %1.2f%% [%1.2f rec/s] estimated finish: %s\n",
# Line 62  do { Line 90  do {
90                  strftime("%Y-%m-%d %H:%M:%S", localtime( time() + int(($doc_num-$i) / $rate))),                  strftime("%Y-%m-%d %H:%M:%S", localtime( time() + int(($doc_num-$i) / $rate))),
91          );          );
92    
93  } while ($res);  }
94    
95    print "Copy completed.\n";
96    

Legend:
Removed from v.82  
changed lines
  Added in v.133

  ViewVC Help
Powered by ViewVC 1.1.26