\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename remsync.info
@settitle @code{remsync} reference manual
@finalout
@setchapternewpage odd
@c %**end of header

@ifinfo
This file documents the @code{remsync} command and friends, which have
the purpose of synchronizing remote directory trees using email.

Copyright (C) 1994 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).

@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Foundation.
@end ifinfo

@titlepage
@title remsync, version 1.3
@subtitle A remote synchronization utility
@subtitle Edition 1.3, June 1994
@author by @value{Francois} Pinard

@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1994 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Foundation.
@end titlepage

@ifinfo
@node Top, Overview, (dir), (dir)
@top @code{remsync}

@code{remsync} allows for remote synchronization of directory trees,
using electronic mail.

The current @code{remsync} release is 1.3.  This is an alpha state
product, and this documentation is still sketchy.

@menu
* Overview::            Overview of @code{remsync} and friends
* Remsync::             Specifications of program @code{remsync}
* Services::            Specifications of other service programs
* Formats::             Related file formats
* Miscellaneous::       

 --- The Detailed Node Listing ---

Overview of @code{remsync} and friends

* Internals::           How @code{remsync} works
* Quick start::         Quick start at using @code{remsync}

Quick start at using @code{remsync}

* Invoking remsync::    The @code{remsync} command and arguments

Specifications of program @code{remsync}

* Invoking remsync::    The @code{remsync} command and arguments
* Conveniences::        Automatic mechanisms in the @code{remsync} program
* Commands::            Commands for @code{remsync}

The @code{remsync} command and arguments

* Conveniences::        Automatic mechanisms in the @code{remsync} program
* Commands::            Commands for @code{remsync}

Specifications of other service programs

* Invoking mailshar::   The @code{mailshar} command and arguments
* Invoking mail-files::  The @code{mail-files} command and arguments
* Invoking find-mailer::  The @code{find-mailer} command and arguments

Related file formats

* Xremsync::            Format of the @file{.remsync} file
* Package::             Format of transiting packages

Various considerations

* News::                Using News distribution instead?
* Previous::            Documentation for obsolete scripts

Documentation for obsolete scripts

* mailsync::            mailsync
* resync::              resync
@end menu

@end ifinfo

@node Overview, Remsync, Top, Top
@chapter Overview of @code{remsync} and friends

The @code{remsync} program allows for transmitting, over email, selected
parts of directories for trying to maintain up-to-date files over many
sites.  It sends out and processes incoming specially packaged files
using @code{shar}, @code{tar}, @code{gzip} and electronic mail programs.

There is no @emph{master} site, each site has an equal opportunity to
modify files, and modified files are propagated.  Among many other
commands, the @code{broadcast} command sends an update package from the
current site to all others, the @code{process} command is used to apply
update packages locally after reception from remote sites.

The unit of transmission is whole files.  For now, whenever a module is
modified, it is silently synchronized only if it has been modified at
only one place.  The merging has to be done at the site where the
discrepancy is observed, from where it is propagated again.

@menu
* Internals::           How @code{remsync} works
* Quick start::         Quick start at using @code{remsync}
@end menu

@node Internals, Quick start, Overview, Overview
@section How @code{remsync} works

How does @code{remsync} keep track of what is in sync, and what isn't?
@xref{Xremsync}, for a the documentation on the @file{.remsync} file
format.  I understand that a mere description of the format does not
replace an explanation, but in the meantime, you might guess from the
format how the program works.

All files are summarized by a checksum, computed by the @code{sum} program.
There are a few variants of @code{sum} computing checksums in incompatible
ways, under the control of options.  @code{remsync} attempts to retrieve on
each site a compatible way to do it, and complains if it cannot.

@code{remsync} does not compare dates or sizes.  Experience shown that the
best version of a file is not necessarily the one with the latest
timestamp.  The best version for a site is the current version on this
site, as decided by its maintainer there, and this is this version
that will be propagated.

Each site has an idea of the checksum of a file for all other sites.
These checksums are not necessarily identical, for sites do not
necessarily propagate to all others, and the propagation network maybe
incomplete or asymmetrical in various ways.

Propagation is never done unattended.  The user on a site has to call
@code{remsync broadcast} to issue synchronization packages for other sites.
If this is never done, the local modifications will never leave the
site.  The user also has to call @code{remsync process} to apply received
synchronization packages.  Applying a package does not automatically
broadcast it further (maybe this could change?).

If a site @var{A} propagates some files to sites @var{B} and @var{D},
but not @var{C}, site @var{B} is informed that site @var{D} also
received these files, and site @var{D} is informed that site @var{B}
also received these files, so they will not propagate again the same
files to one another.  However, both site @var{B} and @var{D} are
susceptible to propagate further the same files to site @var{C}.

It may happen that a site refuses to update a file, or modifies a file
after having been received, or merges versions, or whatever.  So,
sites may have a wrong opinion of the file contents on other sites.
These differences level down after a few exchanges, and it is very
unlikely that a file would not be propagated when it should have.

This scheme works only when the various people handling the various
files have confidence in one each other.  If site @var{B} modifies a
file after having received it from site @var{A}, the file will
eventually be propagated back to site @var{A}.  If the original file
stayed undisturbed on site @var{A}, that is, if @code{remsync} proves
that site @var{B} correctly knew the checksum of the original file, then
the file will be replaced on site @var{A} without any user confirmation.
So, the user on site A has to trust the changes made by the user on site
@var{B}.

If the original file on site @var{A} had been modified after having been
sent in a synchronization package, than it is the responsibility of the
user on site @var{A} to correctly merge the local modifications with the
modifications observed in the file as received from site @var{B}.  This
responsibility is real, since the merged file will later be propagated
to the other sites in an authoritative way.

@node Quick start,  , Internals, Overview
@section Quick start at using @code{remsync}

@node Remsync, Services, Overview, Top
@chapter Specifications of program @code{remsync}

@menu
* Invoking remsync::    The @code{remsync} command and arguments
* Conveniences::        Automatic mechanisms in the @code{remsync} program
* Commands::            Commands for @code{remsync}
@end menu

@node Invoking remsync, Conveniences, Remsync, Remsync
@section The @code{remsync} command and arguments

At the shell prompt, calling the command @code{remsync} without any
parameters initiates an interactive dialog, in which the user types
commands and receives feedback from the program.

The command @code{remsync}, given at the shell prompt, may have
arguments, in which case these arguments taken together form one
@code{remsync} interactive command.  However, @samp{--help} and
@samp{--version} options are interpreted especially, with their usual
effect in GNU.  Once this command has been executed, no more commands
are taken from the user and @code{remsync} terminates execution.
This allows for using @code{remsync} in some kind of batch mode.
It is unwise to redirect @code{remsync} standard input, because
user interactions might often be needed in ways difficult to predict
in advance.

The two most common usages of @code{remsync} are the commands:

@example
remsync b
remsync p
@end example

The first example executes the @code{broadcast} command, which sends
synchronization packages to all connected remote sites for the current
local directory tree.

The second example executes the @code{process} command, which studies
and complies with a synchronisation package saved in the current
directory (not necessarily into the synchronized directory tree), under
the usual file name @file{remsync.tar.gz}.

@menu
* Conveniences::        Automatic mechanisms in the @code{remsync} program
* Commands::            Commands for @code{remsync}
@end menu

@node Conveniences, Commands, Invoking remsync, Remsync
@section Automatic mechanisms in the @code{remsync} program

The following points apply to many of the @code{remsync} commands.
We describe them here once and for all.

@itemize @bullet

@item
The file @file{.remsync} describes the various properties for the
current synchronization.  It is kept right in the top directory of a
synchronized directory tree.  Some commands may be executed without any
need for this file.  The program waits as far as possible before reading
it.

@item
If the @file{.remsync} file is not found when required, and only then,
the user is interactively asked to fill a questionnaire about it.

@item
If the @file{.remsync} file has been logically modified after having
been read, or if it just has been created, the program will save it back
on disk.  But it will do so only before reading another @file{.remsync}
file, or just before exit.  A preexisting @file{.remsync} will be
renamed to @file{.remsync.bak} before it is rewritten, when this is
done, any previous @file{.remsync.bak} file is discarded.

@item
Many commands refer to previously entered information by repeating this
information.  For example, one can refer to a particular @code{scan}
statement by entering the wildcard to be scanned by this statement.
An alternative method of specifying a statement consists in using the
decimal number which appears between square brackets in the result
of a @code{list} command.

@item
Whenever a site list must be given, it is a space separated list of
remote sites.  If the list is preceeded by a bang (@key{!}), the list is
complemented, that is, the sites that will be operated upon are all
those @emph{not} appearing in the list.  As a special case, if the site
list is completely empty, then all sites are selected.

@end itemize

@node Commands,  , Conveniences, Remsync
@section Commands for @code{remsync}

Program commands to @code{remsync} may be given interactively by the
user sitten at a terminal.  They can come from the arguments of the
@code{remsync} call at the shell level.  Internally, the @code{process}
command might obey many sub-commands found in a received synchronization
package.

Program commands are given one per line.  Lines beginning with a sharp
(@key{#}) and white lines are ignored, they are meant to increase
clarity or to introduce user comments.  With only a few exceptions,
commands are introduced by a keyword and often contains other keywords.
In all cases, the keywords specific to @code{remsync} may be abbreviated
to their first letter.  When there are many keywords in succession, the
space separating them may be omitted.  So the following commands are
all equivalent:

@example
list remote
l remote
list r
l r
listremote
lr
@end example

@noindent
while the following are not legal:

@example
l rem
lisremote
@end example

Below, for clarity, keywords are written in full and separated by
spaces.  Commands often accept parameters, which are then separated by
spaces.  All available commands are given in the table.  The first few
commands do not pre-require the file @file{.remsync}.  The last three
commands are almost never used interactively, but rather automatically
triggered while @code{process}'ing received synchronization packages.

@table @asis

@item @code{?}

Display a quick help summary of available commands.

@item @code{!} [ @var{shell-command} ]

If @var{shell-command} has been given, execute it right now as a shell
command.  When not given, rather start an interactive shell.  Exiting
from the shell will return to this program.  The started shell is taken
from the @code{SHELL} environment variable if set, else @code{sh} is
used.

@item @code{quit}

Leave the program normally and return to the shell.

@item @code{abort}

Leave the program with a nonzero exit status and return to the shell.
No attempt is made to save a logically modified @file{.remsync} file.

@item @code{visit} @var{directory}

Select another synchronized directory tree for any subsequent operation.
@var{directory} is the top directory of the synchronized directory tree.

@item @code{process} [ @var{file} ]

@item @code{list} [ @var{type} ]

List all known statements about some information @var{type}.  Allowable
keywords for @var{type} are @code{local}, @code{remote}, @code{scan},
@code{ignore} and @code{files}.  The keyword @code{files} asks for all
empty statements (see later).  If @var{type} is omitted, then list all
known statements for all types, except those given by @code{files}.

@item [ @code{create} ] @var{type} @var{value}

Create a new statement introducing a @var{value} for a given @var{type}.
Allowable keywords for @var{type} are @code{remote}, @code{scan} and
@code{ignore}.  The @code{create} keyword may be omitted.

For @code{create} @code{ignore}, when the pattern is preceeded by a bang
(@key{!}), the condition is reversed.  That is, only those files which
do match the pattern will be kept for synchronization.

@item @code{delete} @var{type} @var{value}

Delete an existing statement supporting some @var{value} for a given
@var{type}.  Allowable keywords for @var{type} are @code{remote},
@code{scan} and @code{ignore}.

@item @code{email} @var{remote} @var{value}

Modify the electronic mail address associated with some @var{remote}
site, giving it a new @var{value}.  The special @code{local} keyword for
@var{remote} may be used to modify the local electronic mail address.

@item @code{home} @var{remote} @var{value}

Modify the top directory of the synchronized directory tree associated
with some @var{remote} site, giving it a new @var{value}.  The special
@code{local} keyword for @var{remote} may be used to modify the local
top directory.

@item @code{broadcast} @var{site_list}

Send by electronic mail an update package to all sites from
@var{site_list}, containing for each site all and only those files which
are known to be different between the remote site and here.

@item @code{version} @var{version}

This command is not meant for interactive use.  It establishes the
@code{remsync} version needed to process the incoming commands.

@item @code{from} @var{site_list}

This command is not really meant for interactive use.  The first site
from the @var{site_list} is the remote site which originated the
synchronization package.  All the others are all the sites, including
here, which were meant to be synchronized by the @code{broadcast}
command that was issued at the originating remote site.

@item @code{sum} @var{file} @var{checksum}

This command is not really meant for interactive use.  It declares the
@var{checksum} value of a particular @var{file} at the originating
remote site.  Also, if at least one @code{sum} command is received, then
it is guaranteed that the originating remote site sent one @code{sum}
command for each and every file to be synchronized, so any found local
file which was not subject of any @code{sum} command does not exist
remotely.

@item @code{if} @var{file} @var{checksum} @var{packaged}

This command is not really meant for interactive use.  It directs the
@code{remsync} program to check if a local @var{file} has a given
@var{checksum}.  If the checksum agrees, then the local file will be
replaced by the @var{packaged} file, as found in the received
synchronization invoice.

@end table

@node Services, Formats, Remsync, Top
@chapter Specifications of other service programs

@menu
* Invoking mailshar::   The @code{mailshar} command and arguments
* Invoking mail-files::  The @code{mail-files} command and arguments
* Invoking find-mailer::  The @code{find-mailer} command and arguments
@end menu

@node Invoking mailshar, Invoking mail-files, Services, Services
@section The @code{mailshar} command and arguments

@node Invoking mail-files, Invoking find-mailer, Invoking mailshar, Services
@section The @code{mail-files} command and arguments

@node Invoking find-mailer,  , Invoking mail-files, Services
@section The @code{find-mailer} command and arguments

@node Formats, Miscellaneous, Services, Top
@chapter Related file formats

@menu
* Xremsync::            Format of the @file{.remsync} file
* Package::             Format of transiting packages
@end menu

@node Xremsync, Package, Formats, Formats
@section Format of the @file{.remsync} file

The @file{.remsync} file saves all the information a site needs for
properly synchronizing a directory tree with remote sites.  Even if it
is meant to be editable using any ASCII editor, it has a very precise
format and one should be very careful while modifying it.  The
@file{.remsync} file is better handled through the @code{remsync}
program and commands.

The @file{.remsync} file is made up of statements, one per line.  Each
line begins with a statement keyword followed by a single @key{TAB},
then by one or more parameters.  The keyword may be omitted, in this
case, the keyword is said to be @emph{empty}, and the line begins
immediately with the @key{TAB}.  After the @key{TAB}, if there are two
parameters or more, they should all be separated with a single space.
There should not be any space between the last parameter and the end of
line (unless there are explicit empty parameters).

The following table gives the possible keywords.  Their order of
presentation in the table is also the order of appearance in the
@file{.remsync} file.

@table @code

@item remsync
This statement identifies the @file{.remsync} format.  The only
parameter states the file format version.

@item local
This statement should appear exactly once, and has exactly two
parameters.  The first parameter gives the electronic mail address the
other sites should use for sending synchronization packages here.  The
second parameter gives the name of the local directory tree to
synchronize, in absolute notation.

@item remote
This statement may appear zero, one or more times.  Each occurrence
connects the synchronized directory tree to another tree on a remote
site.  The first parameter gives one electronic mail address where to
send remote synchronization packages.  The second parameter gives the
name of the corresponding directory tree for this remote electronic mail
address, in absolute notation.

@item scan
This statement may appear zero, one or more times.  When it does not
appear at all, the whole local directory tree will always be scanned,
searching for files to synchronize.  When the statement appears at least
once, the whole local directory tree will not be scanned, but only those
files or directories appearing in one of these statements.  Each
@code{scan} statement has exactly one parameter, giving one file or
directory to be studied.  These are usually given relative to top
directory of the local synchronization directory tree.  Shell wildcards
are acceptable.

@item ignore
This statement may appear zero, one or more times.  Each occurrence has
one parameter giving a regular expression, according to Perl syntax for
regular expressions.  These @var{regexp}s are applied against each file
resulting from the scan.  If any of the @code{ignore} expression matches
one of resulting file, the file is discarded and is not subject to
remote synchronization.

@end table

After all the statements beginning by the previous keywords, the
@file{.remsync} file usually contains many statements having the empty
keyword.  The empty keyword statement may appear zero, one or more
times.  Each occurrence list one file being remotely synchronized.  The
first parameter gives an explicit file name, usually given relative to
the top directory of the local synchronized directory tree.  Shell
wildcards are @emph{not} acceptable.

Besides the file name parameter, there are supplementary parameters to
each empty keyword statement, each corresponding to one remote statement
in the @file{.remsync} file.  The second parameter corresponds to the
first remote, the third parameter corresponds to the second remote, etc.
If there are more remote statements than supplementary parameters,
missing parameters are considered to be empty.

Each supplementary parameter usually gives the last known checksum
value for this particular file, as computed on its corresponding
@emph{remote} site.  The parameter contains a dash @kbd{-} while the
remote checksum is unknown.  The checksum value for the @emph{local}
copy of the file is never kept anywhere in the @file{.remsync} file.
The special value @samp{666} indicates a checksum from hell, used
when the remote file is known to exist, but for which contradictory
information has been received from various sources.

@node Package,  , Xremsync, Formats
@section Format of transiting packages

@node Miscellaneous,  , Formats, Top
@chapter Various considerations

@menu
* News::                Using News distribution instead?
* Previous::            Documentation for obsolete scripts
@end menu

@node News, Previous, Miscellaneous, Miscellaneous
@section Using News distribution instead?

One correspondent thinks that perhaps the news distribution mechanism
could be pressed into service for this job.  I could have started
from C-news, say, instead of from scratch, and have progressively
bent C-news to behave like I wanted.

My feeling is that the route was shorter as I did it, from scratch,
that it would have been from C-news.  Of course, I could have
removed the heavy administrative details of C-news: the history and
@code{expire}, the daemons, the @code{cron} entries, etc., then added
the interactive features and specialized behaviors, but all this clean
up would certainly have took energies.  Right now, non counting the
subsidiary scripts and shar/unshar sources, the heart of the result
is a single (1200 lines) script written in Perl, which I find fairly
more smaller and maintainable than a patched C-news distribution
would have been.

@node Previous,  , News, Miscellaneous
@section Documentation for obsolete scripts

This is merely a place holder for previous documentation, waiting that I
clean it up.  You have no interest in reading further down.

@menu
* mailsync::            mailsync
* resync::              resync
@end menu

@node mailsync, resync, Previous, Previous
@subsection mailsync

@example
Usage: mailsync [ OPTION ] ... [ EMAIL_ADDRESS ] [ DIRECTORY ]
   or: mailsync [ OPTION ] ... SYNC_DIRECTORY
@end example

Option -i simply sends a @code{ihave} package, with no bulk files.
Option -n inhibits any destructive operation and mailing.

In the first form of the call, find a synchronisation directory in
DIRECTORY aimed towards some EMAIL_ADDRESS, then proceed with this
synchronisation directory.  EMAIL_ADDRESS may be the name of a file
containing a distribution list.  If EMAIL_ADDRESS is not specified,
all the synchronisation directories at the top level in DIRECTORY are
processed in turn.  If DIRECTORY is not specified, the current
directory is used.

In the second form of the call, proceed only with the given
synchronisation directory SYNC_DIRECTORY.

For proceeding with a synchronisation directory, whatever the form of
the call was, this script reads the @code{ident} files it contains to set
the local user and directory and the remote user and directory.  Then,
selected files under the local directory which are modified in regard
to the corresponding files in the remote directory are turned into a
synchronisation package which is mailed to the remote user.

The list of selected files or directories to synchronize from the
local directory are given in the @code{list} file in the synchronisation
directory.  If this @code{list} file is missing, all files under the
local directory are synchronized.

What I usually do is to @code{cd} at the top of the directory tree to be
synchronized, then to type @code{mailsync} without parameters.  This will
automatically prepare as many synchronisation packages as there are
mirror systems, then email multipart shars to each of them.  Note that
the synchronisation package is not identical for each mirror system,
because they do not usually have the same state of synchronisation.

@code{mailsync} will refuse to work if anything needs to be hand cleaned
from a previous execution of @code{mailsync} or @code{resync}.  Check
for some remaining @file{_syncbulk} or @file{_synctemp} directory, or
for a @file{_syncrm} script.

@example
TODO:
- interrogate the user if @file{ident} file missing.
- automatically construct the local user address.
- create the synchronisation directory on the fly.
- avoid duplicating work as far as possible for multiple sends.
- have a quicker mode, depending on stamps, not on checksums.
- never send core, executables, backups, @file{.nsf*}, @file{*/_synctemp/*}, etc.
@end example

@node resync,  , mailsync, Previous
@subsection resync

@example
Usage: resync [ OPTION ]... TAR_FILE
   or: resync [ OPTION ]... UNTARED_DIRECTORY
@end example

Given a tar file produced by mailsync at some remote end and already
reconstructed on this end using unshar, or a directory containing the
already untared invoice, apply the synchronization package locally.

Option -n inhibits destroying or creating files, but does everything
else.  It will in particular create a synchronization directory if
necessary, produce the @file{_syncbulk} directory and the @file{_syncrm}
script.

The synchronization directory for the package is automatically
retrieved or, if not found, created and initialized.  @code{resync} keeps
telling you what it is doing.

There are a few cases when a resync should not complete without manual
intervention.  The common case is that several sites update the very
same files differently since they were last resync'ed, and then
mailsync to each other.  The prerequisite checksum will then fail, and
the files are then kept into the @file{_syncbulk} tree, which has a shape
similar to the directory tree in which the files where supposed to go.
For GNU Emacs users, a very handy package, called emerge, written by
Dale Worley <drw@@kutta.mit.edu>, helps reconciling two files
interactiveley.  The @file{_syncbulk} tree should be explicitely deleted
after the hand synchronisation.

Another case of human intervention is when files are deleted at the
mailsync'ing site.  By choice, all deletions on the receiving side are
accumulated in a @file{_syncrm} script, which is not executed automatically.
Explicitely executed, @file{_syncrm} will remove any file in the receiving
tree which does not exist anymore on the sender system.  I often edit
@file{_syncrm} before executing it, to remove the unwanted deletions (beware
the double negation :-).  The script removes itself.

All the temporary files, while resynchronizing, are held in @file{_synctemp},
which is deleted afterwards; if something goes wrong, this directory
should also be cleaned out by hand.  @code{resync} will refuse to work if
anything remains to be hand cleaned.

@display
TODO:
- interrogates the user if missing receiving directory in @file{ident}.
- allow @file{remote.sum} to be empty or non-existent.
@end display

@contents
@bye

@c Local Variables:
@c texinfo-column-for-description: 24
@c End:
