]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-xcpdb
No ext_urls
[public-inbox.git] / script / public-inbox-xcpdb
1 #!perl -w
2 # Copyright (C) 2019-2021 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|EXTINDEX_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, -eidx_ok => 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
34         jobs|j=i quiet|q verbose|v
35         blocksize|b=s no-full|n fuller|F
36         all C=s@ 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 PublicInbox::Admin::do_chdir(delete $opt->{C});
42
43 require PublicInbox::Config;
44 my $cfg = PublicInbox::Config->new;
45 my ($ibxs, $eidxs) = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
46 unless ($ibxs) { print STDERR $help; exit 1 }
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 # we rely on --no-renumber to keep docids synched for NNTP(artnum) + IMAP(UID)
61 for my $ibx (@$ibxs) {
62         $ibx = PublicInbox::InboxWritable->new($ibx);
63         PublicInbox::Xapcmd::run($ibx, 'cpdb', $opt);
64 }
65
66 for my $eidx (@$eidxs) {
67         PublicInbox::Xapcmd::run($eidx, 'cpdb', $opt);
68 }