I'm using rsync to make some regularly backups. Now I want to exclude all files and folders with a red an orange tag. As I learned using tags in OSX isn't available as a criteria to rsync. But with an extension to mdls it would be possible. But I don't have any glue how? Any hints or examples? Thanks in advance Dirk
Summary: I already run rsync successfully. But mdls I didn't understand as well, as the result of mdls would be a filter to rsync.
I am not in a position to test this, but you should be able to get something working if you use this as a starting point.
The general idea is to use
rsync's--exclude-from "excluded.txt"option to specify the things you don't want included in your backup, like this:where
"excluded.txt"contains one line per file or directory you wish to exclude. Try making a simple two-lineexcluded.txtby hand to see if you can get the hang of it first.One the macOS side, you need to use
mdfindto find your red-tagged or orange-tagged files. The basic starting point is:Maybe you actually mean
'tag:red AND tag:orange'? This will produce a list of files (and directories) tagged that way, so you will then want to redirect that to a file when it looks right using:And then you can join the two commands:
There are ways of doing that without creating a temporary file, but I'm not sure if you want anything that complicated:
Note also that I believe
rsyncuses only relative paths for the--exclude-fromparameter, so you may need to convert absolute to relative paths.Note there's an excellent intro to
mdfindby Michael Klement that I commend to you for reading and upvoting here.