
나는 컴퓨터에서 백업 서버로 폴더와 파일을 백업하기 위해 bash 스크립트를 작성했습니다. 내 목표는 이번 주간 백업에서 6개월이 넘은 모든 파일을 제외하는 것입니다. 이를 위해 find 명령을 사용하여 이러한 파일의 경로가 포함된 txt 파일을 만들었습니다.
find . -type f -mtime -200 -fprintf $SCRIPT_DIR/Exclusions.txt "%P\n"
그런 다음 rsync의 "--include-from" 옵션을 사용했습니다.
rsync . -e ssh -qrtl --exclude-from=$SCRIPT_DIR/Exclusions.txt $USER@$DEST_SRV:$DEST_DIR
결과적으로 백업은 작동했지만 포함되지는 않았습니다. 따라서 6개월이 넘은 파일도 모두 백업되었습니다.
어떻게 해야 합니까?
미리 감사드립니다
답변1
매뉴얼 페이지에 따르면,
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don't exclude files matching PATTERN
--include-from=FILE read include patterns from FILE
제외는 파일 이름 자체에 따르지 않고 파일에서 읽기 패턴으로 이루어집니다.
이름에 따라 파일을 포함/제외하는 것도 소수일 수 있다는 데 동의하지만 이것이 작동하는 방식은 아닙니다.
1주일 전보다 최신 파일을 포함하려면 다음과 같이 시도해 볼 수 있습니다.
--files-from=<(find . -mtime -7 -print0)
답변2
알겠습니다. 문제를 해결했습니다. "찾기" 줄은 동일하게 유지됩니다.
find . -type f -mtime -200 -fprintf $SCRIPT_DIR/includes.txt "%P\n"
그리고 "--exclude-from" 대신 "--files-from" 옵션을 사용합니다.
rsync . -e ssh -qrtl --files-from=$SCRIPT_DIR/includes.txt $USER@$DEST_SRV:$DEST_DIR