LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Rsync issue with files with spaces. (https://www.linuxquestions.org/questions/linux-newbie-8/rsync-issue-with-files-with-spaces-829696/)

Mortuus 09-01-2010 05:42 AM

Rsync issue with files with spaces.
 
Hi!

I am trying to write a script for my daily incremental backups with rsync, but I am having some trouble with files which have spaces in their name.

I am executing the following command:
Code:

# rsync -ravuz $(find "/home/mortuus/Documentos/" -mtime -7 -type f) /media/Multimedia/Backup/Debian/home_incre_$(date +%Y-%m-%d)
Files without spaces are copied successfully, but if the file has spaces, it returns the following without being copied:
Code:

rsync: link_stat "/home/mortuus/Documentos/Curriculum" failed: No such file or directory (2)
rsync: link_stat "/root/Vitae_ES.doc" failed: No such file or directory (2)
rsync: link_stat "/home/mortuus/Documentos/testing" failed: No such file or directory (2)
rsync: link_stat "/root/spaces" failed: No such file or directory (2)

The name of the two files are: "Curriculum Vitae_ES.doc" and "testing spaces" respectively. I do not get a method for escaping spaces with this command.

Any ideas?

Thanks in advance.

xeleema 09-01-2010 05:47 AM

I know wrapping things in quotes works, so maybe this will work;

Code:

# rsync -ravuz "$(find "/home/mortuus/Documentos/" -mtime -7 -type f)" /media/Multimedia/Backup/Debian/home_incre_$(date +%Y-%m-%d)

Mortuus 09-01-2010 05:58 AM

Thanks for replying so fast.

I wrapped the first argument with quotes, and now I get the following error:

Code:

root@normandy:~# rsync -ravuz "$(find "/home/mortuus/Documentos/" -mtime -7 -type f)" /media/Multimedia/Backup/Debian/home_incre_$(date +%Y-%m-%d)
sending incremental file list
rsync: change_dir "/home/mortuus/Documentos/Curriculum-Vitae_EN.doc\#012/home/mortuus/Documentos/.~lock.ATHEROS_INSTRUCCIONES.docx#\#012/home/mortuus/Documentos/scripts/full_semanal.sh\#012/home/mortuus/Documentos/Curriculum Vitae_ES.doc\#012/home/mortuus/Documentos/testing spaces\#012/home/mortuus/Documentos/.~lock.wpa.odt#\#012/home/mortuus/Documentos/para-hacer-copia\#012/home/mortuus/Documentos/instrucciones+solicitud+admision.pdf\#012/home/mortuus/Documentos/IT-security-resume-sample.pdf\#012/home/mortuus/Documentos/estudio-sobre-tribus-urbanas.doc\#012/home/mortuus/Documentos/Resume.doc\#012/home/mortuus/Documentos" failed: No such file or directory (2)

sent 12 bytes  received 12 bytes  48.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1060) [sender=3.0.7]

It seems that mixes all files in one.

xeleema 09-01-2010 09:42 AM

try this then (maybe in a script);

Code:

DATETIME=`date +%Y-%m-%d`
for file_name in $(find /home/mortuus/Documentos/ -mtime -7 -type f)
do
rsync -ravuz "${file_name}" /media/Multimedia/Backup/Debian/home_incre_${DATETIME}
done


grail 09-01-2010 09:54 AM

Untested, but if not a great deal of files I am assuming you could use exec option??
Code:

find /home/mortuus/Documentos/ -mtime -7 -type f -exec rsync -ravuz "{}" /media/Multimedia/Backup/Debian/home_incre_$(date +%Y-%m-%d) \;

xeleema 09-01-2010 10:27 AM

Quote:

Originally Posted by grail (Post 4084909)
Untested, but if not a great deal of files I am assuming you could use exec option??
Code:

find /home/mortuus/Documentos/ -mtime -7 -type f -exec rsync -ravuz "{}" /media/Multimedia/Backup/Debian/home_incre_$(date +%Y-%m-%d) \;

@grail
Oh, that should totally work! :) That's way better than my idea!!
/posi-rep bump

@Mortuus
Hey, give grail's suggestion a shot!

Mortuus 09-01-2010 11:46 AM

Thanks to both of you :)

I tried Grail suggestion and it worked perfectly! Thanks! This was getting me mad hehe

I didn't know that find could exec commands, but it is a bit hard for understanding, I will search on google and on books why do you put "{}"

Thanks again. I mark this as solved.

xeleema 09-01-2010 12:24 PM

Quote:

Originally Posted by Mortuus (Post 4085019)
Thanks to both of you :)

I tried Grail suggestion and it worked perfectly! Thanks! This was getting me mad hehe

I didn't know that find could exec commands, but it is a bit hard for understanding, I will search on google and on books why do you put "{}"

Thanks again. I mark this as solved.

The curley brackets "{}" is where find puts the pattern it finds.

Basically, if you ran the find without the -exec, the brackets {}, and the terminator \;, then find will give you a list of directories.

with -exec, the list of directories is stuffed inside {}, one by one. We need double-quotes around the {} because the file names have spaces.


All times are GMT -5. The time now is 02:10 AM.