]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-compact
No ext_urls
[public-inbox.git] / script / public-inbox-compact
1 #!perl -w
2 # Copyright (C) 2018-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 $opt = { compact => 1, -coarse_lock => 1, -eidx_ok => 1 };
8 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
9 usage: public-inbox-compact <INBOX_DIR|EXTINDEX_DIR>
10
11   Compact Xapian DBs in an inbox
12
13 options:
14
15   --all               index all configured inboxes
16   --jobs=NUM          control parallelization
17
18 See public-inbox-compact(1) man page for full documentation.
19 EOF
20 GetOptions($opt, qw(all C=s@ help|h),
21         # compact options:
22         qw(jobs|j=i quiet|q blocksize|b=s no-full|n fuller|F),
23 ) or die $help;
24 if ($opt->{help}) { print $help; exit 0 };
25
26 require PublicInbox::Admin;
27 PublicInbox::Admin::require_or_die('-index');
28 PublicInbox::Admin::do_chdir(delete $opt->{C});
29 PublicInbox::Admin::progress_prepare($opt);
30
31 require PublicInbox::InboxWritable;
32 require PublicInbox::Xapcmd;
33 my $cfg = PublicInbox::Config->new;
34 my ($ibxs, $eidxs) = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
35 unless ($ibxs) { print STDERR $help; exit 1 }
36 for my $ibx (@$ibxs) {
37         $ibx = PublicInbox::InboxWritable->new($ibx);
38         PublicInbox::Xapcmd::run($ibx, 'compact', $opt);
39 }
40 for my $eidx (@$eidxs) {
41         PublicInbox::Xapcmd::run($eidx, 'compact', $opt);
42 }