Repository navigation
Expand file tree
/
Copy pathsynchronization.html
More file actions
155 lines (147 loc) · 14.9 KB
/
Copy pathsynchronization.html
File metadata and controls
155 lines (147 loc) · 14.9 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; form-action 'none'">
<meta name="description" content="How sync-servers finds what changed on each side and turns it into the rows of a preview.">
<title>Synchronization | cmd-sync-servers</title>
<link rel="stylesheet" href="assets/site.css">
</head>
<body>
<a class="skip" href="#main">Skip to the content</a>
<header class="site-header">
<div class="inner">
<a class="brand" href="index.html">cmd-sync-servers</a>
<nav aria-label="Pages">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="quickstart.html">Quickstart</a></li>
<li><a href="getting-started.html">Getting started</a></li>
<li><a href="examples.html">Examples</a></li>
<li><a href="cheatsheets.html">Cheatsheets</a></li>
<li><a href="configuration.html">Configuration</a></li>
<li><a href="cli.html">Command line</a></li>
<li><a href="options.html">Options</a></li>
<li><a href="synchronization.html" aria-current="page">Synchronization</a></li>
<li><a href="api.html">Library API</a></li>
<li><a href="security.html">Security</a></li>
<li><a href="troubleshooting.html">Troubleshooting</a></li>
</ul>
</nav>
</div>
</header>
<main id="main">
<h1>Synchronization</h1>
<p class="lead">How a sync finds what changed on each side, decides what each file needs, and runs only what you confirm.</p>
<p>To put only the files you worked on in the last hours or days, see <a href="#range">Putting the files of a time range</a>.</p>
<h2 id="records">The memory of the last sync</h2>
<p>For every file it synchronizes, sync-servers records both sides as they were at that moment: the size and modification time of the local copy and of the server copy. These <strong>sync records</strong> are kept per site and server in the state folder of this computer.</p>
<p>On the next sync each side is compared with its <em>own</em> record, never with the other side's clock. A local file whose size or time moved is changed locally; a server file whose size or time moved is changed on the server. When both moved, the file changed on both sides, and it waits for your decision instead of being overwritten. A local file is held to its record exactly, since the disk reports the same time for a file nobody touched. On the server, times closer than the tolerance, 2 seconds by default, count as equal, because many servers round them in listings.</p>
<p>A file with no record yet, as on a first sync, is compared across the two sides: the newer copy wins, and copies of the same age that differ ask for a decision. In checksum mode (<code>sync.compare</code> set to <code>checksum</code>) SHA-256 hashes settle what times cannot.</p>
<p>One file is never compared at all: <code>_notes/dwsync.xml</code>, where Dreamweaver keeps its own records of a folder. It is never a row of a preview, on either side.</p>
<p>A site that Dreamweaver synchronized has a memory already, in those files. With <a href="configuration.html#dreamweaver"><code>sync.dreamweaver.enabled</code></a> on, sync-servers reads an entry as evidence for a file both sides have: when both copies are as Dreamweaver last recorded them, the file is in sync, and when only one is, the other side changed. So the first preview of such a site lists only real differences, and a file put with Dreamweaver between two syncs is not a conflict. A file that is missing on one side is never judged by an entry, so an entry never checks a delete. After each transfer the entry is written the way Dreamweaver would have written it, a delete removes it, and the entries of other servers stay as they are, so both programs go on agreeing. The records of sync-servers itself stay the ones it trusts: removing a <code>_notes</code> folder loses nothing here.</p>
<p>Dreamweaver reads a server's clock its own way, so nothing is taken from its records, or written to them, until sync-servers knows the difference. It learns it from the entries during the first synchronization of the whole site, when at least three files agree, and accepts one hour either way for daylight time.</p>
<p><code>sync-servers status</code> shows what changed on each side without planning anything. <code>mark-synced</code> records files as in sync without moving them, and <code>state reset</code> forgets the records so the next sync starts from scratch.</p>
<h2 id="actions">From a change to an action</h2>
<p>Each direction turns what changed into an action. A file whose row says "not listed" is counted as skipped and never moves.</p>
<table>
<caption>The action each change gets, by direction</caption>
<thead>
<tr><th scope="col">What happened since the last sync</th><th scope="col">Put newer files</th><th scope="col">Get newer files</th><th scope="col">Both</th></tr>
</thead>
<tbody>
<tr><td>Changed here</td><td>Put</td><td>not listed</td><td>Put</td></tr>
<tr><td>Changed on the server</td><td>not listed</td><td>Get</td><td>Get</td></tr>
<tr><td>Changed on both sides</td><td>Resolve</td><td>Resolve</td><td>Resolve</td></tr>
<tr><td>New here</td><td>Put</td><td>not listed</td><td>Put</td></tr>
<tr><td>New on the server</td><td>not listed</td><td>Get</td><td>Get</td></tr>
<tr><td>Deleted on the server, unchanged here</td><td>Put again</td><td>not listed</td><td>Put again</td></tr>
<tr><td>Deleted here, unchanged on the server</td><td>not listed</td><td>Get again</td><td>Get again</td></tr>
<tr><td>Changed here, deleted on the server</td><td>Resolve</td><td>Resolve</td><td>Resolve</td></tr>
<tr><td>Deleted here, changed on the server</td><td>Resolve</td><td>Resolve</td><td>Resolve</td></tr>
<tr><td>No record, newer here</td><td>Put</td><td>not listed</td><td>Put</td></tr>
<tr><td>No record, newer on the server</td><td>not listed</td><td>Get</td><td>Get</td></tr>
<tr><td>No record, differs, same age</td><td>Resolve</td><td>Resolve</td><td>Resolve</td></tr>
</tbody>
</table>
<p>A <strong>Resolve</strong> row is unchecked and cannot run until you choose Put, Get, Skip or Synchronized for it.</p>
<h3 id="delete-option">The delete option</h3>
<p>With <code>--delete</code>, or the delete checkbox, a file missing on the other side is offered for deletion instead of being copied back. The checkbox is worded for the direction: <em>Delete remote files not on local drive</em> when putting, <em>Delete local files not on remote server</em> when getting.</p>
<table>
<caption>What the delete option changes</caption>
<thead>
<tr><th scope="col">What happened</th><th scope="col">Put newer files</th><th scope="col">Get newer files</th><th scope="col">Both</th></tr>
</thead>
<tbody>
<tr><td>Deleted here since the last sync</td><td>Delete on the server, checked</td><td>Get again</td><td>Delete on the server, checked</td></tr>
<tr><td>Deleted on the server since the last sync</td><td>Put again</td><td>Delete here, checked</td><td>Put again</td></tr>
<tr><td>On the server only, never synchronized</td><td>Delete on the server, <strong>unchecked</strong></td><td>Get</td><td>Delete on the server, <strong>unchecked</strong></td></tr>
<tr><td>Here only, never synchronized</td><td>Put</td><td>Delete here, <strong>unchecked</strong></td><td>Put</td></tr>
</tbody>
</table>
<p>A file that was never synchronized is only ever offered for deletion unchecked: nothing is deleted just because it has no record.</p>
<h3 id="single-files">Put and Get of single files</h3>
<p><code>sync-servers put css/site.css</code> and <code>get</code> move the files and folders you name at once, through the same checks. When one of them changed on the other side, or is held back by the guard, the preview opens first so you can decide.</p>
<h2 id="range">Putting the files of a time range</h2>
<p>Sometimes only the work of the last hours or days should go to the server: on a site with other differences that are not ready to go yet, or on one that was never synchronized, where a Put lists every file. A <strong>time range</strong> puts just the files you worked on lately:</p>
<pre><code>sync-servers sync --put recent --range 2d</code></pre>
<p>The range is a number and one unit in lower case, counted back from now. <code>-r</code> is short for <code>--range</code>, the word <code>recent</code> may be left out, and paths after it keep the range to those folders and files, as in <code>sync-servers sync --put recent -r 90m css</code>.</p>
<table>
<caption>The units of a time range</caption>
<thead><tr><th scope="col">Unit</th><th scope="col">Counts</th><th scope="col">Example</th></tr></thead>
<tbody>
<tr><td><code>m</code></td><td>Minutes</td><td><code>--range 90m</code>, the last 90 minutes</td></tr>
<tr><td><code>h</code></td><td>Hours</td><td><code>--range 24h</code>, the last 24 hours</td></tr>
<tr><td><code>d</code></td><td>Days</td><td><code>--range 2d</code>, the last two days</td></tr>
<tr><td><code>w</code></td><td>Weeks</td><td><code>--range 1w</code>, the last week</td></tr>
</tbody>
</table>
<p>The number may have a decimal part, as in <code>1.5h</code>. A capital letter, another unit or two ranges at once are refused, so <code>2M</code> is never taken for two minutes.</p>
<ul>
<li><strong>What recent means.</strong> A file is recent when it was created or last modified at or after the start of the range, by this computer's clock and the dates its file system keeps. A file copied into the site keeps the modification time it came with, and still counts from the day it arrived. Folders are not judged, only the files in them.</li>
<li><strong>What the preview holds.</strong> The recent files that differ from the server, each as in any preview: one that also changed on the server waits for a decision, and one that matches a sensitive pattern is held back. Recent files already in sync are counted as skipped, and cloaked files are left out as always.</li>
<li><strong>What it never holds.</strong> A delete, a Get, or a file only the server has. A range goes with Put only, and not with the delete option.</li>
<li><strong>What the server is asked.</strong> Only the recent files are looked up on the server, file by file, and nothing connects when no file is recent. That is quick for a few files. When the range takes in most of a large site, <code>sync --put</code> without a range, which compares whole folders, is faster.</li>
<li><strong>Time on disk.</strong> A file counts by the time it was saved to disk. One that is open in an editor with unsaved changes counts by its last save.</li>
</ul>
<p>The preview is titled for the range, such as <code>Put files from the last 2 days</code>, and from there everything is as in any synchronization: check or uncheck rows, then confirm. In a terminal, <code>sync-servers sync</code> without a direction offers <em>Put files from a time range</em> as its first choice and asks for the range, with <code>1d</code> as the answer Enter gives. The Synchronize screen of the <a href="cli.html#tui">terminal interface</a> has the same choice.</p>
<h2 id="preview">The preview</h2>
<p>The preview lists only files with a difference; unchanged files are counted, never listed. A preview made from <a href="#range">a time range</a> lists only the recent ones among them. Its summary line counts what will happen, such as <code>Files: 37 will be updated, 169 will be skipped, 12 need a decision</code>. Each row has a checkbox, an action and a status that says why, in a sentence:</p>
<table>
<caption>Rows that start unchecked</caption>
<thead><tr><th scope="col">Row</th><th scope="col">Why</th></tr></thead>
<tbody>
<tr><td>Resolve</td><td>Changed on both sides, or differs with no record. Choose an action first.</td></tr>
<tr><td>Guarded</td><td>Matches a sensitive pattern such as <code>.env</code>; see <a href="configuration.html#guard">the guard</a>.</td></tr>
<tr><td>Never-synchronized delete</td><td>Offered by the delete option for a file with no record.</td></tr>
<tr><td>Problem</td><td>A name that cannot be used here: not valid on this system, a symbolic link that is not followed, or two names that differ only by case on a file system that cannot tell them apart. Problem rows never run.</td></tr>
</tbody>
</table>
<p>You can change any row: check or uncheck it, or choose another action that the file can take. Put needs a local copy, Get a server copy, and Synchronized both.</p>
<h2 id="running">Running a plan</h2>
<ul>
<li><strong>Checked once more.</strong> Just before a file moves, both sides are looked at again. A file that changed since the preview is skipped and reported as stale.</li>
<li><strong>Written whole or not at all.</strong> A file is written to a partial copy, its size checked, and only then renamed into place, so an interrupted transfer never leaves half a file.</li>
<li><strong>Local files kept.</strong> A local file that a run deletes or overwrites is moved to the recovery folder of the state folder first, and kept 14 days.</li>
<li><strong>Through links.</strong> When the site follows <a href="configuration.html#links">symbolic links</a>, a Get through a link writes the file the link points to and keeps the link, and rows that reach one file through two names run one at a time.</li>
<li><strong>Folders in order.</strong> Folders are created before their files and removed after them.</li>
<li><strong>Retries.</strong> A dropped connection or a timeout is retried on a fresh connection after 1, 2 and 4 seconds.</li>
<li><strong>Recorded as it goes.</strong> Records are saved during the run, so a cancelled or interrupted sync keeps what it finished. Cancelling starts no new transfer and removes partial files.</li>
<li><strong>Recorded when nothing moves.</strong> A synchronization with nothing to transfer still records the files it found to be the same on both sides, so the next one does not compare them from scratch. <code>--dry-run</code> and <code>status</code> record nothing.</li>
</ul>
<h2 id="guards">Safety guards</h2>
<p>Some plans stop before anything moves, with exit code 5:</p>
<ul>
<li><strong>Mass delete.</strong> Deleting more than 50 files, or more than a quarter of a side's files, asks you to type the count. A script needs <code>--allow-mass-delete</code>. Both limits are settings of the site.</li>
<li><strong>Empty root.</strong> When one side is empty and the plan would delete everything on the other, the run is refused: an unmounted drive or a wrong root directory looks exactly like that.</li>
<li><strong>Top of a server.</strong> Deletes are refused when the server's root directory is <code>/</code> or a drive root, unless the server allows it with <code>allowRootDeletes</code>.</li>
</ul>
</main>
<footer class="site-footer">
<div class="inner">
<p>cmd-sync-servers is open source under the MIT license. Source, issues and releases are on <a href="https://github.com/isocialPractice/cmd-sync-servers">GitHub</a>.</p>
</div>
</footer>
</body>
</html>