3

How can I download from a remote server to local excluding folders or files?

I have used something like this but the exclude doesn't work...

rsync -avr -P -e ssh --exclude=/path/to/exclude/* user@ipaddress:/home/path/to/copy /home/user/www

Suggestions?

mgorven
  • 30,036
  • 7
  • 76
  • 121
Rob
  • 31
  • 1
  • 1
  • 2
  • I can't do reverse operation (launch rsync from my remote server to copy files to my local server) because I can't remote open my local server. – Rob Jun 06 '12 at 15:07
  • 2
    Did you protect globstar '*' from expansion with single quotes? – Dmitri Chubarov Jun 06 '12 at 15:28
  • yes, also used: rsync -avr -P -e ssh --exclude="/path/to/exclude/*" user@ipaddress:/home/path/to/copy /home/user/www – Rob Jun 07 '12 at 09:35

2 Answers2

6

The problem here is likely to be with the paths in the exclude filters in rsync.

The paths used in the rsync file list are relative to the SOURCE path.

That is if your directory structure is

 /home/path/to/copy
                | files_to_copy
                     | file1
                     \ file2
                \ files_to_exclude
                     | file3
                     \ file4

Then if you issue the command

rsync -avr -e ssh user@host:/home/path/to/copy \
                 /home/user/www --exclude='files_to_exclude/*'

You will get the following structure in the copy

 /home/user/www
             | files_to_copy
                  | file1
                  \ file2
             \ files_to_exclude

If you do not want to have the directory files_to_exclude in the copy you may use the following command:

rsync -avr -e ssh user@host:/home/path/to/copy \
                 /home/user/www --exclude='files_to_exclude'
Dmitri Chubarov
  • 2,296
  • 1
  • 15
  • 28
0

We use something similar to this

filename=`date +%F`_backup
rsync --verbose --log-file=/backup_logs/"$filename" --progress --stats --compress --rsh=/usr/bin/ssh --recursive --times --perms --links --delete --exclude '*.zip' user@remoteMachine:/data/documents/ /local/data/documents/
Ben Poulson
  • 101
  • 2