대상 소유자 및 권한과의 재동기화가 가능합니까?

대상 소유자 및 권한과의 재동기화가 가능합니까?

원본 서버의 소유자는 루트입니다.

----/home/sub1/test1 
----/home/sub2/test1

내 로컬 컴퓨터가 대상입니다.

----/home/sub1/test1 owner by user1
----/home/sub2/test1 owner by user2

소스 서버의 새 업데이트 파일을 로컬 컴퓨터에 동기화하고 로컬 소유자를 변경하지 않으려면 어떻게 해야 합니까?

편집하다

폴더가 많고 로컬 컴퓨터에도 소유자가 많기 때문에 하나의 명령으로 모든 소스를 동기화해야 합니다. 아마도 가능할까요?

감사해요.

답변1

이전 후 변경을 원하지 않는 것 같습니다.

아래 명령을 시도해 보세요:

rsync -avr -o -g /source/directory user@:destinationHost/destination/directory

이러한 옵션을 사용하지 않으면 사용자 및 그룹은 수신 측에서 호출하는 사용자로 변경됩니다. 다른 사용자를 지정하려면 스크립트에 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...

SEE MAN rsync

답변2

내 생각에 좋은 옵션은 다음과 같은 것을 사용하여 별도의 물리적 파일 시스템 전송이라고 가정하고 소스에서 대상으로 정상적으로 rsync하는 것입니다.

rsync -e 'ssh -p 22' -quaxz --bwlimit=1000 --del --no-W --delete-excluded --exclude-from=/excludedstufflist /sourcedir serverIP:/destinationdir

그런 다음 새 시스템의 올바른 위치에 모두 복사되면 시스템이 소스 시스템의 데이터에 어떤 새 UID를 제공했는지 알아보세요. 아마도 1001, 1002 등일 것입니다. 이 경우 쉽게 할 수 있습니다

find /destinationdir -user 1001 -exec chown username '{}' \;
find /destinationdir -user 1002 -exec chown otherusername '{}' \;
etc.

예, 마지막 작업을 100번 수행해야 하지만 rsync 중에 사용된 UID 시퀀스를 알고 있다면 쉽게 스크립트를 작성할 수 있습니다. 저는 이 작업을 정확히 한 번 수행하여 한 서버에서 다른 서버로 약 60명의 사용자를 마이그레이션했습니다. 그리고 그것은 합리적으로 잘 작동했습니다. 또한 비슷한 거래인 그룹 권한을 교체해야 했습니다.

chown --from=oldguy newguy * -R
chown --from=:friends :family * -R

그런 것. 이것을 사용할 수 있기를 바랍니다.

답변3

하나의 명령으로는 이 작업을 수행할 수 없습니다. 그러나 사용자가 100명 이상인 경우에도 작업을 자동화하는 것은 매우 간단하므로 왜 하나의 명령이어야 한다고 주장하는지 모르겠습니다.

당신은당기다이 시나리오에서는 대상 컴퓨터의 데이터입니다. 이론적 으로 훨씬 더 복잡한 rsync역방향 터널을 통해 터널링하여 소스 서버에서 전송을 구동하는 것이 가능합니다 .ssh

for testdir in /home/sub*/test1
do
    owner=$(stat -c %u "$testdir")
    rsync -avP --chown "$u" sourceserver:"$testdir"/ "$testdir"/
done

플래그가 없으면 --chown다음 두 단계 프로세스로 이를 에뮬레이트할 수 있습니다.

for testdir in /home/sub*/test1
do
    owner=$(stat -c %u "$testdir")
    rsync -avP --no-owner sourceserver:"$testdir"/ "$testdir"/
    chown -R "$u" "$testdir"                   # If possible
    # find "$testdir" -exec chown "$u" {} +    # Otherwise
done

find변형을 사용해야 하는데 find이해하지 못하는 경우 +약간 덜 효율적인 변형 \;(백래시 세미콜론)으로 바꾸십시오.

관련 정보