11

Title says it all really.

I see that you can preserve owner:group but is it possible to change the owner:group on all files on the remote after they've been synced?

Or can you somehow pipe an extra command?

rsync -vzrP --delete ~/Sites/website-name/ root@server.com:/home/website-name/public_html/ | chown website-name:websites-group *

Sorry, my rsync/bash knowledge is pretty limited.

ekad
  • 14,436
  • 26
  • 44
  • 46
CMSCSS
  • 2,076
  • 9
  • 28
  • 49

2 Answers2

9

Yes, rsync provides the --usermap and --groupmap options to allow you to customise how these are mapped at the remote end.

For your particular use case, where all files are to be mapped to the same user/group combo, you can use the --chown option, which is a shortcut for the above.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • Thanks heaps for the reply but after searching (and reading the man pages) I can't find anything on ````--usermap --groupmap --chown```` (I found ````--chmod```` only) sorry. Can you point me in the right direction or show me an example of the syntax? Cheers – CMSCSS Oct 03 '14 at 19:28
  • Which version of rsync are you using? Those options were added in rsync 3.1.0, and they are described in the [man page](http://rsync.samba.org/ftp/rsync/rsync.html). – C. K. Young Oct 04 '14 at 02:30
  • Thanks for that, I've updated rsync on my mac but the server says 3.0.9 is the latest. I used ````apt-get```` - is there a way to force the server to see the newer versions? – CMSCSS Oct 05 '14 at 02:14
  • Well, if your distribution doesn't have 3.1.0 or 3.1.1 packages, you'll have to backport them yourself. See https://wiki.debian.org/BuildingFormalBackports for instructions. I frequently build backport packages myself and I can create one for you, but that might be considered too untrustworthy for you. :-) – C. K. Young Oct 07 '14 at 17:25
  • 1
    It seems like both client **and server** should be running 3.1.0+ in order to use `--chown`. – Jacket Mar 11 '16 at 07:06
  • @Jacket Yep, it's a protocol 31 feature. – C. K. Young Mar 11 '16 at 07:08
  • so, how do you chown file in rsync with 3.0.9 without backporting rsync to 3.0.10 or 3.1.x ? a pipe could work like in the question ? – ToXinE Mar 16 '16 at 11:14
  • 8
    It seems `--chown` doesn't work unless you also set `--owner --group`. It's kind of counter intuitive, since the latter options talk about perserving owner and group from source. On top of that, the man page for `--chown` does not mention that, neither is a warning issued. The section for `--usermap` does mention this. –  Jun 18 '16 at 18:41
1

In addition to Chris's answer, you can also edit your /etc/rsyncd.conf and include the uid and gid you want the files to get in the relevant rsync folder.

Example:

[hadoop_out]
        comment =  hadoop_out
        path = /mass1/mt_data/hadoop_out
        read only = no
        list = yes
        uid = 26
        gid = 26
        auth users = postgres
        secrets file = /etc/rsyncd.secrets
        hosts allow = 10.11.20.61

That way, the files will be sync'ed and saved with uid and gid 26 of user postgres so you will not have to provide this info in the command you run.

Itai Ganot
  • 5,873
  • 18
  • 56
  • 99