0

Variations on this question are everywhere and I have tried many suggested solutions. Yet I cannot grasp what it is that I am missing in the following rsync command:

This sends everything in the source directory, which I do not want:

    echo "$HP3000_SRC"  "$HP0000_DST_HOST":"$HP3000_DST_DIR"
    /tmp/hp3000 192.168.216.107:/usr/local/www/apache24/data/hll_DaV/upload/Other_Scans

rsync --dry-run -avz -ogt --include="./" --include="*pdf-Q*"  --rsh='ssh -p22' "$HP3000_SRC"  "$HP0000_DST_HOST":"$HP3000_DST_DIR" 
!!Warning!! -   Any deliberate attempt to access this resource without 
                legitimate authorization is a criminal offence
                (R.S.C. 1985, c. C-46 - Section 342.1).
sending incremental file list
hp3000/
hp3000/HP3000-2021-04-23T23:27:16-04:00.pdf
hp3000/HP3000-2021-04-23T23:27:18-04:00.pdf
hp3000/HP3000-2021-04-23T23:27:18-04:00.pdf-QZARDBD
hp3000/HP3000-2021-04-23T23:27:19-04:00.pdf
hp3000/HP3000-2021-04-23T23:27:21-04:00.pdf
hp3000/HP3000-2021-04-23T23:27:21-04:00.pdf-QZCCB3R
hp3000/HP3000-2021-04-23T23:27:24-04:00.pdf
hp3000/HP3000-2021-04-23T23:27:24-04:00.pdf-QZCCMWR
hp3000/HP3000-2021-04-24T05:52:33-04:00.pdf
hp3000/HP3000-2021-04-24T05:52:33-04:00.pdf-QZARBDW
hp3000/HP3000-2021-04-24T05:52:34-04:00.pdf
hp3000/HP3000-2021-04-24T05:52:34-04:00.pdf-QZARDBJ
hp3000/HP3000-2021-04-24T05:52:35-04:00.pdf
hp3000/HP3000-2021-04-24T05:52:35-04:00.pdf-QZCCUBT
hp3000/HP3000-2021-04-24T05:52:36-04:00.pdf
hp3000/HP3000-2021-04-24T05:52:36-04:00.pdf-QZGLRQB
hp3000/HP3000-2021-04-25T00:39:49-04:00.pdf
hp3000/HP3000-2021-04-25T00:39:49-04:00.pdf-QZAPATB
hp3000/HP3000-REPORTS.txt

sent 811 bytes  received 77 bytes  592.00 bytes/sec
total size is 701,038  speedup is 789.46 (DRY RUN)

While this sends nothing at all:

rsync --dry-run -avz -ogt --include="./" --include="*pdf-Q*" --exclude="*"  --rsh='ssh -p22' "$HP3000_SRC"  "$HP0000_DST_HOST":"$HP3000_DST_DIR" !!Warning!! -  Any deliberate attempt to access this resource without 
                legitimate authorization is a criminal offence
                (R.S.C. 1985, c. C-46 - Section 342.1).
sending incremental file list

sent 18 bytes  received 12 bytes  20.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

All I want transferred are the files containing "pdf-Q". What invocation of rsync accomplishes this; and why does the --exclude override the --include?

11
  • How about --include '**pdf-Q*' --exclude '*' (in that order)? – Tom Yan Apr 26 at 15:53
  • Double star? I will check. – James B. Byrne Apr 26 at 19:48
  • 1
    Right, and it works fine for me: bpa.st/VLVA – Tom Yan Apr 27 at 5:18
  • 1
    I was testing with bash as well though. " worked fine. – Tom Yan Apr 29 at 1:28
  • 1
    I think that I must have omitted the --exclude=* option in my earliest trials. I cannot see why the later ones with the --exclude=* did not work but I believe that started out on the wrong foot. In any case, copying a rsync command from .bash_history and re-running it now works. I do not know what it was I was doing wrong or what changed in the interim, but I cannot duplicate the error. – James B. Byrne Apr 29 at 14:49
0

Include and exclude options apply from left to right: for any given file or directory the first one that matches is the one that's applied.

Looking at your command

rsync --dry-run -avz -ogt --include="./" --include="*pdf-Q*"  --rsh='ssh -p22' "$HP3000_SRC"  "$HP0000_DST_HOST":"$HP3000_DST_DIR" 

You would match the topmost directory (which already happens, so this is a no-op), then include anything with pdf-Q in the file name. There are no exclusions so nothing is excluded.

Try this instead (you don't need -ogt because these options are already implied by -a).

rsync --dry-run -avz --include='**/' --include='*pdf-Q*' --exclude '*' --prune-empty-dirs --rsh='ssh -q' "$HP3000_SRC"  "$HP0000_DST_HOST":"$HP3000_DST_DIR" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.