1. rsync 기본 사용법
rsync -av 소스경로 저장경로
rsync -av /var/log/ /home/data/
root@com1:/home/data# rsync -av /var/log/ /home/data/ sending incremental file list ./ auth.log btmp chrony/measurements.log chrony/statistics.log chrony/tracking.log nova/nova-compute.log
sent 84,105,327 bytes received 160 bytes 168,210,974.00 bytes/sec total size is 153,421,880 speedup is 1.82
옵션 : -v : verbose
-r : recurisively 데이터 복사
-a : archive mode , 심볼릭 링크, 유저,그룹,권한, timestamp 복제
-z : 파일 데이터 압축
2. 특정 폴더 파일 제외 설정
옵션 : --exclude '폴더' --exclude '파일명' --exclude '*.log'
rsync -av --exclude 'apt' /var/log/ /home/data/
root@com1:/home/data# rsync -av --exclude 'apt' /var/log/ /home/data/ sending incremental file list ./ alternatives.log auth.log auth.log.1 auth.log.2.gz bootstrap.log btmp dmesg dpkg.log faillog kern.log kern.log.1 kern.log.2.gz lastlog syslog syslog.1 syslog.2.gz syslog.3.gz syslog.4.gz syslog.5.gz syslog.6.gz syslog.7.gz wtmp
sent 153,252,964 bytes received 1,178 bytes 102,169,428.00 bytes/sec total size is 153,211,199 speedup is 1.00
3. 동기화 기능 (원본폴더의 file, 폴더 삭제시 복사본에서도 삭제)
sent 84,094,820 bytes received 266 bytes 56,063,390.67 bytes/sec total size is 153,644,716 speedup is 1.83
4. 진척도 확인
옵션 : --progress, -P
root@com1:/home/data# rsync -av --progress /var/log/ /home/data/
root@com1:/home/data# rsync -av -P /var/log/ /home/data/
root@com1:/home/data# rsync -av --progress /var/log/ /home/data/ sending incremental file list auth.log 4,249,723 100% 148.95MB/s 0:00:00 (xfr#1, to-chk=72/75) btmp 79,631,616 100% 204.15MB/s 0:00:00 (xfr#2, to-chk=68/75) chrony/measurements.log 115,676 100% 303.67kB/s 0:00:00 (xfr#3, to-chk=39/75) chrony/statistics.log 106,116 100% 261.03kB/s 0:00:00 (xfr#4, to-chk=36/75) chrony/tracking.log 94,644 100% 232.81kB/s 0:00:00 (xfr#5, to-chk=33/75) nova/nova-compute.log 237,636 100% 581.62kB/s 0:00:00 (xfr#6, to-chk=7/75)
sent 84,458,379 bytes received 157 bytes 168,917,072.00 bytes/sec total size is 153,774,944 speedup is 1.82
5. 원격지 서버 ssh 이용한 rsync
rsync -av 원본 계정@IP:폴더
root@control:/home/user# rsync -av /var/log root@com1:/home/data/ sending incremental file list log/auth.log log/btmp
sent 62,954 bytes received 76,833 bytes 55,914.80 bytes/sec total size is 198,302,390 speedup is 1,418.60
일반 rsync 사용시 :: 사용, ssh 사용시 :
6. ssh 포트가 22번이 아닌 경우
rsync -avz -e "ssh -p $portNumber"user@remoteip:/path/to/files/ /local/path/
7. 백업에 사용시
a. ssh-keygen 을 통한 원격 서버 로그인 설정
c. remote 서버의 file 이 압축되어 있을 경우 z 사용안함.
|