synk

Synchronize files between multiple hosts.

Installation

Run these commands to build and install synk on your system:

$ make
# make install

Usage

The following requirements are needed in order for [synk(1)](/man/synk.1.html) to work between multiple peers:

For more information on how this program works, check the synk(1) and synk.conf(5) manpages. As a quick reference, here is an example usage:

# Output "peer: HOSTNAME PATH SHA512 MTIME"
$ synk -v $HOME/file -h keel.z3bra.org -h orbb.z3bra.org
peer: localhost /home/z3bra/file        c8e37eb 1473157623
peer: orbb.z3bra.org    /home/z3bra/file        6d4af03 1473157643
peer: keel.z3bra.org    /home/z3bra/file        005f686 1473157705
master: keel.z3bra.org
synk: rsync -azEq --delete keel.z3bra.org:/home/z3bra/file /home/z3bra/file
synk: ssh keel.z3bra.org rsync -azEq --delete /home/z3bra/file phobos.z3bra.org:/home/z3bra/file

Internal logic

Local client spawns server-mode instances to peers via ssh:

synk $FILE
 \_ ssh phobos.z3bra.org 'synk -s'
 \_ ssh apophis.z3bra.org 'synk -s'
 \_ ssh doom.z3bra.org 'synk -s'

Client sends metadata for $FILE to each peer, which includes the following:

* filename (as passed on the command line)
* sha512 digest for this file
* last modification fime

Each peer will then recreate this structure locally, using the given path and send it back to the client, which will build a list of peer/metadata internally.

This list is then processed to figure out wether all sha512 digests together match or not. In case a difference is found, the modification times are used to determine a "master", which will rsync it local file to all other peers (localhost included).

In this case, we have two possibilities:

localhost is the most recent

If localhost is the most recent, we just spawn [rsync(1)](/man/rsync.1.html) processes locally to update the file with peer that have a different hash:

synk file
 \_ rsync -azEq file phobos.z3bra.org:file
 \_ rsync -azEq file apophis.z3bra.org:file
 \_ rsync -azEq file doom.z3bra.org:file

remote peer X is the most recent

We need to spawn [rsync(1)](/man/rsync.1.html) processes remotely on the host, to sync it with all the peers (except for localhost):

synk file
 \_ rsync -azEq phobos.z3bra.org:file file
 \_ ssh phobos.z3bra.org 'rsync -azEq file apophis.z3bra.org:file'
 \_ ssh phobos.z3bra.org 'rsync -azEq file doom.z3bra.org:file'

License

ISC License. See LICENSE file for copyright and license details.

Development

git clone git://z3bra.org/synk.git

If you find any bug, please report them or send a patch to dev@z3bra.org.

Download