3

I am trying to sync all PHP files to another computer over ssh via rsync. However, it never copies any files. I am on Mac OSX Mountain Lion (10.8.4)

Here is what I have tried:

rsync --rsh=ssh --verbose --remove-source-files --recursive --exclude=* --include='*.php' $HOME/ pi@raspberrypi:~

building file list ... done
sent 36 bytes  received 20 bytes  112.00 bytes/sec
total size is 0  speedup is 0.00

or

rsync --verbose --remove-source-files -e "ssh" $HOME/*.php pi@raspberrypi:~
rsync: link_stat "/Users/simonjackson/*.php" failed: No such file or directory (2)

sent 21 bytes  received 20 bytes  82.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]

Any thoughts on this?

0

2 Answers 2

1

The right syntax would be:

rsync --include="*.php" --filter="-! */" source dest

The problem with a normal exclude="*" rule is that it would exclude everything, even the directories, so you couldn't include anything because all files and folders would be excluded again—makes sense?

To explain the --filter rule here, look at the man page:

A ! specifies that the include/exclude should take effect if the pattern fails to match. For instance, "-! */" would exclude all non-directories.

This is exactly what we want here, since we want to exclude all other files, simply put.

Also beware that the --exclude=* only works in some shells, Bash for example. In Zsh, it would try to expand * before executing the command. That'd mean rsync gets the wrong include/exclude list. So to be safe, always quote the patterns to prevent them from being expanded prematurely.

For further reading, see: Tricks with rsync filter rules

-1

This topic could help you: rsync using regex to include only some files

It seems that rsync's --include and --exclude do not understand regex

Regards,

1
  • That's not the problem; also, the OP isn't using regular expressions at all.
    – slhck
    Jul 16, 2013 at 12:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .