rsync는 특정 파일을 제외한 모든 것을 제외합니다.

rsync는 특정 파일을 제외한 모든 것을 제외합니다.

특정 파일을 제외한 모든 파일을 제외하는 방법은 무엇입니까 rsync?

rsync일부 특정 파일(예: 파일)을 제외한 모든 파일을 제외하기 위해 를 사용하여 특정 파일만 백업하려고 시도했지만 .md이 페이지의 모든 솔루션이 작동하지 않았습니다.

$ rsync -vua --exclude="*" --include="*.md" ../log ./
sending incremental file list

sent 19 bytes  received 12 bytes  62.00 bytes/sec
total size is 0  speedup is 0.00

$ rsync -vua --include="*.md" --exclude="*" ../log ./
sending incremental file list

sent 19 bytes  received 12 bytes  62.00 bytes/sec
total size is 0  speedup is 0.00

$ du -sh ../log
1016M   ../log

$ apt-cache policy rsync
rsync:
  Installed: 3.2.7-0ubuntu0.22.04.2
  Candidate: 3.2.7-0ubuntu0.22.04.2
  Version table:
 *** 3.2.7-0ubuntu0.22.04.2 500
        500 http://ca-toronto-1-ad-1.clouds.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
        100 /var/lib/dpkg/status
     3.2.3-8ubuntu3 500
        500 http://ca-toronto-1-ad-1.clouds.archive.ubuntu.com/ubuntu jammy/main amd64 Packages

답변1

나는 당신이 아래 어디에서나 파일을 복사하고 싶다고 가정합니다 ../log.

이름이 --include또는 --exclude패턴과 일치하면 명령줄의 나머지 패턴은 사용되지 않습니다("첫 번째 일치 항목이 승리함"). */패턴과 일치하지 않으면 절대 반복되지 않습니다 --include.

*.md이러한 고려 사항을 염두에 두고 일치 및 일치 전에 다음을 수행 */하세요.--include*--exclude

rsync --archive --update --verbose --include='*.md' --include='*/' --exclude='*' ../log .

빈 디렉토리를 생성하지 않으려면 -m또는를 추가하세요.--prune-empty-dirs

답변2

옵션은 왼쪽에서 오른쪽으로 적용되므로 항목을 먼저 포함하고 나머지 항목을 제외해야 합니다.

rsync -av --include '*.md' --include '*/' --exclude '*' --prune-empty-dirs src/ dst/

여기에는 하위 디렉터리를 포함하여 원하는 파일이 포함되지만(일치하는 항목을 찾기 위해 드릴다운할 수 있음) 다른 모든 파일은 제외됩니다. 결국 비어 있게 되는 디렉터리도 건너뜁니다.

관련 정보