=head1 NAME

tdx-util - Tradindexed overview manipulation utility

=head1 SYNOPSIS

B<tdx-util> [B<-AFcgiOo>] [B<-a> I<article>] [B<-f> I<status>]
[B<-n> I<newsgroup>] [B<-p> I<path>] [B<-R> I<path>]

=head1 DESCRIPTION

B<tdx-util> is an administrative interface to the tradindexed overview
method for INN.  It only works on tradindexed overview databases, not on
any other type of INN overview.  It allows the administrator to dump
various information about the internal state of the overview, audit it for
errors, and rebuild portions of the overview database.

The tradindexed overview method should lock properly and therefore it
should be safe to run this utility and perform any operation it performs,
including full repairs or per-group overview rebuilds, while the server is
running.  However, note that some of the operations performed by this
utility can take an extended period of time and will hold locks in the
overview database during that period, which depending on what the server
is doing may cause the server to stall until B<tdx-util> completes its
operation.

The dump operations are B<-i>, which dumps the master index for the
overview database, B<-g>, which dumps the index for an individual group,
and B<-o> and B<-O>, which dump the overview information for a particular
group (including the additional metadata stored in the index) in two
different formats.  For B<-g>, B<-o>, and B<-O>, the B<-n> option must
also be given to specify a newsgroup to operate on.

To add a new newsgroup to the overview database, use B<-c>.  A group must
be specified with B<-n>.  If the group status is something other than C<y>,
it should be specified with B<-f>, and the low and high article numbers
may be specified with B<-a>.  If only one number is given rather than a
range, it will be taken to be the high water mark and the low mark will be
set to 1.

To audit the entire overview database for problems, use B<-A>.  Any
problems found will be reported to standard error.  Use B<-F> to correct
the errors found.

To rebuild the database for a particular newsgroup, use B<-R>.  The B<-R>
option takes a path to a directory which contains all of the articles for
that newsgroup, one per file.  The names of the files must be the numbers
of the articles in that group.  (In other words, this directory must be a
traditional spool directory for that group.)  The B<-n> option must also
be given to specify the newsgroup for which the overview is being rebuilt.

For all operations performed by B<tdx-util>, a different overview database
than the one specified in F<inn.conf> may be specified using the B<-p>
option.

=head1 OPTIONS

=over 4

=item B<-A>

Audit the entire overview database for problems.  This runs the internal
consistency checks built into the tradindexed overview implementation,
checking such things as the validity and reachability of all group index
entries, the format of the individual overview entries, the correspondence
of index entries to overview data, and similar such things.  No changes
will be made to the database, but problems will be reported to standard
error.

=item B<-a> I<article>

The article number or numbers to act on.  I<article> is a valid NNTP
range, meaning that it can be either a single article number or a range of
article numbers (like C<1-5>).  Either the start or the end (or both) of
the range may be omitted, in which case they will be set to the first or
last article number in the group.  Passing C<-> for I<article> is
therefore equivalent to not using the B<-a> option at all.

Only useful in combination with the B<-o> option to dump overview
information or with B<-c> to specify the low and high article numbers when
creating a group.

=item B<-c>

Create a new group in the overview database.  The group must be specified
with B<-n>.  The newsgroup status defaults to C<y> but may be set with
B<-f>.  The low and high article numbers default to 1 and 0 respectively,
but may be set with B<-a>.  If only one number is given to B<-a>, it is
taken as the high article number.

=item B<-F>

Audit the entire overview database for problems, fixing them as they're
detected where possible.  This runs the internal consistency checks built
into the tradindexed overview implementation, checking such things as the
validity and reachability of all group index entries, the format of the
individual overview entries, the correspondence of index entries to
overview data, and similar such things.  The strategy used when fixing
problems is to throw away data that's unrecoverable, so be warned that
using this option may result in inaccessible articles if their overview
data has been corrupted.

To see what would be changed by B<-F>, run B<tdx-util> with B<-A> first.

=item B<-f> I<status>

When creating a newsgroup with B<-c>, set the status of the newly created
group to I<status> instead of C<y>.  Only useful with B<-c>.

=item B<-g>

Dump the index of a particular group.  The fields are, in order, the
article number, the offset of the data for that article in the overview
data file for that group, the length of the overview data, the time (in
seconds since epoch) when the article arrived on the server, the time (in
seconds since epoch) when the article should expire based on its Expires
header field (or 0 if there is no Expires header field), and the storage API
token of the article.

If this option is given, the B<-n> option must also be given to specify
the newsgroup on which to act.

=item B<-i>

Dump the master index of the overview database.  This contains similar
information to the server F<active> file, such as high and low water marks
and moderation status, and is the information that B<nnrpd> hands out to
clients.

The fields are, in order, the newsgroup name, the high water mark, the low
water mark, the base article number (the point at which the group index
begins), the count of articles in the group, the group status, the
time (in seconds since epoch) when that newsgroup was deleted or 0 if it
hasn't been, and the inode of the index file for that group.

A particular newsgroup can be specified with the B<-n> option.  If B<-n>
is not given, the entire master index will be dumped.

=item B<-n> I<newsgroup>

Specify the newsgroup on which to act, required for the B<-i>, B<-o>, and
B<-R> options.

=item B<-O>

Dump the overview information for a newsgroup in the format used by
B<overchan> as input.  Each line will start with the storage API token,
the arrival timestamp in seconds since epoch, the expires timestamp in the
same format (or 0 if there is no Expires header field), and then the overview
data.

If this option is given, the B<-n> option must also be given to specify
the newsgroup on which to act.  By default, all of the overview
information for that newsgroup is dumped, but the B<-a> option may be
given to restrict the dump to the information for a single article.

=item B<-o>

Dump the overview information for a newsgroup, in the same format as it
would be returned to clients but with one modification.  Appended to the
end of each entry will be four additional pieces of data: the article
number according to the index file for that group labelled with
C<Article:>, the storage API token for that article labelled with
C<Token:>, the arrival date for that article on the server in S<RFC 5322> date
format labelled with C<Arrived:>, and the expiration date for that article
(from the Expires header field) in S<RFC 5322> date format if there is any,
labelled with C<Expires:>.

If this option is given, the B<-n> option must also be given to specify
the newsgroup on which to act.  By default, all of the overview
information for that newsgroup is dumped, but the B<-a> option may be
given to restrict the dump to the information for a single article.

=item B<-p> I<path>

Act on the overview database rooted in I<path>, overriding the overview
path specified in F<inn.conf>.

=item B<-R> I<path>

Rebuild the overview for a given group from the articles stored in
I<path>.  The articles must be in the form of a traditional spool
directory; in other words, each article must be in a separate file and the
name of the file must match the article number of the article.

If this option is given, the B<-n> option must also be given to specify
the newsgroup on which to act.

=back

=head1 EXAMPLES

Dump the master index for the overview database in F</news/overview>,
regardless of the overview path specified in F<inn.conf>:

    tdx-util -i -p /news/overview

Dump the group index for example.test:

    tdx-util -g -n example.test

Dump the complete overview information for example.test:

    tdx-util -o -n example.test

Dump the overview information for articles 45 and higher in example.test:

    tdx-util -o -n example.test -a 45-

Create an entry for example.test with mode m and low and high article
numbers of 4 and 23, respectively.

    tdx-util -c -n example.test -f m -a 4-23

Audit the entire overview database for any problems:

    tdx-util -A

Rebuild the overview information for example.test from a traditional spool
directory:

    tdx-util -R <patharticles in inn.conf>/example/test -n example.test

The last command may be useful for recovering from a bad crash or
corrupted overview information for a particular group, if you are also
using the tradspool article storage method.

=head1 HISTORY

Written by Russ Allbery <eagle@eyrie.org> for InterNetNews.

=head1 SEE ALSO

makehistory(8), nnrpd(8).

=cut
