rsync에서 패턴과 일치하는 모든 디렉토리를 어떻게 제외합니까? branch1, / root / branch2, /

rsync에서 패턴과 일치하는 하위 디렉토리를 제외하려고합니다. 그러나 나는 그것을 작동시킬 수 없다. 여기와 Google에서 찾은 몇 가지 예를 따랐습니다. 그러나 올바른 결과를 얻지 못했습니다. 내 명령의 옵션 비트는 다음과 같습니다.

-avh --exclude 'branch*' --stats --delete --link-dest=$LNK

내 소스 디렉토리 구조는

/root
    /branch1
    /branch2
    /branch3
    /other
    /stillAnother
    /etc

이것은 백업 스크립트의 일부입니다. $ LNK는 전날의 rsync 목적지에 대한 링크입니다.

/ root / branch1, / root / branch2, / root / branch3을 원하지 않습니다. 또는 동기화 할 내용. 그러나 그들은 있습니다.

이미 시도한 제외 비트는 다음과 같습니다.

--exclude=branch*
--exclude='branch*'
--exclude '/branch*'
--exclude /branch*

도움 / 조언에 감사드립니다.

편집- “가능한 중복”플래그를 해결

이 질문 은 알려진 디렉토리 목록에 관한 것입니다. 해당 디렉토리가없는 경우에도 패턴을 따르는 디렉토리를 제외해야합니다. 예를 들어 내 예제에서 다른 디렉토리 /branch*가 추가 될 수 있습니다. 스크립트를 미래에 대비하고 패턴과 일치하는 디렉토리가 추가 될 때 스크립트를 편집하지 않아야합니다. 해당 디렉토리는 임시 디렉토리 일 수 있습니다.



답변

제외 규칙이 맞습니다. 그러나 rsync는 추가 매개 변수없이 대상에서 제외 된 파일을 삭제하지 않습니다 --delete-excluded.

--delete-excluded also delete excluded files from dest dirs

예:

#  tree test
test
|-- 123
|-- branch1
|-- branch2
|-- branch3
`-- other

#  tree test2
test2
|-- 123
|-- branch1
|-- branch2
|-- branch3
`-- other

# rsync -avh test/ test2 --delete --exclude='branch1' --delete-excluded
sending incremental file list
deleting branch1/

sent 140 bytes  received 27 bytes  334.00 bytes/sec
total size is 0  speedup is 0.00

#  tree test2
test2
|-- 123
|-- branch2
|-- branch3
`-- other

3 directories, 1 file


답변

rsync 버전 3.1.3 (이전에는 체크하지 않았을 수 있음)은이 구문을 사용하여 하위 디렉토리를 올바르게 제외합니다 (명확하게 exclude_dirname제외하려는 패턴으로 대체 ).

rsync [other opts...] --exclude='*/exclude_dirname/' /src/ /dst/

와일드 카드에서도 작동합니다. 원래 질문은을 사용 'branch*'하므로 다음과 같이 작동합니다.

rsync [other opts...] --exclude='*/branch*/' /src/ /dst/

도움이 되었기를 바랍니다.


답변