rsync over SSH preserve ownership only for www-data owned files

后端 未结 6 1498
轮回少年
轮回少年 2021-02-05 16:36

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:

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 16:59

    Well, you could skip the challenges of rsync altogether, and just do this through a tar tunnel.

    sudo tar zcf - /path/to/files | \
      ssh user@remotehost "cd /some/path; sudo tar zxf -"
    

    You'll need to set up your SSH keys as Graham described.

    Note that this handles full directory copies, not incremental updates like rsync.

    The idea here is that:

    • you tar up your directory,
    • instead of creating a tar file, you send the tar output to stdout,
    • that stdout is piped through an SSH command to a receiving tar on the other host,
    • but that receiving tar is run by sudo, so it has privileged write access to set usernames.

提交回复
热议问题