App-FileSync

 view release on metacpan or  search on metacpan

website/html/quickstart.html  view on Meta::CPAN

		</ul>
	</div>

	<h2 id="server">On the server</h2>

	<p>Create the repo as the account the clients log in to. A session over ssh
	carries only the repo, the client id and the role, so the client never tells
	the server which root to use: name the same <code>--root</code> on every
	server command.</p>

<pre><code># on the server, once
filesync-admin --root ~/filesync repo create documents
filesync-admin --root ~/filesync client allow laptop --repo documents</code></pre>

	<p><code>repo create</code> makes the master directory and the metadata beside
	it, printing both paths. <code>client allow</code> is optional, because a repo
	with no clients admits every client; it takes the client's id, which is the
	host name unless <code>--id</code> was given.</p>

	<p>The example keeps the master in the server account's home directory, so
	nothing has to run as root. <code>/srv/filesync</code> is the built-in default
	root; see <a href="#srv">a root of /srv/filesync instead</a> if you prefer it.</p>

	<h2 id="wrapper">The server-command wrapper</h2>

	<p>The server also needs <code>--root</code> when <code>filesync-server</code>
	starts, and the client cannot pass one, so wrap it:</p>

<pre><code># on the server, once
cat &gt; ~/bin/filesync-server-home &lt;&lt;'EOF'
#!/bin/sh
exec /usr/local/bin/filesync-server --root "$HOME/filesync" "$@"
EOF
chmod +x ~/bin/filesync-server-home</code></pre>

	<p>Use the path <code>filesync-server</code> was actually installed to, which
	<code>ssh srv 'command -v filesync-server'</code> shows: a non-interactive ssh
	command can see a shorter <code>PATH</code> than an interactive login
	shell.</p>

	<h2 id="client">On each client</h2>

	<p>Register the directory and name the wrapper as the server program:</p>

<pre><code># on the client, once
filesync init --repo documents --root /home/foo/Documents \
        --server foo@srv \
        --server-command /home/foo/bin/filesync-server-home</code></pre>

	<p>Nothing else needs naming: the client reports its host name, which is the id
	<code>client allow</code> lists and the name the server keeps this client's
	base, its journal entries and its conflict copies under. Pass <code>--id</code>
	only when the host name is not the name you want, and allow that name on the
	server instead. An id is not a login &mdash; the ssh key and the account do the
	authenticating &mdash; and it does not divide the repo: every client of a repo
	syncs the whole tree.</p>

	<div class="callout">
		<p>ssh runs with <code>BatchMode=yes</code>, so the client's key must already
		be in the server account's <code>authorized_keys</code>, or loaded in
		<code>ssh-agent</code>: cron cannot answer a password prompt.</p>
	</div>

	<h2 id="first">The first sync</h2>

	<p>Look before you leap. <code>--dry-run</code> prints the actions the session
	would take without changing either side.</p>

<pre><code>filesync sync --repo documents --dry-run
filesync sync --repo documents</code></pre>

	<p>Each run reports what moved and how much of it crossed the wire:</p>

<pre><code>documents: pulled 0, pushed 3, deleted 0, conflicts 0
  transfer: sent 148.2 KiB, received 0 B, 1 file by delta</code></pre>

	<h2 id="cron">From cron</h2>

<pre><code># crontab -e, on each client
* * * * * ionice -c3 /usr/local/bin/filesync sync --repo documents --quiet &gt;/dev/null</code></pre>

	<p>The summary line is dropped so cron does not mail on every successful run;
	diagnostics still go to standard error, so a failure is mailed. Every attempt,
	successful or not, is also appended to
	<code>~/.filesync/logs/documents.jsonl</code>.</p>

	<p>Adjust <code>/usr/local/bin/filesync</code> to where the script was
	installed, because cron's default <code>PATH</code> rarely includes a per-user
	Perl bin directory.</p>

	<h2 id="checking">Checking what happened</h2>

<pre><code>filesync status --repo documents
filesync log --repo documents -n 5
filesync log --repo documents --exit 1
filesync verify --repo documents --deep</code></pre>

	<p><code>status</code> shows when each repo last synced, how big it is and what
	the last transfer cost. <code>log</code> filters the run log by time, exit code
	or warning. <code>verify</code> compares the local tree with the base the last
	successful sync recorded; it works offline.</p>

	<p>Exit codes tell cron what happened: <strong>0</strong> ok,
	<strong>1</strong> fatal, <strong>2</strong> another run holds the lock,
	<strong>3</strong> completed with warnings, <strong>4</strong> verification
	found drift.</p>

	<h2 id="windows">On Windows</h2>

	<p>Windows clients use a scheduled task rather than cron. With the script in
	<code>C:\filesync</code> and Strawberry Perl installed, the same job is set up
	from a command prompt:</p>

<pre><code>REM on the client, once
C:\Strawberry\perl\bin\perl.exe C:\filesync\bin\filesync init ^
  --repo documents --root C:\Users\foo\Documents --server foo@srv ^
  --server-command /home/foo/bin/filesync-server-home

REM then create the task; it runs every minute as the current user
schtasks /Create /SC MINUTE /MO 1 /TN FileSync /F ^
  /TR "C:\Strawberry\perl\bin\perl.exe C:\filesync\bin\filesync sync --repo documents --quiet"</code></pre>



( run in 1.938 second using v1.01-cache-2.11-cpan-f5f21f1076c )