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 $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
8 usage: public-inbox-xcpdb [options] INBOX_DIR
10 upgrade or reshard Xapian DB(s) used by public-inbox
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)
21 index options (see public-inbox-index(1) man page for full description):
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
27 See public-inbox-xcpdb(1) man page for full documentation.
29 my $opt = { quiet => -1, compact => 0, fsync => 1 };
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 };
39 use PublicInbox::Admin;
40 PublicInbox::Admin::require_or_die('-search');
42 require PublicInbox::Config;
43 my $cfg = PublicInbox::Config->new;
44 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg) or
46 my $idx_env = PublicInbox::Admin::index_prepare($opt, $cfg);
48 # we only set XAPIAN_FLUSH_THRESHOLD for index, since cpdb doesn't
49 # know sizes, only doccounts
50 $opt->{-idx_env} = $idx_env;
52 if ($opt->{sequential_shard} && ($opt->{jobs} // 1) > 1) {
53 warn "W: --jobs=$opt->{jobs} ignored with --sequential-shard\n";
57 require PublicInbox::InboxWritable;
58 require PublicInbox::Xapcmd;
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);