title: rsync over SSH preserve ownership only for www-data owned files
body: <p>I am using rsync to replicate a web folder structure from a local server to a remote server.  Both servers are ubuntu linux.  I use the following command, and it works well:</p>
  
  <pre><code>rsync -az /var/www/ user@10.1.1.1:/var/www/
  </code></pre>
  
  <p>The usernames for the local system and the remote system are different.  From what I have read it may not be possible to preserve all file and folder owners and groups.  That is OK, but I would like to preserve owners and groups just for the www-data user, which does exist on both servers.  </p>
  
  <p>Is this possible?  If so, how would I go about doing that?</p>
  
  <p>** EDIT **</p>
  
  <p>There is some mention of rsync being able to preserve ownership and groups on remote file syncs here: <a href="http://lists.samba.org/archive/rsync/2005-August/013203.html" rel="nofollow noreferrer">http://lists.samba.org/archive/rsync/2005-August/013203.html</a></p>
  
  <p>** EDIT 2 ** </p>
  
  <p>I ended up getting the desired affect thanks to many of the helpful comments and answers here.  Assuming the IP of the source machine is 10.1.1.2 and the IP of the destination machine is 10.1.1.1.  I can use this line from the destination machine:</p>
  
  <pre><code>sudo rsync -az user@10.1.1.2:/var/www/ /var/www/
  </code></pre>
  
  <p>This preserves the ownership and groups of the files that have a common user name, like www-data. Note that using <code>rsync</code> without <code>sudo</code> does not preserve these permissions.</p>