3 # http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
11 use Data::Dump qw(dump);
12 use Time::HiRes qw(time);
13 use File::Path qw(make_path remove_tree);
16 my $name = shift @ARGV || 'pxelator';
18 my $conn = MongoDB::Connection->new;
19 my $db = $conn->get_database( $name );
20 my $audit = $db->get_collection("audit");
23 IO::Socket::INET->new(
24 PeerAddr => '10.60.0.91',
37 # warn "# $sock\n$chunk\n";
41 my $sock = couchdb_socket;
43 print $sock "GET /$name/_all_docs?include_docs=true HTTP/1.0\r\n\r\n";
48 $total =~ s{^.*total_rows\D+(\d+).+$}{$1};
51 print "# $name total: $total\n";
58 if ( /"id":"([^"]+)"/ ) {
60 s/,[\r\n]+$//; # cleanup JSON
61 my $json = from_json( $_ );
62 $audit->insert( $json->{doc} );
63 printf " %d/%d %.2f%% %.2f/s\r", $count, $total
64 , ( $count / $total ) * 100
65 , ( $count / ( time() - $start_t ) )
66 if ++$count % 1000 == 0;