How to arbitrarily map user/group ownerships in rsync

Solution 1:

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

Solution 2:

Last version (at least 3.1.1) of rsync allows you to specify the "remote ownership":

--usermap=tom:www-data

Changes tom ownership to www-data (aka PHP/Nginx). If you are using Mac as the client, use brew to upgrade to the last version. And on your server, download archives sources, then "make" it!

Solution 3:

If you want to change ownership of files to arbitrary users, you'll first need to be root on the destination box.

I don't think there is such a feature integrated by rsync, but you can achive it by running a find after doing your rsync.

Maybe, a command like this will do the trick : For example, translate from UID 1000 => 505 and UID 1001 => 700 :

find /your/rsynced/path -user 1000 -exec chown 505 {} \;
find /your/rsynced/path -user 1001 -exec chown 700 {} \;

If you have many users, you may consider using a loop with a mapping, in your predilection language.

Have fun.