remove messages from CRON
[pxelator] / bin / couchdb2mongodb.pl
index 6d9420e..f54f554 100755 (executable)
@@ -13,7 +13,7 @@ use Time::HiRes qw(time);
 use File::Path qw(make_path remove_tree);
 use MongoDB;
 
-my $name = 'pxelator';
+my $name = shift @ARGV || 'pxelator';
 
 my $conn = MongoDB::Connection->new;
 my $db = $conn->get_database( $name );
@@ -46,7 +46,13 @@ get_chunk($sock);
 
 my $total = <$sock>;
 $total =~ s{^.*total_rows\D+(\d+).+$}{$1};
-warn "# total: $total\n";
+
+$|=1;
+print "# $name total: $total\n";
+
+my $start_t = time();
+my $count = 0;
+
 
 while(<$sock>) {
        if ( /"id":"([^"]+)"/ ) {
@@ -54,7 +60,10 @@ while(<$sock>) {
                s/,[\r\n]+$//; # cleanup JSON
                my $json = from_json( $_ );
                $audit->insert( $json->{doc} );
-               print STDERR ".";
+               printf " %d/%d %.2f%% %.2f/s\r", $count, $total
+                       , ( $count / $total ) * 100
+                       , ( $count / ( time() - $start_t ) )
+                       if ++$count % 1000 == 0;
        } else {
                warn "UNKNOWN: $_";
        }