Skip to content

Commit befd528

Browse files
committed
backup - remove type
1 parent 4e8a29b commit befd528

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

bin/backup.pl

+15-18
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121
my $size = 1000;
2222
my $index = "cpan";
2323

24-
my ( $type, $purge, $dry_run, $restore );
24+
my ( $dry_run, $mode, $purge, $restore );
2525
GetOptions(
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
3639
my $home = home();
@@ -69,22 +72,19 @@ ()
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} ) {
@@ -158,16 +158,13 @@ ()
158158
sub 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

Comments
 (0)