synk

synchronize files between hosts
Log | Files | Refs | README | LICENSE

README (2813B)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
synk
====

Synchronize files between multiple 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

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)` 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)

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)` 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'

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