synk ==== Synchronize a bunch of files between different hosts. * one-shot tool (no running daemon) * Compares sha512 to check synchronisation status * Last modification time used to elect a "master" * uses `rsync(1)` for fast copying between peers The following requirements are needed in order for `synk(1)` to work between multiple peers: * `synk` must be installed, and in the `$PATH` on each peer * peers must be able to interconnect via `ssh` (without a prompt) usage ----- $ cat /etc/synk.conf peer keel.z3bra.org peer phobos.z3bra.org $ synk -v $HOME/file peer: localhost /home/z3bra/file c8e37eb 1473157623 peer: phobos.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 $ synk -v $HOME/file peer: localhost /home/z3bra/file 005f686 1473157705 peer: phobos.z3bra.org /home/z3bra/file 005f686 1473157705 peer: keel.z3bra.org /home/z3bra/file 005f686 1473157705 syntax ------ The configuration file (default: /etc/synk.conf) contain the peers definition, one per line, in the following format: peer <host> [port] If no port is specified, the default value (9723) will be used. Hosts can be specified either by their fqdn, or ip address. how it works ------------ 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)` 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)` 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'