selecting some kind of files using the resync command

Ian Malone ibmalone at gmail.com
Wed Oct 22 13:34:05 UTC 2014


On 22 October 2014 10:41, Angelo Moreschini <mrangelo.fedora at gmail.com> wrote:
> Hi,
>
> I am able to backup files with this command:
>  rsync -av --delete /home/programmers/Labels /media/saved_labels
>
> but I am not able to select some kind of files doing the backup
>
> I tried in many different way:
>
>  rsync -av --delete /home/programmers/Labels/*.java /media/saved_lab
>  rsync -avr --delete /home/programmers/Labels/*.java /media/saved_lab
>
> The message that I get is :
>
> sending incremental file list
> rsync: link_stat "/home/programmers/java/PROJECTS_development/Labels/*.java"
> failed: No such file or directory (2)
>
> sent 18 bytes  received 12 bytes  60.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(1165) [sender=3.1.0]
>
>
> ===========
>
> I would like to know how to start this command (after it is inside a shell
> script) at the boot.

Both Bill Oliver and Patrick O'Callaghan have given good suggestions,
but I thought it might be helpful to also explain why this isn't
working the way you might think it should.

rsync -av --delete /home/programmers/Labels/*.java /media/saved_lab

Will get expanded by the shell to any files that match the glob
pattern /home/programmers/Labels/*.java that is to say if there is a
file /home/programmers/Labels/a.java then it will get replaced by
that, if there is more than one file matching *.java in that directory
then it will get expanded to all the matches. Once that's done rsync
gets called with the resulting arguments. The matching only matches
files in that directory, it's performed by the shell (not rsync) and
doesn't descend into subdirectories. Once rsync gets it it will either
have the full path to the (likely non-existent) file "*.java" or a
list of files in the Labels directory which all end .java. If some of
those happen to be directories it will recurse into them as the -a
option tells it to, but likely they'll be regular files and they will
be the only ones to get copied.

If you want recursive descent and matching within subdirectories (eg.
you've got .java files under Labels/Code/) then you either need a find
command to collect them and pass them to rsync or use rsync's "FILTER
RULES" (see man rsync).

-- 
imalone
http://ibmalone.blogspot.co.uk


More information about the users mailing list