Shawn Rutledge
2009-Jun-18 23:28 UTC
idea: include/exclude files by mime type (use magic like file(1) does)
I have been thinking this would be a nice feature: exclude files by type rather than just regular expressions. Mostly because binaries don't have any extension on Linux, so they aren't recognizable just by name. At work I rsync a source directory for doing builds in a chroot environment for the target system, and I'd like to exclude binaries that happen to be in the tree, on the host system. (It's easy enough to exclude the .o files but not the final linked executables.) Likewise at home, I was thinking of rsyncing my home directory between a couple of machines, one of which is 32-bit, so it doesn't make sense to sync any 64-bit binaries from other machines to that one. So I would like to exclude "ELF executables" or "application/x-executable" from the rsync. I think for speed, if the --exclude-mime option is given, rsync would need to process the other include/exclude patterns first, then as a final pass, basically look up the magic numbers the same way that file(1) does for each file that it plans to transfer, and exclude files on that basis. For --include-mime, it wouldn't be as efficient (would have to get the mime type for every candidate file).