2 <li><a href="#1">Read-only file system</a><br>
3 <li><a href="#2">copies every file</a><br>
4 <li><a href="#3">is your shell clean</a><br>
5 <li><a href="#4">memory usage</a><br>
6 <li><a href="#5">out of memory</a><br>
7 </ul></td><td> </td><td><ul>
8 <li><a href="#6">rsync through a firewall</a><br>
9 <li><a href="#7">rsync and cron</a><br>
10 <li><a href="#8">rsync: Command not found</a><br>
11 <li><a href="#9">spaces in filenames</a><br>
12 <li><a href="#10">ignore "vanished files" warning</a><br>
13 </ul></td></tr></table>
15 <h3><a name=1>Read-only file system</a></h3>
17 <p>If you get "Read-only file system" as an error when sending to a rsync
18 daemon then you probably forgot to set "read only = no" for that module.
21 <h3><a name=2>copies every file</a></h3>
23 <p>Some people occasionally report that rsync copies every file when they
24 expect it to copy only a small subset. In most cases the explanation is
25 that you forgot to include the --times (-t) option in the original copy,
26 so rsync is forced to check every file to see if it has changed (because
27 the modified time and size do not match).
29 <p>If you think that rsync is erroneously copying every file then look at
30 the stats produced with -v and see if rsync is really sending all the data.
33 <h3><a name=3>is your shell clean</a></h3>
35 <p>The "is your shell clean" message and the "protocol mismatch" message
36 are usually caused by having some sort of program in your .cshrc, .profile,
37 .bashrc or equivalent file that writes a message every time you connect
38 using a remote-shell program (such as ssh or rsh). Data written in this
39 way corrupts the rsync data stream. rsync detects this at startup and
40 produces those error messages. However, if you are using rsync-daemon
41 syntax (host::path or rsync://) without using a remote-shell program (no
42 --rsh or -e option), there is not remote-shell program involved, and the
43 problem is probably caused by an error on the daemon side (so check the
46 <p>A good way to test if your remote-shell connection is clean is to try
47 something like this (use ssh or rsh, as appropriate):
49 <blockquote><pre>ssh remotesystem /bin/true > test.dat</pre></blockquote>
51 <p>That should create a file called test.dat with nothing in it. If
52 test.dat is not of zero length then your shell is not clean. Look at the
53 contents of test.dat to see what was sent. Look at all the startup files on
54 remotesystem to try and find the problem.
57 <h3><a name=4>memory usage</a></h3>
59 <p>Yes, rsync uses a lot of memory. The majority of the memory is used to
60 hold the list of files being transferred. This takes about 100 bytes per
61 file, so if you are transferring 800,000 files then rsync will consume
62 about 80M of memory. It will be higher if you use -H or --delete.
64 <p>To fix this requires a major rewrite of rsync, which my or may not
68 <h3><a name=5>out of memory</a></h3>
70 <p>The usual reason for "out of memory" when running rsync is that you are
71 transferring a _very_ large number of files. The size of the files doesn't
72 matter, only the total number of files.
74 <p>As a rule of thumb you should expect rsync to consume about 100 bytes
75 per file in the file list. This happens because rsync builds a internal
76 file list structure containing all the vital details of each file. rsync
77 needs to hold structure in memory because it is being constantly traversed.
79 <p>A future version of rsync could be built with an improved protocol that
80 transfers files in a more incremental fashion, which would require a lot
81 less memory. Unfortunately, such an rsync does not yet exist.
84 <h3><a name=6>rsync through a firewall</a></h3>
86 <p>If you have a setup where there is no way to directly connect two
87 systems for an rsync transfer, there are several ways to use the firewall
88 system to act as an intermediary in the transfer.
92 <p>Use your remote shell (e.g. ssh) to access the middle system and have it
93 use a remote shell to hop over to the actual target system.
95 <p>To effect this extra hop, you'll need to make sure that the remote-shell
96 connection from the middle system to the target system does not involve any
97 tty-based user interaction (such as prompting for a password) because there
98 is no way for the middle system to access the local user's tty.
100 <p>One way that works for both rsh and ssh is to enable host-based
101 authentication, which would allow all connections from the middle system to
102 the target system to succeed (when the username remains the same).
103 However, this may not be a desirable setup.
105 <p>Another method that works with ssh (and is also very safe) is to setup
106 an ssh key (see the ssh-key manpage) and ensure that ssh-agent forwarding
107 is turned on (e.g. "ForwardAgent yes"). You would put the public
108 version of your key onto the middle and target systems, and the private key
109 on your local system (which I recommend you encrypt). With this setup, a
110 series of ssh connections that starts from the system where your private
111 key is available will auto-authorize (after the pass-phrase prompt on the
114 <p>You should then test that a series of ssh connections works without
115 multiple prompts by running a command like this (put in the real "middle"
116 and "target" hostnames, of course):
118 <blockquote><pre>ssh middle ssh target uptime</pre></blockquote>
120 <p>If you get a password/passphrase prompt to get into the middle system
121 that's fine, but the extra hop needs to occur without any extra user
124 <p>Once that's done, you can do an rsync copy like this:
126 <blockquote><pre>rsync -av -e "ssh middle ssh" target:/source/ /dest/</pre></blockquote>
130 <p>Assuming you're using ssh as your remote shell, you can configure ssh to
131 use a proxy command to get to the remote host you're interested in reaching.
133 <p>Here is an example config for your ~/.ssh/config file (substitute "target",
134 "target_user", and "middle" as appropriate):
136 <blockquote><pre>Host target
137 ProxyCommand nohup ssh middle nc -w1 %h %p
141 <p>This proxy setup uses ssh to login to the firewall system ("middle") and
142 uses nc (netcat) to connect to the target host (%h) using the target port
143 number (%p). The use of "nohup" silences a warning at the end of the run,
144 and the "-w1" option tells nc to shut down when the connection closes.
146 <p>With this done, you could run a normal-looking rsync command to "target"
147 that would run the proxy command to get through the firewall system:
149 <blockquote><pre>rsync -av /src/ target:/dest/</pre></blockquote>
153 <p>Assuming you're using ssh as your remote shell, you can configure ssh to
154 forward a local port through your middle system to the ssh port (22) on the
155 target system. This method does not require the use of "nc" (it uses only
156 ssh to effect the extra hop), but otherwise it is similar to, but slightly
157 less convenient than, method 2.
159 <p>The first thing we need is an ssh configuration that will allow us to
160 connect to the forwarded port as if we were connecting to the target
161 system, and we need ssh to know what we're doing so that it doesn't
162 complain about the host keys being wrong. We can do this by adding this
163 section to your ~/.ssh/config file (substitute "target" and "target_user"
166 <blockquote><pre>Host target
173 <p>Next, we need to enable the port forwarding:
175 <blockquote><pre>ssh -fN -l middle_user -L 2222:target:22 middle</pre></blockquote>
177 <p>What this does is cause a connection to port 2222 on the local system to
178 get tunneled to the middle system and then turn into a connection to the
179 target system's port 22. The -N option tells ssh not to run a command on
180 the remote system, which works with modern ssh versions (you can run a
181 sleep command if -N doesn't work). The -f option tells ssh to put the
182 command in the background after any password/passphrase prompts.
184 <p>With this done, you could run a normal-looking rsync command to "target"
185 that would use a connection to port 2222 on localhost automatically:
187 <blockquote><pre>rsync -av target:/src/ /dest/</pre></blockquote>
189 <p><b>Note:</b> starting an ssh tunnel allows anyone on the source system
190 to connect to the localhost port 2222, not just you, but they'd still need
191 to be able to login to the target system using their own credentials.
195 <p>Install and configure an rsync daemon on the target and use an ssh
196 tunnel to reach the rsync sever. This is similar to method 3, but it
197 tunnels the daemon port for those that prefer to use an rsync daemon.
199 <p>Installing the rsync daemon is beyond the scope of this document, but
200 see the rsyncd.conf manpage for more information. Keep in mind that you
201 don't need to be root to run an rsync daemon as long as you don't use a
204 <p>Once your rsync daemon is up and running, you build an ssh tunnel
205 through your middle system like this:
207 <blockquote><pre>ssh -fN -l middle_user -L 8873:target:873 middle</pre></blockquote>
209 <p>What this does is cause a connection to port 8873 on the local system to
210 turn into a connection from the middle system to the target system on port
211 873. (Port 873 is the normal port for an rsync daemon.) The -N option
212 tells ssh not to run a command on the remote system, which works with
213 modern ssh versions (you can run a sleep command if -N doesn't work). The
214 -f option tells ssh to put the command in the background after any
215 password/passphrase prompts.
217 <p>Now when an rsync command is executed with a daemon-mode command-line
218 syntax to the local system, the conversation is directed to the target
221 <blockquote><pre>rsync -av --port 8873 localhost::module/source dest/
222 rsync -av rsync://localhost:8873/module/source dest/</pre></blockquote>
224 <p><b>Note:</b> starting an ssh tunnel allows anyone on the source system
225 to connect to the localhost port 8873, not just you, so you may want to
226 enable username/password restrictions on you rsync daemon.
229 <h3><a name=7>rsync and cron</a></h3>
231 <p>On some systems (notably SunOS4) cron supplies what looks like a socket
232 to rsync, so rsync thinks that stdin is a socket. This means that if you
233 start rsync with the --daemon switch from a cron job you end up rsync
234 thinking it has been started from inetd. The fix is simple—just
235 redirect stdin from /dev/null in your cron job.
238 <h3><a name=8>rsync: Command not found</a></h3>
240 <p>This error is produced when the remote shell is unable to locate the rsync
241 binary in your path. There are 3 possible solutions:
245 <li>install rsync in a "standard" location that is in your remote path.
247 <li>modify your .cshrc, .bashrc etc on the remote system to include the path
250 <li>use the --rsync-path option to explicitly specify the path on the
251 remote system where rsync is installed
255 <p>You may echo find the command:
257 <blockquote><pre>ssh host 'echo $PATH'</pre></blockquote>
259 <p>for determining what your remote path is.
262 <h3><a name=9>spaces in filenames</a></h3>
264 <p>Can rsync copy files with spaces in them?
266 <p>Short answer: Yes, rsync can handle filenames with spaces.
270 <p>Rsync handles spaces just like any other unix command line application.
271 Within the code spaces are treated just like any other character so a
272 filename with a space is no different from a filename with any other
275 <p>The problem of spaces is in the argv processing done to interpret the
276 command line. As with any other unix application you have to escape spaces
277 in some way on the command line or they will be used to separate arguments.
279 <p>It is slightly trickier in rsync (and other remote-copy programs like
280 scp) because rsync sends a command line to the remote system to launch the
281 peer copy of rsync (this assumes that we're not talking about daemon mode,
282 which is not affected by this problem because no remote shell is involved
283 in the reception of the filenames). The command line is interpreted by the
284 remote shell and thus the spaces need to arrive on the remote system
285 escaped so that the shell doesn't split such filenames into multiple
290 <blockquote><pre>rsync -av host:'a long filename' /tmp/</pre></blockquote>
292 <p>This is usually a request for rsync to copy 3 files from the remote
293 system, "a", "long", and "filename" (the only exception to this is for a
294 system running a shell that does not word-split arguments in its commands,
295 and that is exceedingly rare). If you wanted to request a single file with
296 spaces, you need to get some kind of space-quoting characters to the remote
297 shell that is running the remote rsync command. The following commands
300 <blockquote><pre>rsync -av host:'"a long filename"' /tmp/
301 rsync -av host:'a\ long\ filename' /tmp/
302 rsync -av host:a\\\ long\\\ filename /tmp/</pre></blockquote>
304 <p>You might also like to use a '?' in place of a space as long as there
305 are no other matching filenames than the one with spaces (since '?' matches
308 <blockquote><pre>rsync -av host:a?long?filename /tmp/</pre></blockquote>
310 <p>As long as you know that the remote filenames on the command line
311 are interpreted by the remote shell then it all works fine.
314 <h3><a name=10>ignore "vanished files" warning</a></h3>
316 <p>Some folks would like to ignore the "vanished files" warning, which
317 manifests as an exit-code 24. The easiest way to do this is to create
318 a shell script wrapper. For instance, name this something like
321 <blockquote><pre>#!/bin/sh
324 if test $e = 24; then
327 exit $e</pre></blockquote>