How to rsync PULL multiple files/dirs

Matt McCutchen hashproduct at verizon.net
Sat Jan 28 03:15:05 GMT 2006


On Fri, 2006-01-27 at 18:10 -0800, Jonathan Chen -X (jonachen - The
Armada Group, Inc. at Cisco) wrote:
> /usr/bin/rsync -e ssh --archive --sparse --compress --update --dry-run
> --exclude=cdersync.tar.gz --exclude=*.bz2  --exclude=*.jpg
> --exclude=*.mp3 --exclude=ZDE --exclude=*.rpm --exclude=*.sit
> jona at cdeprd:' /users/jona/cde /users/jona/Desktop  /users/jona/.bashrc
> /users/jona/.profile' /users/jona/ 
> 
> RSYNC_CMD="${RSYNC_CMD} ${RSYNC_ARGS} $RSYNC_DEST_HOST${RSYNC_FILES}"
> ${RSYNC_CMD}

The variable version doesn't match the written-out version.  I think the
variable version was supposed to be something like this:
	RSYNC_CMD="${RSYNC_CMD} ${RSYNC_ARGS} $RSYNC_SRC_HOST${RSYNC_FILES} /users/jona"

The problem clearly has to do with quoting and word splitting.  rsync
expects a single argument with the source host and all the filenames so
that the remote shell can split them:
	/usr/bin/rsync
	[...]
	--exclude=*.sit
	jona at cdeprd:/users/jona/cde /users/jona/Desktop /users/jona/.bashrc /users/jona/.profile
	/users/jona

But bash parsed the command into these arguments (look closely at the
debug output):
	/usr/bin/rsync
	[...]
	--exclude=*.sit
	jona at cdeprd:'
	/users/jona/cde
	/users/jona/Desktop
	/users/jona/.bashrc
	/users/jona/.profile'
	/users/jona

The single quotes are coming out literally, probably because they are
inside other quotes.  If you have something like this:
	RSYNC_FILES="' /users/jona/cde /users/jona/Desktop'"
delete the single quotes.  You can also get rid of that extraneous space
in front of /users/jona/cde.

Secondly, when you store everything into $RSYNC_CMD, the entire source
argument is substituted in such a way that its internal spaces (which
should be kept and processed by the remote shell) can no longer be
distinguished from the spaces separating it from other arguments.  When
you run $RSYNC_CMD, bash splits on all the spaces.  To avoid this, don't
use $RSYNC_CMD.  Run the command as soon as you put it together from its
pieces, quoting RSYNC_FILES to protect the internal spaces.  Do
something like this:
	${RSYNC_CMD} ${RSYNC_ARGS} $RSYNC_SRC_HOST"${RSYNC_FILES}" /users/jona

I'm missing the lines of your script that set RSYNC_ARGS and so forth,
so these steps may not be exactly right.  If you can't get the script to
work, send the whole script.
-- 
Matt McCutchen, ``hashproduct''
hashproduct at verizon.net -- http://mysite.verizon.net/hashproduct/



More information about the rsync mailing list