rsync ownership oddity - bug or feature?
Keith
keith at caramail.com
Thu Apr 21 03:22:53 UTC 2022
On 4/20/22 9:51 PM, Keith wrote:
> On 4/20/22 5:51 PM, Karl Auer wrote:
>> On Thu, 2022-04-21 at 07:51 +1000, Karl Auer wrote:
>>> It all works exactly as expected except that afterwards, /destination
>>> is owned by fred:fred.
>>>
>>> Why?!? And is there anything I can do in the rsync command to stop
>>> this behaviour?
>>
>> Sigh. I read the man page (again) and found this:
>>
>> 'A trailing slash on the source changes this behavior to avoid creating
>> an additional directory level at the destination. You can think of a
>> trailing / on a source as meaning "copy the contents of this directory"
>> as opposed to "copy the directory by name", but in both cases the
>> attributes of the containing directory are transferred to the
>> containing directory on the destination.'
>>
>> I still find this behaviour wrong, but at least it's a known thing. I
>> imagine that since it's been that way forever, it is not going to
>> change any time soon.
>>
>> Out of interest I tried this:
>>
>> rsync -a /source/* /destination
>>
>> ...and that worked without changing the ownership on /destination.
>> Unfortunately, this does not catch hidden files, so it's not really a
>> useful equivalent.
>>
>> Regards, K.
>>
>
> Assuming your shell is bash, enable the shell option "dotglob". man bash(1)
>
> # shopt -s dotglob
>
> then run the rsync command
>
> # rsync -a /source/* /destination/
>
> It should copy all files and directories including hidden ones under
> /source with fred:fred ownership to /destination, but leaving the
> directory owned by mary:mary.
>
Ok, in case you have a mail reader (like thunderbird) that displays
italicized words between forward slashes, then the rsync command above
isn't going to look right. Should be /source /* and /destination /
without the spaces before the last / marks. Of course, if you use
another app, or turn off the config setting in Thunderbird, it'll look
right.
--
Keith
More information about the ubuntu-users
mailing list