]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-xcpdb
xcpdb: wire up new index options and --help
[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 $usage = 'Usage: public-inbox-xcpdb [options] INBOX_DIR';
8 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
9 usage: $usage
10
11   upgrade or reshard Xapian DB(s) used by public-inbox
12
13 options:
14
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
21
22 index options (see public-inbox-index(1) man page for full description):
23
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
27
28 See public-inbox-xcpdb(1) man page for full documentation.
29 EOF
30 my $opt = { quiet => -1, compact => 0, fsync => 1 };
31 GetOptions($opt, qw(
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 };
39
40 use PublicInbox::Admin;
41 PublicInbox::Admin::require_or_die('-search');
42
43 require PublicInbox::Config;
44 my $cfg = PublicInbox::Config->new;
45 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, undef, $cfg) or
46         die $usage;
47 my $idx_env = PublicInbox::Admin::index_prepare($opt, $cfg);
48
49 # we only set XAPIAN_FLUSH_THRESHOLD for index, since cpdb doesn't
50 # know sizes, only doccounts
51 $opt->{-idx_env} = $idx_env;
52
53 if ($opt->{sequential_shard} && ($opt->{jobs} // 1) > 1) {
54         warn "W: --jobs=$opt->{jobs} ignored with --sequential-shard\n";
55         $opt->{jobs} = 0;
56 }
57
58 require PublicInbox::InboxWritable;
59 require PublicInbox::Xapcmd;
60 foreach (@ibxs) {
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);
64 }