0

I am using Rsync to deploy to a remote server, which is working. However the file and directory ownership always replaces old files with root:root

I need the ownership of all files and folders transferred to the destination folder on the remote server to be changed to www-data:www-data.

I need to access the server as root via ssh, as I don't have the password for www-data. At the moment I have to transfer all the files, and then run the chown command in Terminal afterwards, but I'd like to automate this.

At the moment I am trying the following, but it doesn't work or transfer any files.

'rsync -rlDvz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress --exclude exclude --exclude .htaccess --exclude site/accounts source root@ip:dest && chown -R user:group dest'

Thanks

Jack Wild
  • 101
  • 1

2 Answers2

0

Try rsync -aAX

This should transfer both ownership/group and extended attribute (eg: selinux)

shodanshok
  • 44,038
  • 6
  • 98
  • 162
0

Rsync has the --usermap and --groupmap in version 3.1.0 and above

https://rsync.samba.org/ftp/rsync/src/rsync-3.1.0-NEWS

So if you have 3.1 or above version, you can use either --usermap=www-data:www-data or --chown=www-data:www-data in rsync command like below

rsync --chown=user:group -rlDvz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress source user@ip:dest
Vaibhav Panmand
  • 959
  • 5
  • 17