rsync with spaces in filenames fun
By Jon Archer
While I was trying to copy a load of files from one server to another I found a problem I’ve seen time and time again, rsync with filenames that have spaces in them. While normally this can be easily fixed via number of methods:
rsync ‘jon@example.com:/remote/path/filename with spaces.txt’ /local/path/
Notice the quotes around the remote path, you can also use the -s (or –protect-args) which will send the command as-is to the remote.
Tonight I find this doesn’t seem to work (or I can’t get it to work) with a list of files (–files-from=LISTOFFILES.txt). After a few minutes of frigging around I decided there was only one thing for it… A bash for loop :) #!/bin/bash SAVEIFS=$IFS IFS=$(echo -en “\n\b”) for i in `cat LISTOFFILES.txt` do rsync -av ‘jon@example.com:/path/to/files/"$i"’ /local/path done This seemed to work quite nicely.
Edit: OK so it doesn’t seem to be working as well as I thought, seems to pull everything which is just weird…. come back for a fix soon!
Edit: So this is a bit strange, but seems to be working now. Removing the quotes seems to do the trick
#!/bin/bash SAVEIFS=$IFS IFS=$(echo -en “\n\b”) for i in `cat LISTOFFILES.txt` do rsync -av jon@example.com:/path/to/files/$i /local/path done