Solved

Rsync to remote server over SSH - Maintain spaces in filenames

Posted on 2011-03-25
8
667 Views
Last Modified: 2012-05-11
I am performing an rsync from one CentOS server to another remote CentOS server over SSH (using private keys). I am transferring a directory that contains numerous sub-directories and files - many of which contain spaces in them.

The problem is that the remote rsync is escaping the spaces in the filenames like so:
CO Ltr ID-00020 USA Ltr.docx  --->   CO\ Ltr\ ID-00020\ USA\ Ltr.docx

I understanding the reasoning behind this (rsync uses spaces between arguments and filenames, etc) -- I'm just looking for a workaround.

This rsync job, once working properly, will run 4 times a day to update / transfer changes to ensure this directory is identical on both systems.

Is there any way, using rsync or another script, to ensure that filenames containing spaces are maintained as-is and are not escaped during the transfer? Or if they must be escaped, any help on a script to remove the slashes on the remote system after transfer would be nice, although not an ideal solution. It's important that the directory structure and files are identical between the two machines.

Thanks,
Chris
0
Comment
Question by:goodie069
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 35215805
Are you using the "--protect-args" option?  That seems to leave spaces alone.
0
 

Author Comment

by:goodie069
ID: 35215900
I receive an error when I include that argument:

rsync: --protect-args: unknown option
0
 

Author Comment

by:goodie069
ID: 35215916
I'm using rsync-2.6.8-3.1.i386
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 19

Expert Comment

by:simon3270
ID: 35215988
protect-args seems to be a v3 option - can you upgrade your client?
0
 

Author Comment

by:goodie069
ID: 35216052
I'd rather not. Haven't had many pleasant experiences with replacing core packages in CentOS, and a quick google search shows a number of forum posts with people who tried and failed.

I suppose I could try and rollback if it failed, but do you have any other ideas before I go that route?

Thanks.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35216138
It looks as though deleting the \ from the target server may be the best option, then, though that may be difficult.

I have tried a few shell fixes, but in most cases, the shell itself removes the '\', meaning that commands such as "mv" fail to find the source file.  For example:
cd /root/to/copied/files
find . -type f | while read nam
do
  mv "$nam" "$(echo $nam | tr -d \\)"
done

Open in new window

fails because the "$nam" after the mv has already had the \ removed, so doesn't find the original file.
0
 

Author Comment

by:goodie069
ID: 35217581
Yeah, did the same thing to me. Thanks for trying though.

Actually, I just went ahead and let the rsync complete with the escaped spaces, then accessed those files through the ajax file manager and found that the files are displayed and download without the slashes -- all of the spaces are where they should be and, to the end user, the file names look identical.

So I think this will work as-is. As long as rsync sees the file names as identical (so it doesn't copy them each time, just updates) and as long as they appear identical to the user I'm good. I think I'll just leave it as-is.

Thanks again for the the attempts. I'll award you full points since I think your --protect-args option would have solved this if I was able to upgrade to 3.0.

0
 

Author Closing Comment

by:goodie069
ID: 35217591
Didn't work for me since I didn't want to upgrade the base rsync package in CentOS, but this would have worked otherwise.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question