|
2 | 2 | use warnings;
|
3 | 3 | use v5.36;
|
4 | 4 |
|
5 |
| -use Cpanel::JSON::XS qw< decode_json encode_json >; |
| 5 | +use Cpanel::JSON::XS qw< decode_json encode_json >; |
6 | 6 | use DateTime ();
|
7 | 7 | use DateTime::Format::ISO8601 ();
|
8 | 8 | use HTTP::Tiny ();
|
9 | 9 | use Getopt::Long;
|
10 | 10 | use Sys::Hostname qw< hostname >;
|
| 11 | +use Try::Tiny; |
11 | 12 |
|
12 | 13 | use MetaCPAN::Logger qw< :log :dlog >;
|
13 | 14 |
|
14 | 15 | use MetaCPAN::ES;
|
15 |
| -use MetaCPAN::Ingest qw< are_you_sure >; |
| 16 | +use MetaCPAN::Ingest qw< |
| 17 | + are_you_sure |
| 18 | + config |
| 19 | + is_dev |
| 20 | +>; |
16 | 21 |
|
17 | 22 | # setup
|
18 |
| -my $hostname = hostname(); |
19 |
| -my $mode = $hostname =~ /dev/ ? 'testing' : 'production'; |
| 23 | +my $config = config(); |
| 24 | +my $mode = is_dev() ? 'testing' : 'production'; |
20 | 25 | my $bucket = "mc-${mode}-backups"; # So we don't break production
|
21 | 26 | my $repository_name = 'our_backups';
|
22 | 27 |
|
23 |
| -#my $es = MetaCPAN::ES->new( type => "distribution" ); |
24 |
| -#my $bulk = $es->bulk(); |
| 28 | +my $aws_key = $config->{es_aws_s3_access_key}; |
| 29 | +die "es_aws_s3_access_key not in config" unless $aws_key; |
| 30 | + |
| 31 | +my $aws_secret = $config->{es_aws_s3_secret}; |
| 32 | +die "es_aws_s3_secret not in config" unless $aws_secret; |
| 33 | + |
| 34 | +my $http_client = HTTP::Tiny->new( |
| 35 | + default_headers => { 'Accept' => 'application/json' }, |
| 36 | + timeout => 120, # list can be slow |
| 37 | +); |
25 | 38 |
|
26 | 39 | # args
|
27 | 40 | my (
|
28 | 41 | $date_format, $indices, $list, $purge_old, $restore,
|
29 | 42 | $setup, $snap, $snap_name, $snap_stub
|
30 | 43 | );
|
31 |
| -my $host = MetaCPAN::Server::Config::config()->{elasticsearch_servers}; |
| 44 | + |
| 45 | +my $host = $config->{es_node}; |
| 46 | + |
32 | 47 | GetOptions(
|
33 | 48 | "list" => \$list,
|
34 | 49 | "date_format=s" => \$date_format,
|
|
45 | 60 | # Note: can take wild cards https://www.elastic.co/guide/en/elasticsearch/reference/2.4/multi-index.html
|
46 | 61 | $indices //= '*';
|
47 | 62 |
|
48 |
| -my $config = {}; ## TODO ( use MetaCPAN::Server::Config (); ??? ) |
49 |
| - |
50 |
| -my $aws_key = $config->{es_aws_s3_access_key}; |
51 |
| -my $aws_secret = $config->{es_aws_s3_secret}; |
52 |
| - |
53 |
| -my $http_client = HTTP::Tiny->new( |
54 |
| - default_headers => { 'Accept' => 'application/json' }, |
55 |
| - timeout => 120, # list can be slow |
56 |
| -); |
57 |
| - |
58 | 63 | # run
|
59 |
| -die "es_aws_s3_access_key not in config" unless $aws_key; |
60 |
| -die "es_aws_s3_secret not in config" unless $aws_secret; |
61 |
| - |
62 | 64 | run_list_snaps() if $list;
|
63 | 65 | run_setup() if $setup;
|
64 | 66 | run_snapshot() if $snap;
|
@@ -205,7 +207,7 @@ ( $method, $path, $data )
|
205 | 207 | Dlog_error {"Error response: $_"} $resp_json;
|
206 | 208 | }
|
207 | 209 | catch {
|
208 |
| - log_error { 'Error msg: ' . $response->{content} } |
| 210 | + log_error { 'Error msg: ' . $response->{content} }; |
209 | 211 | }
|
210 | 212 | return 0;
|
211 | 213 | }
|
|
0 commit comments