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>
6 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
7 my $usage = 'Usage: public-inbox-xcpdb [options] INBOX_DIR';
8 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
11 upgrade or reshard Xapian DB(s) used by public-inbox
15 --compact | -c run public-inbox-compact(1) after indexing
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 --help | -? show this help
22 index options (see public-inbox-index(1) man page for full description):
24 --no-fsync speed up indexing, risk corruption on power outage
25 --batch-size=BYTES flush changes to OS after a given number of bytes
26 --max-size=BYTES do not index messages larger than the given size
28 See public-inbox-xcpdb(1) man page for full documentation.
30 my $opt = { quiet => -1, compact => 0, fsync => 1 };
32 fsync|sync! compact|c reshard|R=i
33 max_size|max-size=s batch_size|batch-size=s
34 sequential_shard|seq-shard|sequential-shard
35 jobs|j=i quiet|q verbose|v
36 blocksize|b=s no-full|n fuller|F
37 help|?)) or die "bad command-line args\n$usage";
38 if ($opt->{help}) { print $help; exit 0 };
40 use PublicInbox::Admin;
41 PublicInbox::Admin::require_or_die('-search');
43 require PublicInbox::Config;
44 my $cfg = PublicInbox::Config->new;
45 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, undef, $cfg) or
47 my $idx_env = PublicInbox::Admin::index_prepare($opt, $cfg);
49 # we only set XAPIAN_FLUSH_THRESHOLD for index, since cpdb doesn't
50 # know sizes, only doccounts
51 $opt->{-idx_env} = $idx_env;
53 if ($opt->{sequential_shard} && ($opt->{jobs} // 1) > 1) {
54 warn "W: --jobs=$opt->{jobs} ignored with --sequential-shard\n";
58 require PublicInbox::InboxWritable;
59 require PublicInbox::Xapcmd;
61 my $ibx = PublicInbox::InboxWritable->new($_);
62 # we rely on --no-renumber to keep docids synched for NNTP
63 PublicInbox::Xapcmd::run($ibx, 'cpdb', $opt);