How to escape spaces in rsync source and destination paths

Carney Mimms carney.mimms at
Thu Aug 21 20:32:47 GMT 2008


Thank you for taking an interest in my problem of escaping spaces. Here is
the entire script and the entire output. I am at my wits end as I have tried
every every trick I know or have heard of, including \\\ and adding single
quotes. I added ‹protect-args at your suggestion, but it doesn¹t seem to
change anything. I am running the script as root for now to take sudo out of
the picture. I have also tried putting the paths directly in the command as
arguments, rather than as script variables.

Many thanks,



# Space-separated list of directories to back up; edit as needed; SOURCE
#DIRS="/Volumes/Christine/Complete\ Rug\ Image\ Archive/Misc"
DIRS="admin at\ Rug\ Image\
Archive/Layered\ Rooms/"
# Options to pass to rsync; edit as needed
# "--update" = update only (don't overwrite newer versions of files)
# "--delete"= delete files that exist on DESTINATION BUT NOT SOURCE"
OPTS="-avAX --progress --delete --rsync-path=/usr/local/bin/rsync
--protect-args --dry-run"

# If you wish to back up to a server via ssh, change the line to something
BACKUPDIR="remoteusername at someserver.something:/path/to/backup/destination"
#BACKUPDIR="admin at Rug Image
BACKUPDIR="/Volumes/Paris/Complete\  Rug\ Image\ Archive/Layered\ Rooms/"
# ignore Mac droppings
EXCLUDES="--exclude .DS_Store --exclude .Trash --exclude Cache --exclude

# Build the actual command
# NOTE the specific path to the "special" version of rsync
COMMAND="/usr/local/bin/rsync  $OPTS $EXCLUDES $DIRS $BACKUPDIR"

# Informative output
echo About to run:
echo Please do not close this window until it is finished.

# DO IT!

echo Done.

# the end.

xserve03:/Users/admin/Documents/Rsync 3.0.3/rsync_scripts root#
About to run:
sudo /usr/local/bin/rsync -avAX --progress --delete
--rsync-path=/usr/local/bin/rsync --protect-args --dry-run --exclude
.DS_Store --exclude .Trash --exclude Cache --exclude Caches
admin at\ Rug\ Image\
Archive/Layered\ Rooms/ /Volumes/Paris/Complete\ Rug\ Image\
Archive/Layered\ Rooms/
Please do not close this window until it is finished.
Unexpected local arg: Rug\
If arg is a remote file/dir, prefix it with a colon (:).
rsync error: syntax or usage error (code 1) at main.c(1216) [receiver=3.0.3]


On 8/20/08 11:23 AM, "Kyle Crawford" <kcrwfrd at> wrote:

> On Aug 20, 2008, at 10:32 AM, "Carney Mimms" <Carney.Mimms at>
> wrote:
>> This may not be an rsync-specific question, but it is certainly stopping me
>> from moving forward with rsync and I am sure it has a simple solution. I
>> have written a simple shell script to rsync disks attached to a Mac OS X
>> Server 10.4.11 Xserve box at our offices to a similar Mac OS X Server
>> 10.4.11 setup at our colocation facility. The script runs rsync 3.0.3 on the
>> machine at the colocation facility but syncs the disks at our office back to
>> its own disks, so DIRS is the path to the directory being backed up, which
>> is remote, and BACKUP DIR is the path to the backup destination, which is on
>> the machine running the script.
>> The script works fine, except when I try to specify paths containing spaces.
>> As you can see from the script excerpts below and the result, the backslash
>> escape character isn't getting the job done and I can't figure out why. I've
>> never had any trouble using the backslash escape in this way before.
>> Can anyone suggest a different approach, other than renaming all my paths to
>> eliminate spaces, which is the direction I seem to be heading :-)
>> --------------------------------------------------------
>> DIRS="admin at
>> ered\ Rooms/"
>> BACKUPDIR="/Volumes/Paris/Complete_Rug_Image_Archive/Layered\ Rooms/"
>> COMMAND="sudo /usr/local/bin/rsync  $OPTS $EXCLUDES $DIRS $BACKUPDIR"
>> result:
>> Unexpected local arg: Rooms/
>> If arg is a remote file/dir, prefix it with a colon (:).
>> rsync error: syntax or usage error (code 1) at main.c(1216) [receiver=3.0.3]
>> ----------------------------------------------------------
> You haven't shown us the Rsync portion of your script.
> Are you using the protect args flag?
> Kyle

-------------- next part --------------
HTML attachment scrubbed and removed

More information about the rsync mailing list