Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you pass a chown command during an rsync call?

Tags:

rsync

owner

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.

like image 609
CMSCSS Avatar asked Oct 03 '14 01:10

CMSCSS


People also ask

Does rsync preserve ownership?

'rsync -a' option preserves the permissions, ownership, timestamp of files and folders that are to be transferred using rsync. This will synchronize the two folders or files and will also maintain the same timestamp as that of the source.

What does rsync command do?

Rsync is a command-line tool for copying files and directories between local and remote systems that should be in every Linux sysadmin's toolbox.

How do I know if rsync is working?

Method 1: Using –progress option to see the rsync progress:Use the “–progress” in the rsync command and “-av” to get a summary at the end of file transfer, consisting of transfer rate, sent/receive bytes, speed of transfer, and total file size.


2 Answers

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.

like image 193
Chris Jester-Young Avatar answered Oct 18 '22 10:10

Chris Jester-Young


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.

like image 34
Itai Ganot Avatar answered Oct 18 '22 09:10

Itai Ganot