5

I'm trying to exclude all vim backup files (hidden *.swp files) from the sync. The pattern in my exclude file looks like this:

**.swp

My rsync call:

rsync -ravu --exclude=~/sync/exclude.txt /home/username/Documents/ remotehost:/home/username/Documents/

The file sits in a subdirectory of the sync root. It deosn't work. Rsync copies the vim backup file as well. I also tried: *.swp

What am I doing wrong?

1
  • --exclude= expect the patters themselves. --exclude-from= is how you specify the file that has patterns into it. Also, why are you using **.swp instead of *.swp?
    – SDsolar
    Aug 24 '17 at 9:38
5

You're using --exclude (which expects a pattern) rather than --exclude-from (which expects the name of a file containing patterns).

You also do not need -r (--recursive) with -a (--archive) as -a enables recursive syncing. In fact, -a is the same as -rlptgoD according to the manual.

3

You don't need the ** and for a single pattern you might as well just use --exclude. The --include pattern ensures that directories matching the --exclude pattern are included in the copy.

rsync -a  --include '*/' --exclude='.*.swp' /home/username/Documents/ remotehost:/home/username/Documents/

If your remote username has /home/username as its home directory you can further simplify with a relative path:

rsync -a  --include '*/' --exclude='.*.swp' /home/username/Documents/ remotehost:Documents/

Bear also in mind that vim will use other filenames for its swap file if one matching *.swp already exists or is in use. But you'll catch most of them with this single pattern. Here's what the documentation warns:

If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc.

You could adapt the exclusion pattern to use .*.sw[a-p] if you were sufficiently concerned.

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.