-2

I am backing up most of an entire volume with rsync, wanting to omit the OS X overhead files and most of the files associated with a bunch of virtual machines.

Omitting the overhead files works. It's the VM files that I am having trouble with.

All of the VMs are located in a directory tree that starts at /VirtualMachines/. The VMs are located at the top level and in various levels of sub-directories. I want to keep just the VM configuration files (.vmx, .vmxf, and .plist), and skip the rest of the files (virtual disks, etc.)

So far I have been unable to get this to work. I have seen three outcomes:
- I get all VM files
- I get no VM files
- I get the files I want but only from the top-level

This is my current script:

#!/usr/bin/env bash
rsync \
  -vv \
  --dry-run \
  --stats \
  --human-readable \
  --archive \
  --acls \
  --executability \
  --owner \
  --group \
  --hard-links \
  --numeric-ids \
  --perms \
  --xattrs \
  --filter="exclude /.DocumentRevisions*" \
  --filter="exclude .DS_Store" \
  --filter="exclude /.fseventsd" \
  --filter="exclude /.Spotlight*" \
  --filter="exclude /.TemporaryItems" \
  --filter="exclude /.Trash*" \
  --filter="exclude /.VolumeIcon*" \
  --filter="exclude /.disk_label*" \
  --filter="include /VirtualMachines/**.vmx" \
  --filter="include /VirtualMachines/**.vmxf" \
  --filter="include /VirtualMachines/**.plist" \
  --filter="exclude /VirtualMachines" \
  /Volumes/Data02/ /Volumes/Data03/Backups/Rsync/dpconsulting.dpc/Data02

It returns none of the VM files.

It is my understanding that rsync uses the first rule that matches so the includes should take precedence over the final exclude.

I'm obviously misunderstanding something, but re-reading the rsync docs and and reading lots of google results has not provided any clarification.

What have I missed?
TIA

2
  • why not use --include instead?
    – alexus
    Jun 13 '18 at 14:27
  • Because I like to use long forms in scripts. :-) Jun 13 '18 at 14:48
0

I would --include and/or --exclude instead of --filter, however you did mentioned you want to go the other way, and if that's the way you want to go then you should do man rsync and search for FILTER RULES and then do some reading...

here is working example:

$ touch 1 2
$ mkdir 3
$ rsync -rnv --filter "- 1" ./ ./3/
sending incremental file list
2
3/

sent 90 bytes  received 23 bytes  226.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
$ 
6
  • What do you mean "not up to specs"? In what way? Jun 13 '18 at 15:04
  • And, just for grins, I tried using --include and --exclude. I get the exact same results as with --filter. Jun 13 '18 at 15:37
  • Is there a reason why you have ** for your filename instead of *? I've tried it locally, everything works without any hiccup on my side... (refresh your page, to see my updated answer)
    – alexus
    Jun 13 '18 at 15:48
  • The ** is just the most recent attempt to get things working. ** matches slashes in addition to everything else. Jun 13 '18 at 21:43
  • Unfortunately your example is extremely simple in comparison to my actual situation. My VM directory contains sub-directories and some of those also contain sub-directories. A VM can live in any directory in the tree. Jun 13 '18 at 21:44

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.