0

I'm trying to rsync to a remote server, how can I change the owner for this directory? Putting down some information below, so it is more clear.

The directory owner on the server over which I'm running this command is jenkins

Now when I do:

rsync -av --include =*txt /var/lib/jenkins/*/. [email protected]:/tmp/.

The rsync command is part of a perl script which is running as the user bpmdev.

The directory owner is preserved as owned by jenkins on the server to where it is copied. However I need to change this owner to bpmdev (the one who's running the rsync command). How can I do this?

The /tmp drive is shared across these two servers, and the rsync version is 2.6.8

3
  • Try --usermap=jenkins:bpmdev. This will cause all files/directories owned by jenkins on the source to be owned by bpmdev on the destination. You will probably want to use a --groupmap option too. See man rsync and search for --usermap for details on both options.
    – cas
    Apr 28, 2021 at 10:11
  • @cas That seems to be what they are asking about. Care to write an answer? Hmmm... If this bpmdev user isn't root, shouldn't the ownerships be changed to that user regardless though? Oh, I see now, they SSH as root for whatever reason.
    – Kusalananda
    Apr 28, 2021 at 11:29
  • @cas Can you please elaborate what you're trying to say a bit more? Or if you could point me to a particular thread from which I could understand it more, that'd be really helpful. Thanks
    – Pv66
    Apr 28, 2021 at 11:52

1 Answer 1

2

Why are you using the root account on the destination for this sync then? If you use the bpmdev account instead, all the files that reach there will be owned by that user. There may be other advantages if you don't otherwise need this account to have access to the root account there.

rsync -av --include =*txt /var/lib/jenkins/*/. [email protected]:/tmp/.

This does assume that bpmdev has write permission in /tmp, but that is commonly true.

1
  • Yes bpmdev has the permission to write to /tmp. This worked for me. I initially was under the impression that rsync changes the directory owner to the user with which it is run. Certainly that wasn't the case.
    – Pv66
    Apr 29, 2021 at 6:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .