You are not logged in.

#1 2010-03-07 12:03:18

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

[SOLV]rsync not preserving ownership when data copied off remote host?

hey everybody

I've got a small server that I want to backup with rsync. My setup and scenario is rather simple: my laptop executes rsync on a remote server and stores data locally.

I've figured that in order to copy files and preserve ownership and permissions I need to actually run rsync as root user since if run as any other unprivileged user all the copied data is assigned ownership of that very user rsync has been run as.

For example, if files:

/srv/ftp/archive

are owned by ftpuser.ftpuser and I run rsync as joe.joe the local copy will be owned by joe.joe. Running rsync via sudo helps in this situation and the resulting local copy will be owned by ftpuser.ftpuser or whatever original ownership scheme.

Now, I want to do this over the network but whenever I run rsync from my laptop and tell the server to run rsync as 'sudo /usr/bin/rsync' the resulting local copy is owned by the local user, just like in the case with rsync being run by joe.joe on a server.

The following is the exact command I use on my laptop:

rsync -avzh --rsync-path="sudo /usr/bin/rsync" joe@server.org:/srv/ftp/archive ./

server.org's /etc/sudoers is set to:

Defaults        env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification
Cmnd_Alias RSYNC=/usr/bin/rsync

# User privilege specification
root    ALL=(ALL) ALL
joe     ALL=NOPASSWD: RSYNC

Why the local copy on a laptop is given ownership of a user rsync has been run as? Have I missed any command line option? Have I missed completely the point of rsync? Is what I aim for feasible? If so, how is this done?

I would be really grateful for any piece of advice.
Thank you!

Last edited by xCrucialDudex (2010-03-07 13:10:25)

Offline

#2 2010-03-07 12:16:45

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

Re: [SOLV]rsync not preserving ownership when data copied off remote host?

I've further tested this scenario and it seems that rsync relies on text labels for ownership data.

For example, /srv/ftp/archive is owned by ftpuser.ftpuser which is uid=1001 gid=1001 on a server. When I copy this directory to a laptop by running rsync as root on a laptop and logging into server.org as root user too the local copy ownership is set to uid=1004 (ftpuser) gid=1001 (ossec) on a laptop. This somehow tells me that rsync relies on text labels and not actual uid/gid which I find really strange.

Offline

#3 2010-03-07 13:08:04

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

Re: [SOLV]rsync not preserving ownership when data copied off remote host?

Okay, I solved this myself.

Two important points:

1) when doing rsync over ssh the user you run rsync as on a receiver determines the level of privileges (i.e. run rsync as root on a laptop log into a server as normal user)
2) use --numeric-ids to prevent rsync from relying on text labels for uid/gid.

I achieved my goal by using the following command:

root@sega:/media/disk-1/rsync-tests % rsync -avzh --numeric-ids joe@server.org:/srv/ftp/archive ./

P.S.: no need for sudo, no need to PermitRootLogins via SSH.

Last edited by xCrucialDudex (2010-03-07 13:09:01)

Offline

Board footer

Powered by FluxBB