리눅스 / rsync / 동기화 프로그램

rsync는 동기화 프로그램이다. 백업할 때 유용하게 사용할 수 있다.

사용법

기본

  • abc 디렉토리 안의 def 디렉토리를 xyz 디렉토리 안에 동기화시킨다.
  • 처음 실행하는 것이라면 xyz 디렉토리 안에 def 디렉토리가 복사된다.
  • 다시 실행시키면 /abc/def 디렉토리의 내용 중 수정되거나 추가된 것만 /xyz/def 디렉토리로 복사된다.
  • /abc/def에서 삭제된 내용은 /xyz/def에 반영되지 않는다.
# rsync -avz /abc/def /xyz
  • def 뒤에 /를 붙이면 def 디렉토리 안에 있는 폴더와 파일들만 동기화된다. 즉, xyz 디렉토리 안에 def 디렉토리가 생기지 않는다.
# rsync -avz /abc/def/ /xyz

삭제 파일도 동기화하기

  • --delete 옵션을 추가하면, /abc/def에서 삭제된 것은 /xyz/def에서도 삭제된다.
# rsync -avz --delete /abc/def /xyz

특정 디렉토리 제외하기

  • abc 디렉토리 안에 있는 abc-2 디렉토리를 제외하고 동기화한다.
# rsync -avz --exclude 'abc-2' abc xyz

다른 서버와 동기화

  • ssh로 다른 서버에 접속하여 동기화할 수 있다.
  • 도메인 대신 IP를 적어도 되고, 같은 네트워크에 있다면 호스트네임을 적어도 된다.
# rsync -avz --delete -e ssh root@abc.com:/abc/def /xyz
  • ssh 포트를 다른 것으로 사용할 수 있다.
# rsync -avz --delete -e "ssh -p 2345" root@abc.com:/abc/def /xyz

sshpass

  • sshpass를 이용하면 비밀번호 입력을 따로 할 필요가 없다.
# rsync -avz --delete /abc/def --rsh="sshpass -p password ssh -p 2345" root@abc.com:/xyz
같은 카테고리의 다른 글

리눅스 / 명령어

명령어 개요 adduser 사용자 추가하는 명령어. alias 명령어 별칭을 만든다. cal calendar. 달력을 출력하는 명령어. cat concatenate. 파일 내용 출력하는 명령어. cd change directory. 다른 디렉토리로 이동하는 명령어. chmod 파일 또는 디렉토리의 읽기, 쓰기, 실행 권한 설정하는 명령어 chown 파일 또는 디렉토리의 소유자(그룹) 설정하는 명령어 clear 터미널 화면의 내용을 다 지운다. cp copy. 파일 또는 디렉토리 복사. du disk usage. 디스크 사용량 출력. file 파일의 종류를 출력하는 명령어 find 파일 또는 디렉토리를 검색하는 명령어 free 메모리 사용량 ...

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 ...

리눅스 / crontab 사용법

cron & crontab cron은 특정 시간에 특정 작업을 수행하게 하는 시스템 대몬이다. 백업, 캐시 메모리 비우기 등 주기적으로 어떤 작업을 해야할 때 유용하다. crontab은 시간과 작업을 적은 텍스트 파일이다. 사용자별로 파일이 존재한다. cron은 모든 사용자의 crontab 파일을 찾아서, 적혀진 일정대로 작업을 수행한다. 작업 목록 보기 예약 작업 목록을 보고 싶다면 다음과 같이 명령한다. 사용자의 crontab ...

Ubuntu 18.04 / 빠르게 다운로드하는 방법

우분투 다운로드 우분투 다운로드는 보통 우분투 홈페이지에서 합니다. 상단의 Downloads 메뉴를 클릭하고 안내를 따라가면 됩니다. 그런데, 우분투 홈페이지를 통해 다운로드를 받으면 전송 속도가 느릴 수 있습니다. 만약 너무 느리다면 가까운 미러 사이트에 직접 접속하여 다운로드해보세요. 빠르게 다운로드를 할 수 있습니다. 카카오 서버 한국이라면 카카오 서버가 빠릅니다. 우분투 페이지로 간 다음 원하는 버전을 선택합니다. 데스크톱 이미지와 ...

Ubuntu 16.04 Server / PHP / 메모리 늘리는 방법

PHP 설정은 php.ini에서 한다. Ubuntu 16.04에서 php.ini의 위치는 /etc/php/7.0/apache2/php.ini 이다. PHP 버전에 따라 7.0은 다른 숫자일 수 있다. 메모리를 늘리기 위해 수정해야 할 것은 memory_limit이다. 기본값은 128M이다. 128을 적절히 변경한다. memory_limit = 128M 변경한 설정이 적용되도록 하려면 웹서버를 다시 시작하거나 다시 로드한다. Apache 웹서버라면 다음과 같이 명령하여 다시 시작할 수 있고, # service apache2 restart 다음과 같이 ...

CentOS 7 / ntsysv로 부팅할 때 서비스 자동으로 시작하게 하기

CentOS 7 / ntsysv로 부팅할 때 서비스 자동으로 시작하게 하기

서비스 관리는 보통 systemctl 명령어로 합니다. systemctl 명령어의 enable을 이용하면 시스템이 부팅할 때 서비스가 자동으로 시작하게 할 수 있습니다. 예를 들어 systemctl enable httpd.service 는 서버가 부팅할 때 httpd 서비스를 자동으로 시작합니다. 만약 이러한 서비스 관리를 명령어로 하는 불편하다면 ntsysv를 사용해보세요. TUI로 자동으로 시작하는 서비스를 관리할 수 있습니다. 다음과 같이 명령하여 ntsysv 패키지를 설치합니다. yum install ntsysv 다음과 같이 ...

Ubuntu 22.04 Server / NGINX / 설치와 설정

Ubuntu 22.04 Server / NGINX / 설치와 설정

Nginx는 높은 성능과 안정성을 제공하는 웹 서버 소프트웨어로, 웹 서버 외에도 리버스 프록시, 로드 밸런서, 메일 프록시 등의 기능을 수행할 수 있다. Igor Sysoev가 2004년에 처음 개발했으며, 현재는 오픈 소스 소프트웨어로 널리 사용되고 있다. 가정 Ubuntu 22.04 Server의 IP는 192.168.3.242이고, 내 컴퓨터에서 IP로 접근 가능하다. 내 컴퓨터의 OS는 Windows이다. 설치 nginx 패키지 설치 다음과 같이 명령하여 ...

Ubuntu 22.04 Server / SSH / 포트 변경하는 방법

보안 상의 이유로 SSH 포트는 변경하는 것이 좋다. Ubuntu 22.04 Server에서 SSH 포트 변경하는 방법은 다음과 같다. 1980으로 변경한다고 가정한다. /etc/ssh/sshd_config에서 다음의 코드를... #Port 22 다음으로 변경한다. Port 1980 방화벽이 활성화되어 있다면 1980 포트를 열어준다. ufw allow 1980/tcp SSH 서비스를 다시 시작한다. systemctl restart ssh SSH 서비스를 다시 시작해도 적용되지 않으면, 컴퓨터를 다시 시작한다.

리눅스 / 명령어 / rmdir / 빈 디렉토리 삭제하는 명령어

rmdir rmdir은 빈 디렉토리를 삭제하는 명령어이다. Remove the DIRECTORY(ies), if they are empty. 사용법 rmdir directory a 디렉토리를 삭제한다. # rmdir a  비어있다면 삭제를 하고, 그렇지 않다면 다음을 출력한다. rmdir: failed to remove ‘a’: Directory not empty rmdir --ignore-fail-on-non-empty directory 디렉토리가 비어있지 않아도 메시지를 출력하지 않는다. rmdir -v directory 현재 디렉토리 안에 있는 모든 비어있는 디렉토리를 삭제한다. v 옵션을 넣으면 작업 결과를 ...

CentOS 7 / Webmin / 설치하는 방법

CentOS 7 / Webmin / 설치하는 방법

Webmin은 웹브라우저를 통해 시스템 관리를 하는 툴이다. CentOS라면 아래의 순서로 설치할 수 있다. 저장소 추가 webmin 저장소를 추가한다. vi 등 텍스트 에디터로 저장소 파일을 만들고... # vi /etc/yum.repos.d/webmin.repo 아래의 내용을 추가하고 저장한다. name=Webmin Distribution Neutral #baseurl=http://download.webmin.com/download/yum mirrorlist=http://download.webmin.com/download/yum/mirrorlist enabled=1 키 추가 PGP key를 다운로드하고... # wget http://www.webmin.com/jcameron-key.asc 설치한다. # rpm --import jcameron-key.asc 설치와 설정 webmin을 설치한다. # yum install webmin 10000 포트를 열어준다. # firewall-cmd --add-port=10000/tcp 접속 https://<server-ip>:10000으로 접속한다. 공인 인증서가 없으므로, 웹브라우저에 ...