rsync에서 전송 된 파일 목록을 가져 오시겠습니까?


14

현재 rsync스테이징에서 프로덕션 서버로 PHP 응용 프로그램을 배포하는 스크립트를 사용하고 있습니다. 방법은 다음과 같습니다.

rsync -rzai --progress --stats --ignore-times --checksum /tmp/app_export/ root@app.com:/var/www/html/app/

현재 비교중인 모든 파일 (프로젝트의 모든 파일) 목록을 출력하고 있지만 수정 된 파일 만 출력하고 싶습니다. 따라서 --dry-run모든 배치가 업데이트되고 있는지 확인 하는 옵션으로 파일을 실행할 수 있습니다 원하는 파일.

참고 : 지금까지 내가 할 수있는 최선 grep fcst의 결과는 있지만 rsync거기에 확실하지만 매뉴얼 페이지에서 찾을 수없는 옵션을 찾고 있습니다.

미리 감사드립니다!

답변:


6

원하는대로 정확하게 수행 할 수있는 rsync 옵션이 있으면 맨 페이지에서도 찾지 못했습니다. :-)

즉, rsync -i필요한 것을 정확하게 파싱하기 위해 출력을 grepping하는 데 문제가있는 것은 아닙니다 . 그것은 기분이 좋고 Unixy입니다.

당신의 rsync를 명령 한 니트 - 까다 롭고 애매한는 다음 -r이 암시 된 바와 같이, 중복입니다 -a.


2
고마워요 나는 왜 (이 프로그램이 가지고있는 다양한 옵션으로) 그에 대한 옵션이 없는지 궁금합니다. 나에게는 매우 기본적 인 것 같습니다.
Mauro

안녕 케빈, 실제로는 옵션이 있습니다. -P진행은 -n드라 이런 설정 에서 정확하게 진행 되지만 -i잘못되지는 않습니다. 아래 답변을 참조하십시오.
Robert Riedl

6

--out-format옵션을 사용하십시오

매뉴얼 페이지에 따르면 :

--out-format옵션을 지정하면 중요한 방식 (전송 된 파일, 재 작성된 symlink / 장치 또는 디렉토리)으로 업데이트되는 각 파일, 디렉토리 등이 언급됩니다.

실제 파일 이름 ( --out-format="%n") 만 필요한 경우 드라이 런 명령은 다음과 같습니다.

rsync -rzan --out-format="%n" --ignore-times --checksum /tmp/app_export/ root@app.com:/var/www/html/app/


rsync가로 호출되면 -v내부적으로이 옵션을 기본 형식 인으로 사용합니다.이 옵션 "%n%L"은 파일 이름과 항목이 링크 인 경우 해당 위치를 알려줍니다.

그러나 여기에는 동기화 프로세스의 시작과 끝에 간단한 요약도 포함됩니다.

해당 요약을 제거하려면 --out-format옵션을 직접 사용하십시오 .

Btw. -i내부적으로를 사용 --out-format하지만 형식은 "%i %n%L"입니다.


3

2013 년에 출시 된 rsync v3.1.0부터는 --info출력을 세밀하게 제어 할 수 있는 플래그가 있습니다.

 --info=FLAGS
          This option lets you have fine-grained control over the information output you want to see.  An individual flag name may be followed
          by a level number, with 0 meaning to silence that output, 1 being the default output level, and higher numbers increasing the output
          of that flag (for those that support higher levels).  Use --info=help to see all the available flag names,  what  they  output,  and
          what flag names are added for each increase in the verbose level.  Some examples:

              rsync -a --info=progress2 src/ dest/
              rsync -avv --info=stats2,misc1,flist0 src/ dest/

          Note  that  --info=names  output  is  affected  by the --out-format and --itemize-changes (-i) options.  See those options for more
          information on what is output and when.

          This option was added to 3.1.0, so an older rsync on the server side might reject your attempts at fine-grained control (if  one  or
          more  flags  needed  to  be  send to the server and the server was too old to understand them).  See also the "max verbosity" caveat
          above when dealing with a daemon.

사용 가능한 --info플래그는 다음과 같습니다.

Use OPT or OPT1 for level 1 output, OPT2 for level 2, etc.; OPT0 silences.

BACKUP     Mention files backed up
COPY       Mention files copied locally on the receiving side
DEL        Mention deletions on the receiving side
FLIST      Mention file-list receiving/sending (levels 1-2)
MISC       Mention miscellaneous information (levels 1-2)
MOUNT      Mention mounts that were found or skipped
NAME       Mention 1) updated file/dir names, 2) unchanged names
PROGRESS   Mention 1) per-file progress or 2) total transfer progress
REMOVE     Mention files removed on the sending side
SKIP       Mention files that are skipped due to options used
STATS      Mention statistics at end of run (levels 1-3)
SYMSAFE    Mention symlinks that are unsafe

ALL        Set all --info options (e.g. all4)
NONE       Silence all --info options (same as all0)
HELP       Output this help message

Options added for each increase in verbose level:
1) COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE
2) BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP

1
감사합니다. Mac을 사용하기 때문에이 플래그가 존재하는지 전혀 몰랐습니다. 최신 MacOS에서도 2004 롤에서 rsync 버전을 설치합니다. 건배 애플 ...
twistedpixel

0

이것이 사용 된 버전 / 옵션간에 확실하지 않지만 옵션을 사용할 때 내 버전 -i에서는 다음과 같은 목록이 표시됩니다.

>f..T...... existing-file.png
>f+++++++++ new-file.png
cd+++++++++ new-dir/
>f+++++++++ new-dir/new-file.png

따라서 실제로 전송 된 파일 목록 만 가져 오는 간단한 솔루션은 다음과 같이 실행하십시오.

rsync [your options here] | grep -v "f..T......"

이것은 단순히를 포함하는 모든 줄을 숨길 것 f..T......입니다. 따라서 효과적으로 동일한 파일을 숨길 수 있습니다.


0

사실, 당신은 원래 명령이 이미 가지고 있기 때문에 당신은 당신의 자신의 질문에 대답했습니다. --progress

매뉴얼 페이지는 약간 비밀 스럽지만 올바른 옵션입니다.

     --progress              show progress during transfer
 -P                          same as --partial --progress

rsync드라 이런 모드로 문자열 을 호출하기 때문에 전송기가 발생하지 않지만 여전히 진행 중입니다. 즉 파일이 변경되어 전송됩니다.

이렇게하면 모든 파일의 깔끔한 작은 목록을 얻을 수 있습니다.

대상에 이미 소스 및 이전 파일에서 업데이트 된 변경된 파일의 사본이 있으며 변경되지 않은 상태로 유지됩니다. 소스에는 추가 파일 인 newfile도 있습니다.

#~$ ls -lhan /tmp/destination/
total 20K
drwxrwxr-x  2 1000 1000 4,0K Jän 31 09:07 .
drwxrwxrwt 18    0    0  12K Jän 31 09:15 ..
-rw-rw-r--  1 1000 1000    2 Jän 31 09:08 changedfile
-rw-rw-r--  1 1000 1000    0 Jän 31 09:07 oldfile



#~$ ls -lhan /tmp/source/
total 20K
drwxrwxr-x  2 1000 1000 4,0K Jän 31 09:07 .
drwxrwxrwt 18    0    0  12K Jän 31 09:15 ..
-rw-rw-r--  1 1000 1000    2 Jän 31 09:15 changedfile
-rw-rw-r--  1 1000 1000    0 Jän 31 09:07 newfile
-rw-rw-r--  1 1000 1000    0 Jän 31 09:07 oldfile

그런 다음 rsync 명령을 호출하지만 항목 화를 제거 -i하고 dryrun을 추가하면-n

#~$ ~$ rsync -n -rza --progress --stats --ignore-times --checksum /tmp/source/ /tmp/destination/
sending incremental file list
changedfile
newfile

Number of files: 4 (reg: 3, dir: 1)
Number of created files: 1 (reg: 1)
Number of deleted files: 0
Number of regular files transferred: 2
Total file size: 2 bytes
Total transferred file size: 2 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 187
Total bytes received: 22

sent 187 bytes  received 22 bytes  418.00 bytes/sec
total size is 2  speedup is 0.01 (DRY RUN)

당신은 rsync가 tranfser 할 파일의 목록을 얻는다 : changedfile과 newfile.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.