rsync 란?

ASHAPPYASIKNOW·2022년 7월 25일
0

OS(Linux, Mac, Windows)

목록 보기
3/9
post-thumbnail

rsync 란?

rsync is a utility for efficiently transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files.

출처: rsync

rsync는 파일의 수정시간 및 사이즈를 비교하여 컴퓨터와 저장 장치 간의 효율적인 파일 전송 및 동기화를 도와주는 유틸리티이다.

전송파일 결정 방식

By default, rsync determines which files differ between the sending and receiving systems by checking the modification time and size of each file. If time or size is different between the systems, it transfers the file from the sending to the receiving system

출처: rsync

송신 시스템을 기준으로 수신 시스템을 비교한다. 파일의 수정시간과 사이즈를 확인하여 다를 경우 송신 측에서 수신 측으로 파일을 전송하게 된다.

사용 예제

아래의 쉘 스크립트는 로그 파일을 네트워크 파일 시스템에 저장하기 위한 스크립트이다.

rsync_log.sh

#!/bin/bash

nowdate=$(date "+%Y-%m-%d %H:%M:%S")
echo "Today is ${nowdate}, cron daemon execution complete." >> /home/ec2-user/rsync_scripts/crond_execution.log

echo 'rsync log ...'
rsync -avzh /srv/my-server/logs/ /efs-my-folder/logs/

크론 데몬(cron daemon)이 실행될 때마다 /home/ec2-user/rsync_scripts/crond_execution.log 에 로그를 남기게 된다.

rsync -avzh 옵션으로 /srv/my-server/logs/에 있는 모든 파일을 /efs-my-folder/logs/ 폴더에 복사한다.

  • 경로에 슬래시(/) 붙여 주어야 경로 아래에 있는 모든 파일이 대상이 된다.
  • 슬래시(/)가 없으면 폴더가 대상이 된다.

rsync 옵션 설명

-v, --verbose: increase verbosity (중간과정을 자세히 보여준다.)
-h --human-readable: output numbers in a human-readable format (출력형태를 사람이 읽을 수 있도록 변경)
-z, --compress: compress file data during the transfer (전송할 때 파일을 압축해서 전송)
-a, --archive: archive mode; equals -rlptgoD (no -H,-A,-X)

rlptgoD 란

-r, --recursive: recurse into directories (서브디렉토리 까지 동기화)
-l, --links: copy symlinks as symlinks (심볼릭 링크 복사)
-p, --perms: preserve permissions (권한 유지)
-t, --times: preserve modification times (파일 수정시간 유지)
-g, --group: preserve group (그룹 정보 유지)
-o, --owner: preserve owner, super-user only (슈퍼유저인 경우 소유자 유지)
-D: same as --devices --specials
--devices: preserve device files, super-user only (슈퍼유저인 경우 device 파일 유지)
--specials: preserve special files (special 파일 유지)

버전 확인 및 설치

설치 버전 확인

> rpm -qa |grep rsync
rsync-3.1.2-4.amzn2.x86_64

설치방법

만약 rsync가 없다면 아래의 명령어로 설치할 수 있음

sudo yum install rsync


REFERENCES

rsync
rsync(1) - Linux man page
Rsync: What is it and How do I Use it?

profile
36.9 It's good time to start something new

0개의 댓글