Rsync 명령 문제, 소유자 및 그룹 권한이 변경되지 않음

Rsync 명령 문제, 소유자 및 그룹 권한이 변경되지 않음

다음을 통해 소유자와 그룹을 설정하려고 합니다.rsync 작동하지 않는 것 같습니다.

다음 명령은 다음과 같습니다.

sudo rsync -rlptDvz --owner=cmsseren --group=cmsseren /home/serena/public_html/ -e ssh root@ip:/home/cmsseren/public_html2/

파일이 올바르게 동기화되지만 소유자와 그룹이 변경되지 않는 것 같습니다.

답변1

제대로 작동하는 것 같습니다. 사용--owner--group보존하다(설정되지 않음) 소유자 및 그룹 이름... 이는 이전 후 변경되지 않기를 원함을 의미합니다.

이러한 옵션을 사용하지 않으면 사용자 및 그룹은 수신 측에서 호출하는 사용자로 변경됩니다. 다른 사용자를 지정하려면 chown스크립트에 명령을 추가해야 합니다.

-o, --owner
    This option causes rsync to set the owner of the destination file to be 
    the same as  the source file, but only if the receiving rsync is being run 
    as the super-user (see also the --super and --fake-super options). Without 
    this option, the owner of new and/or transferred files are set to the invoking 
    user on the receiving side...

-g, --group
    This option causes rsync to set the group of the destination file to be the same as 
    the source file. If the receiving program is not running as the super-user (or if
    --no-super was specified), only groups that the invoking user on the receiving side
    is a member of will be preserved. Without this option, the group is set to the default
    group of the invoking user on the receiving side...

남자 rsync

답변2

버전 3.1.0rsync는 Thomas가 소개 --usermap하고 --groupmap언급한 편의 옵션이기도 합니다.--chown, 귀하의 시나리오에 적합합니다.

--chown=USER:GROUP
    This option forces all files to be owned by USER with group GROUP.
    This  is  a  simpler  interface  than  using  --usermap  and  --groupmap directly,
    but  it  is implemented using those options internally, so you cannot mix them.
    If either the USER or GROUP is empty, no mapping for the omitted user/group will
    occur.  If GROUP is empty, the trailing colon may be omitted, but if USER is
    empty, a leading colon must  be supplied.

    If you specify "--chown=foo:bar, this is exactly the same as specifying
    "--usermap=*:foo --groupmap=*:bar", only easier.

또한,-o그리고-g옵션이 필요합니다. 이를 제외하면 해당 속성이 업데이트되지 않지만 오류는 발생하지 않습니다.

rsync -og --chown=cmsseren:cmsseren [src] [dest]

이는 에서 간접적으로 언급된다.맨페이지, 옵션은 " 및 내부적 --chown으로 구현됨 " 을 나타냅니다 .--usermap--groupmap

--usermap옵션이 효과를 가지 려면 -o( --owner) 옵션을 사용해야 하며(또는 묵시적으로) 수신자는 수퍼유저로 실행되어야 합니다(옵션 참조 --fake-super).

옵션 --groupmap이 적용되려면 -g( --groups) 옵션을 사용해야 하며(또는 묵시적으로) 수신자에게 해당 그룹을 설정할 수 있는 권한이 있어야 합니다.

답변3

rsync의 마지막 버전(3.1.1 이상)을 사용하면 "원격 소유권"을 지정할 수 있습니다.

--usermap=tom:www-data

톰 소유권을 www-data(일명 PHP/Nginx)로 변경합니다. Mac을 클라이언트로 사용하는 경우 Brew를 사용하여 최신 버전으로 업그레이드하세요. 그리고 서버에서 아카이브 소스를 다운로드한 다음 "만들기"하세요!

답변4

문제.SSH를 통해 클라우드 VPS에서 원격 파일, 디렉터리를 백업하면 로컬 호스트에서 rsync원격 소유권이 유지되지 않았습니다 .owner:group

해결책.

  1. 원격 호스트에서 rsync된 파일(디렉토리 등)에 대해 로컬 호스트에 사용자를 만듭니다.
  2. 로컬 호스트 명령을 / rsync로 실행하십시오 .rootsudo
  3. 루트 비밀번호, SSH 비밀번호 문구를 수동으로 제공해야 합니다.
# create local host system user(s) for those on remote host; see:
# https://wiki.archlinux.org/title/Users_and_groups#Example_adding_a_system_user

sudo rsync -aqP  -e "ssh -p 4321  \                   ## SSH port
    -i /home/victoria/.ssh/my-vps/id_rsa"  \          ## SSH credentials
    [email protected]_isp.com:/etc/default/solr.in.sh   ## rsync SRC (remote host)
    /<my home path>/backups/solr.in.sh  \             ## rsync DEST (local host)

테스트.

# -----------------------------------------------------------------------------
# REMOTE HOST (cloud VPS):

[me@vps1234]$ ls -l /etc/default/

  ...
  -rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh    ## ownership: root:solr
  ...

[me@vps1234]$ 

# -----------------------------------------------------------------------------
# LOCAL HOST:

The basic command for testing (with variations, following) is:

```bash
rm -f solr.in.sh;  \
rsync -aqP  \
    --rsync-path="sudo /bin/rsync"  \
    -e "ssh -p 4321  \
    -i /home/victoria/.ssh/my-vps/id_rsa"  \
    [email protected]_isp.com:/etc/default/solr.in.sh
    /<my home path>/backups/solr.in.sh;  \
ls -l solr.in.sh
# -----------------------------------------------------------------------------
# [TEST 1] rsync --rsync-path...

[victoria]$ rm -f solr.in.sh;  \
    rsync -aqP --rsync-path="sudo /bin/rsync"  \
      -e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
      /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh 

  -rw-r----- 1 victoria victoria 15079 Aug 12 20:35 solr.in.sh
            ## victoria victoria [incorrect]

[victoria]$
# -----------------------------------------------------------------------------
# [TEST 2] sudo rsync --rsync-path ; user "solr" not on local host so remote files
# in group "solr" renamed "git" on local host; tried rsync -og options: no effect

[victoria]$ rm -f solr.in.sh;  \
    sudo rsync -aqP --rsync-path="/usr/bin/rsync"  \
      -e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
    /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh 

  [sudo] password for victoria: 
  Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa': 

  -rw-r----- 1 root git 15079 Aug 12 20:35 solr.in.sh
            ## root:git [incorrect]

[victoria]$
# -----------------------------------------------------------------------------
# [CONFIGURE USERS]
# local host:

[victoria]$ cat /etc/passwd | grep solr     ## no such user
[victoria]$

# Create local host system user, for user on remote host:

[victoria@victoria backups]$ sudo useradd -r -s /usr/bin/nologin solr
  [sudo] password for victoria: 

[victoria]$ cat /etc/passwd | grep solr

  solr:x:980:980::/home/solr:/usr/bin/nologin

[victoria]$ ls -l /home/     ## check: useradd did not create /home/solr/

  total 52
  drwx------   2 root     root     16384 Mar  6  2015 lost+found
  drwxrwxr-x 178 victoria victoria 36864 Aug 13 10:09 victoria

[victoria]$
# -----------------------------------------------------------------------------
# [TEST 3: works] sudo --rsync-path...

[victoria]$ rm -f solr.in.sh;  \
    sudo rsync -aqP --rsync-path="/bin/rsync"  \
      -e "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
      /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh 

  [sudo] password for victoria: 
  Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa': 

  -rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh
            ## root:solr [correct]

[victoria]$
# -----------------------------------------------------------------------------
# [TEST 4: works] No need for --rsync-path option:

[victoria@victoria backups]$ rm -f solr.in.sh;  \
    sudo rsync -aqP -e  \
      "ssh -p 4321 -i /home/victoria/.ssh/my-vps/id_rsa"  \
      [email protected]_isp.com:/etc/default/solr.in.sh  \
      /<my home path>/backups/solr.in.sh;  \
    ls -l solr.in.sh

  [sudo] password for victoria:
  Enter passphrase for key '/home/victoria/.ssh/my-vps/id_rsa':

  -rw-r----- 1 root solr 15079 Aug 12 20:35 solr.in.sh
            ## root:solr [correct]

[victoria@victoria backups]$

# -----------------------------------------------------------------------------

관련 정보