How to arbitrarily map user/group ownerships in rsync

ownershiprsyncuseruser-groups

I need to rsync a directory to a remote server so that all files belonging to user X and group Y on the source (local) machine are mapped to user W and group Z on the destination (remote) machine. If possible by using ssh as the transport, but if I need to use the rsync daemon it's fine as well.

Is there a way to do that? I'm looking for a way to establish an arbitrary user/group map, such as

local user X => remote user W
local group Y => remote group Z
... and as many of these as needed.

This should be a pretty common use case, isn't it? E.g. I have files on my local computer where my username is X, and I need to upload them to a web server where they need to belong to a given user which doesn't have either the same name or the same UID as my user on my personal computer.

I can't find that on rsync's man page…

LINUX on both local and remote machine (Ubuntu local, centOS remote)

Command I tried:
rsync -avz /path/to/local root@myhost.com:/path/to/remote

Best Answer

Rsync version 3.1.0 introduced the --usermap and --groupmap options precisely for that purpose. See the man page.

Related Question