rsync를 사용하여 기본적으로 파일을 제외하는 방법은 무엇입니까?

rsync를 사용하여 기본적으로 파일을 제외하는 방법은 무엇입니까?

rsync를 사용하여 기본적으로 파일을 제외하는 방법은 무엇입니까? 일반적인 rsync 구문이 시작되는 방법은 다음과 같습니다.

rsync --exclude ".ht*" --exclude "error_log" --exclude ".DS*" --exclude "old" ...

구성 파일에 대해 많은 언급을 보았지만 /etc/rsyncd.conf이는 rsync 명령보다 데몬에 더 구체적일 수 있습니다.

위의 기본 구문과 같이 명령줄에서 호출할 때 rsync에 대한 몇 가지 기본 제외를 수행할 수 있습니까?

답변1

파일에 제외를 추가하고 --exclude-from=/path/to/exclude_file을 사용하십시오.

예를 들어

# cat rsync.excludes
.ht*
error_log
.DS*
old
...

# rsync --exclude-from=rsync.excludes

답변2

아니요, rsync호출 시 읽혀지는 기본 구성 파일이 없습니다. 당신이 할 수 있는 가장 좋은 방법은 @frogstarr78이 말한 대로 제외하려는 패턴, 파일 및 디렉터리 이름이 포함된 텍스트 파일을 만든 rsync다음 --exclude-from=filename.

답변3

rsync에서는 기본 옵션을 설정할 수 없지만 래퍼 스크립트를 생성하여 rsync 바이너리보다 $PATH에 더 높은 위치에 배치할 수 있습니다.

이것은 내 rsync 래퍼입니다.~/bin/rsync

#!/bin/sh

# Set path to the rsync binary
RSYNC=/usr/bin/rsync

# Look for these exclude files
IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)

EXCLUDE_FROM=""
for f in ${IGNORE_FILES[@]}; do
  if [[ -e $f ]]; then
    EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
  fi
done
$RSYNC $EXCLUDE_FROM "$@"

~/.rsyncignore, ./.gitignore, 파일을 찾아 ./.rsyncignore해당 파일이 있으면 기본 --exclude-from매개변수로 사용합니다.

환경과 기본 설정에 맞게 RSYNC 및 IGNORE_FILES를 변경하면 됩니다.

답변4

--exclude "/*"는 기본적으로 모든 것을 제외합니다. 예는 다음과 같습니다.

rsync -av --include "bin/" --exclude "/*"/source_dir//dest_dir/

관련 정보