2121my $size = 1000;
2222my $index = " cpan" ;
2323
24- my ( $type , $purge , $dry_run , $restore );
24+ my ( $dry_run , $mode , $purge , $restore );
2525GetOptions(
2626 " batch_size=i" => \$batch_size ,
27- " purge" => \$purge ,
2827 " dry_run" => \$dry_run ,
29- " size=i" => \$size ,
3028 " index=s" => \$index ,
31- " type=s" => \$type ,
29+ " mode=s" => \$mode ,
30+ " purge" => \$purge ,
3231 " restore=s" => \$restore ,
32+ " size=i" => \$size ,
3333);
34+ # TODO: find a better way
35+ my @es_mode = ( $mode ? mode => $mode : () );
36+ $mode eq ' test' and Log::Log4perl::init(' log4perl_test.conf' );
3437
3538# setup
3639my $home = home();
6972 };
7073
7174 # Create our bulk_helper if we need,
72- # incase a backup has mixed _index or _type
75+ # incase a backup has mixed _index
7376 # create a new bulk helper for each
74- my $key = $raw -> {_index } . $raw -> { _type } ;
77+ my $key = $raw -> {_index };
7578
76- $es_store {$key } ||= MetaCPAN::ES-> new(
77- index => $raw -> {_index },
78- type => $raw -> {_type },
79- );
79+ $es_store {$key } ||= MetaCPAN::ES-> new( index => $key , @es_mode );
8080 my $es = $es_store {$key };
8181
8282 $bulk_store {$key } ||= $es -> bulk( max_count => $batch_size );
8383 my $bulk = $bulk_store {$key };
8484
8585 my $parent = $raw -> {_parent };
8686
87- if ( $raw -> { _type } eq ' author' ) {
87+ if ( $key eq ' author' ) {
8888
8989 # Hack for dodgy lat / lon's
9090 if ( my $loc = $raw -> {_source }{location } ) {
158158sub run_backup {
159159 my $filename = join ( ' -' ,
160160 DateTime-> now-> strftime(' %F' ),
161- grep {defined } $index , $type );
161+ grep {defined } $index );
162162
163163 my $file = $home -> child( qw< var backup > , " $filename .json.gz" );
164164 $file -> parent-> mkpath unless ( -e $file -> parent );
165165 my $fh = IO::Zlib-> new( " $file " , ' wb4' );
166166
167- my $es = MetaCPAN::ES-> new(
168- index => $index ,
169- ( $type ? ( type => $type ) : () )
170- );
167+ my $es = MetaCPAN::ES-> new( index => $index , @es_mode );
171168 my $scroll = $es -> scroll(
172169 scroll => ' 1m' ,
173170 body => {
@@ -191,11 +188,11 @@ sub run_backup {
191188
192189=head1 NAME
193190
194- Backup indices and types
191+ Backup indices
195192
196193=head1 SYNOPSIS
197194
198- $ bin/backup --index user --type account
195+ $ bin/backup --index author
199196
200197 $ bin/backup --purge
201198
0 commit comments