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( |
31 |
debug => $debug, |
debug => $debug, |
32 |
); |
); |
33 |
|
|
34 |
|
unless(eval{ $to_n->name }) { |
35 |
|
if ($to =~ m#^(http://.+)/node/(\w+)$#) { |
36 |
|
my ($url,$name) = ($1,$2); |
37 |
|
print "Creating '$name' on $url\n"; |
38 |
|
$to_n->shuttle_url( $url . '/master?action=nodeadd', |
39 |
|
'application/x-www-form-urlencoded', |
40 |
|
'name=' . uri_escape($name) . '&label=' . uri_escape( $name ), |
41 |
|
undef, |
42 |
|
); |
43 |
|
} else { |
44 |
|
die "can't extract node name from $to\n"; |
45 |
|
} |
46 |
|
} |
47 |
|
|
48 |
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"; |
49 |
|
|
50 |
my $doc_num = $from_n->doc_num || 1; |
my $doc_num = $from_n->doc_num || 1; |
51 |
|
|
|
my $res; |
|
52 |
my $prev; |
my $prev; |
53 |
my $i = 1; |
my $i = 0; |
54 |
|
my $more = 1; |
55 |
|
|
56 |
my $t = time(); |
my $t = time(); |
57 |
|
|
58 |
do { |
while($more) { |
59 |
|
my $res; |
60 |
$from_n->shuttle_url( $from_n->{url} . '/list', |
$from_n->shuttle_url( $from_n->{url} . '/list', |
61 |
'application/x-www-form-urlencoded', |
'application/x-www-form-urlencoded', |
62 |
'max=256' . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ), |
'max=' . $max . ( $prev ? '&prev=' . uri_escape( $prev ) : '' ), |
63 |
\$res, |
\$res, |
64 |
); |
); |
65 |
last unless ($res); |
if (! $res || $res eq '') { |
66 |
|
$more = 0; |
67 |
|
last; |
68 |
|
} |
69 |
foreach my $l (split(/\n/,$res)) { |
foreach my $l (split(/\n/,$res)) { |
70 |
(my $id, $prev) = split(/\t/,$l, 2); |
(my $id, $prev) = split(/\t/,$l, 2); |
71 |
$to_n->put_doc( $from_n->get_doc( $id )); |
|
72 |
|
#$to_n->put_doc( $from_n->get_doc( $id )); |
73 |
|
|
74 |
|
my $doc_draft = $from_n->_fetch_doc( id => $id, chomp_resbody => 1 ); |
75 |
|
$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"; |
76 |
|
|
77 |
$i++; |
$i++; |
78 |
} |
} |
79 |
warn "$prev\n"; |
warn "$prev\n"; |
86 |
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))), |
87 |
); |
); |
88 |
|
|
89 |
} while ($res); |
} |
90 |
|
|
91 |
|
print "Copy completed.\n"; |
92 |
|
|