Can you pass a chown command during an rsync call?

17,360

Solution 1

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.

Solution 2

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.

Share:
17,360
CMSCSS
Author by

CMSCSS

Updated on June 15, 2022

Comments

  • CMSCSS
    CMSCSS almost 2 years

    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/ [email protected]:/home/website-name/public_html/ | chown website-name:websites-group *

    Sorry, my rsync/bash knowledge is pretty limited.

  • CMSCSS
    CMSCSS over 9 years
    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
  • C. K. Young
    C. K. Young over 9 years
    Which version of rsync are you using? Those options were added in rsync 3.1.0, and they are described in the man page.
  • CMSCSS
    CMSCSS over 9 years
    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?
  • C. K. Young
    C. K. Young over 9 years
    Well, if your distribution doesn't have 3.1.0 or 3.1.1 packages, you'll have to backport them yourself. See 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. :-)
  • Jacket
    Jacket about 8 years
    It seems like both client and server should be running 3.1.0+ in order to use --chown.
  • C. K. Young
    C. K. Young about 8 years
    @Jacket Yep, it's a protocol 31 feature.
  • ToXinE
    ToXinE about 8 years
    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 ?
  • Admin
    Admin almost 8 years
    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.