]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-xcpdb
index|compact|xcpdb: support --all switch
[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   --all               copy all configured inboxes
17   --reshard=NUM       change number the number of shards
18   --jobs=NUM          limit parallelism to JOBS count
19   --verbose | -v      increase verbosity (may be repeated)
20   --sequential-shard  copy+index Xapian shards sequentially (for slow HDD)
21   --help | -?         show this help
22
23 index options (see public-inbox-index(1) man page for full description):
24
25   --no-fsync          speed up indexing, risk corruption on power outage
26   --batch-size=BYTES  flush changes to OS after a given number of bytes
27   --max-size=BYTES    do not index messages larger than the given size
28
29 See public-inbox-xcpdb(1) man page for full documentation.
30 EOF
31 my $opt = { quiet => -1, compact => 0, fsync => 1 };
32 GetOptions($opt, qw(
33         fsync|sync! compact|c reshard|R=i
34         max_size|max-size=s batch_size|batch-size=s
35         sequential_shard|seq-shard|sequential-shard
36         jobs|j=i quiet|q verbose|v
37         blocksize|b=s no-full|n fuller|F
38         all help|?)) or die "bad command-line args\n$usage";
39 if ($opt->{help}) { print $help; exit 0 };
40
41 use PublicInbox::Admin;
42 PublicInbox::Admin::require_or_die('-search');
43
44 require PublicInbox::Config;
45 my $cfg = PublicInbox::Config->new;
46 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg) or
47         die $usage;
48 my $idx_env = PublicInbox::Admin::index_prepare($opt, $cfg);
49
50 # we only set XAPIAN_FLUSH_THRESHOLD for index, since cpdb doesn't
51 # know sizes, only doccounts
52 $opt->{-idx_env} = $idx_env;
53
54 if ($opt->{sequential_shard} && ($opt->{jobs} // 1) > 1) {
55         warn "W: --jobs=$opt->{jobs} ignored with --sequential-shard\n";
56         $opt->{jobs} = 0;
57 }
58
59 require PublicInbox::InboxWritable;
60 require PublicInbox::Xapcmd;
61 foreach (@ibxs) {
62         my $ibx = PublicInbox::InboxWritable->new($_);
63         # we rely on --no-renumber to keep docids synched for NNTP
64         PublicInbox::Xapcmd::run($ibx, 'cpdb', $opt);
65 }