]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-xcpdb
script/*: fold $usage into $help, support `-h' instead of -?
[public-inbox.git] / script / public-inbox-xcpdb
1 #!perl -w
2 # Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
7 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
8 usage: public-inbox-xcpdb [options] INBOX_DIR
9
10   upgrade or reshard Xapian DB(s) used by public-inbox
11
12 options:
13
14   --compact | -c      run public-inbox-compact(1) after indexing
15   --all               copy all configured inboxes
16   --reshard=NUM       change number the number of shards
17   --jobs=NUM          limit parallelism to JOBS count
18   --verbose | -v      increase verbosity (may be repeated)
19   --sequential-shard  copy+index Xapian shards sequentially (for slow HDD)
20
21 index options (see public-inbox-index(1) man page for full description):
22
23   --no-fsync          speed up indexing, risk corruption on power outage
24   --batch-size=BYTES  flush changes to OS after a given number of bytes
25   --max-size=BYTES    do not index messages larger than the given size
26
27 See public-inbox-xcpdb(1) man page for full documentation.
28 EOF
29 my $opt = { quiet => -1, compact => 0, fsync => 1 };
30 GetOptions($opt, qw(
31         fsync|sync! compact|c reshard|R=i
32         max_size|max-size=s batch_size|batch-size=s
33         sequential_shard|seq-shard|sequential-shard
34         jobs|j=i quiet|q verbose|v
35         blocksize|b=s no-full|n fuller|F
36         all help|h)) or die $help;
37 if ($opt->{help}) { print $help; exit 0 };
38
39 use PublicInbox::Admin;
40 PublicInbox::Admin::require_or_die('-search');
41
42 require PublicInbox::Config;
43 my $cfg = PublicInbox::Config->new;
44 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg) or
45         die $help;
46 my $idx_env = PublicInbox::Admin::index_prepare($opt, $cfg);
47
48 # we only set XAPIAN_FLUSH_THRESHOLD for index, since cpdb doesn't
49 # know sizes, only doccounts
50 $opt->{-idx_env} = $idx_env;
51
52 if ($opt->{sequential_shard} && ($opt->{jobs} // 1) > 1) {
53         warn "W: --jobs=$opt->{jobs} ignored with --sequential-shard\n";
54         $opt->{jobs} = 0;
55 }
56
57 require PublicInbox::InboxWritable;
58 require PublicInbox::Xapcmd;
59 foreach (@ibxs) {
60         my $ibx = PublicInbox::InboxWritable->new($_);
61         # we rely on --no-renumber to keep docids synched for NNTP
62         PublicInbox::Xapcmd::run($ibx, 'cpdb', $opt);
63 }