21
21
my $size = 1000;
22
22
my $index = " cpan" ;
23
23
24
- my ( $type , $purge , $dry_run , $restore );
24
+ my ( $dry_run , $mode , $purge , $restore );
25
25
GetOptions(
26
26
" batch_size=i" => \$batch_size ,
27
- " purge" => \$purge ,
28
27
" dry_run" => \$dry_run ,
29
- " size=i" => \$size ,
30
28
" index=s" => \$index ,
31
- " type=s" => \$type ,
29
+ " mode=s" => \$mode ,
30
+ " purge" => \$purge ,
32
31
" restore=s" => \$restore ,
32
+ " size=i" => \$size ,
33
33
);
34
+ # TODO: find a better way
35
+ my @es_mode = ( $mode ? mode => $mode : () );
36
+ $mode eq ' test' and Log::Log4perl::init(' log4perl_test.conf' );
34
37
35
38
# setup
36
39
my $home = home();
69
72
};
70
73
71
74
# Create our bulk_helper if we need,
72
- # incase a backup has mixed _index or _type
75
+ # incase a backup has mixed _index
73
76
# create a new bulk helper for each
74
- my $key = $raw -> {_index } . $raw -> { _type } ;
77
+ my $key = $raw -> {_index };
75
78
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 );
80
80
my $es = $es_store {$key };
81
81
82
82
$bulk_store {$key } ||= $es -> bulk( max_count => $batch_size );
83
83
my $bulk = $bulk_store {$key };
84
84
85
85
my $parent = $raw -> {_parent };
86
86
87
- if ( $raw -> { _type } eq ' author' ) {
87
+ if ( $key eq ' author' ) {
88
88
89
89
# Hack for dodgy lat / lon's
90
90
if ( my $loc = $raw -> {_source }{location } ) {
158
158
sub run_backup {
159
159
my $filename = join ( ' -' ,
160
160
DateTime-> now-> strftime(' %F' ),
161
- grep {defined } $index , $type );
161
+ grep {defined } $index );
162
162
163
163
my $file = $home -> child( qw< var backup > , " $filename .json.gz" );
164
164
$file -> parent-> mkpath unless ( -e $file -> parent );
165
165
my $fh = IO::Zlib-> new( " $file " , ' wb4' );
166
166
167
- my $es = MetaCPAN::ES-> new(
168
- index => $index ,
169
- ( $type ? ( type => $type ) : () )
170
- );
167
+ my $es = MetaCPAN::ES-> new( index => $index , @es_mode );
171
168
my $scroll = $es -> scroll(
172
169
scroll => ' 1m' ,
173
170
body => {
@@ -191,11 +188,11 @@ sub run_backup {
191
188
192
189
=head1 NAME
193
190
194
- Backup indices and types
191
+ Backup indices
195
192
196
193
=head1 SYNOPSIS
197
194
198
- $ bin/backup --index user --type account
195
+ $ bin/backup --index author
199
196
200
197
$ bin/backup --purge
201
198
0 commit comments