LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   using rsync with files/folders using embedded blanks in names (https://www.linuxquestions.org/questions/linux-software-2/using-rsync-with-files-folders-using-embedded-blanks-in-names-4175660617/)

SaintDanBert 09-09-2019 03:52 PM

using rsync with files/folders using embedded blanks in names
 
How do I use rsync to read and write when the file and folder names use embedded blanks?

DISCLAIMER -- This issues is typographically awkward. I'll try my best but please bear with me.

I have a flock of external drives, SD cards, and thumb drives that were written using embedded blanks in file and folder names. I'm tasked to consolidate these files and folders onto a linux file server. A simple copy using:
Code:

prompt$  cp -av  "some\ Source"  "some\ Target"
One issue,
(or similar) does not seem to be good enough.

One tangle comes from the "volume name" or "volume label" that typically results in a mount point like
/media/username/some sort of string with blanks

Now when you add folder and file names you quickly run out of allowed characters on a command line in scripts or internal to utilities like rsync.

While running, rsync reports "I/O error writing..." for some blank-embedded files. It succeeds with others. The failing files can be moved manually using:
Code:

prompt$  cp -av "source/a file/that uses blanks" "target/a file/keeping blanks"
Thanks in advance,
~~~ 0;-Dan

michaelk 09-09-2019 04:07 PM

Myabe using the --protect-args option will fix space problem.

Turbocapitalist 09-10-2019 02:28 AM

I have a lot of files and directories with spaces in the names, but haven't seen that error before.
Can you show the exact parameters you are using with rsync?

michaelk 09-10-2019 05:36 AM

Looks like I may have misinterpreted the problem.

I backup sub-directories with spaces in the path/files names like the following with no problems.

rsync -avxP /source/ /path/to/destination

However, I don't think the I/O error writing messages are attributed to just having spaces in the path file name but maybe filesystem errors.

The --protect-args option is used for remote rsync operations to keep the remote shell from interpreting spaces and special characters.

SaintDanBert 09-12-2019 02:51 PM

Quote:

Originally Posted by Turbocapitalist (Post 6035196)
I have a lot of files and directories with spaces in the names, but haven't seen that error before.
Can you show the exact parameters you are using with rsync?

First, this is a local copy -- disk to disk on the same workstation. Okay, one is an internal (typ. source) and one is an external (typ. target)

I pull files from EXT4, without embedded blanks, without issue using:
Code:

prompt$  rsync -av /someSource/  /someTarget
Since its a local copy, I don't need or want compression.

I only get the errors when I have embedded blanks. I'll try --protect-args like *michaelk* suggested.

I have scanned and checked and tested both the source and target file systems and find no errors. When I'm doing this, I limit the workload so that the disk I/O gets most of the workstation (an 8GB, i5 Thinkpad™ laptop).

I really suspect that the embedded blanks and long path+name character counts are part of the troubles but I've no evidence ... I'll have to do a test and submit a bug report if I get proof.

Turbocapitalist 09-12-2019 11:55 PM

Thanks. Make sure you are quoting the paths or escaping the spaces.

This won't work:

Code:

rsync -av /some Source/with/a space or two/  /some Target/
but these will

Code:

rsync -av '/some Source/with/a space or two/'  '/some Target/'
rsync -av "/some Source/with/a space or two/"  "/some Target/"
rsync -av /some\ Source/with/a\ space\ or\ two/  /some\ Target/

There are a lot of shell guides and tutorials around which go into more detail on quoting and escaping.

TenTenths 09-13-2019 03:50 AM

I came across a similar problem a number of years ago and decided to take the stance that spaces in filenames were just plain wrong!

Not sure if you'll find this useful or not: https://centos.tips/fixing-troublesome-filenames/

pan64 09-13-2019 05:08 AM

the i/o error means probably the filename was split into parts and rsync wanted to write to (or read from) an invalid device/path - which was only a part of the real filename.
You need to use quotations to protect filenames against this.
you can use rsync -v to have verbose output or --itemize-changes to get more info.
You would also need to give a better example, we can only guess without seeing the actual filenames/error messages.

SaintDanBert 09-30-2019 04:49 PM

Quote:

Originally Posted by michaelk (Post 6035245)
Looks like I may have misinterpreted the problem.
...

Let me restate things to clarify:
  • I start a local run using rsync. Either SOURCE or TARGET might be an internal HDD or an external usb-connected store or a media device.
  • Somewhere along the way, the SOURCE folder names or file names or both, start to use embedded blanks. The resulting path+filename is usually long, but nowhere near the PATH_MAX=4095 oro 4096 value.
  • rsync now must construct a path+filename to use against the TARGET
  • rsync reports "I/O error" while writing the target; there errors are consistently reported for blank-embedded path+filename on the TARGET
  • there are no reported I/O errors with the same operation where there are zero, none, nada, path+filename using embedded blanks

Thanks in advanced because I'm thorougly stumped,
~~~ 0;-/ Dan

chrism01 10-03-2019 01:02 AM

I agree with pan64, find a minimal 'broken' rsync example, use -v option and show us the exact cmd, and o/p you get.
This is one of those qns where we need to be as if we are sitting in front of the terminal ourselves.

I'd also agree with TenTenths: spaces considered harmful.
Although the Unix spec says spaces are allowed in filenames, practically every *nix cmd assumes spaces means param separation, unless you take special precautions.

If these are your files, rename them without spaces - you'll thank me later as they will continue to cause problems forever otherwise.
Even if they are not, you may be able to get away with temp renaming them, then processing them, then renaming back - I've had to to that when processing MSWin sourced files - it makes *nix cmds/tools etc 'just work' :)

OstermanA 10-03-2019 01:04 AM

Do you need to preserve the spaces? If you are able/willing to replace them with underscores then you ought to be able to use something like this:
Code:

while read -d '' file; do mv "${file}" "${file// /_}"; done < <(find . -type f -print0)
If you can't just ditch the spaces, what happens if you type one of the files in directly as the source for rsync?


All times are GMT -5. The time now is 11:03 AM.