Search code examples
rsync

Apply rsync options specific to a file


rsync provides many options for syncing the files. I am trying to find out an option which can do the following things.
1. Apply rsync options specified for all the files and directory in the source dir.
2. Apply specific option for a directory inside source dir.

For ex:
rsync -avK --ignore-existing /src /dst
I want rsync to apply -avK options for all the files and directories inside src but for one specific directory rsync should apply --ignore-existing option as well.

Is this possible?


Solution

  • Presuming you have the directories /src/foo and /dst/foo with the latter populated with some existing files then the following command line should do what you want:

    rsync -avK --exclude='/foo' src/ dst/ ; rsync -avK --include='/foo' --ignore-existing src/ dst/
    

    The first rsync will exclude transferring files from foo and then the second rsync will transfer only the files in foo using the --ignore-existing option.

    If you have multiple directories you'd like to do that for you can specific multiple exclude/include options like so:

    rsync -avK --exclude='/foo' --exclude='/bar' src/ dst/ ; rsync -avK --include='/foo' --include='/bar' --ignore-existing src/ dst/