http://samba.org/rsync/
http://www.wangsy.com/linux/rsync/
1. Rsync란?
Network을 통해서 데이터 백업을 하는 툴이다. 기존 RCP를 보완하고, 현재 SCP(SSH)를 통해서 보안을 유지할 수 있다.
이 command는 웹 서버의 부하를 분산하기 위해서 remote sync(copy)를 하기 위한 용도로 개발되었다.
l RSYNC Memory 사용 비율
File당 100byte의 메모리가 소요된다. 파일 사이즈에 상관없이 파일 수에 의존하며
1000,000 files이 있을 경우 100Mbyte의 메모리가 소요된다. 또한 option에 따라서 메모리가 더 소요될 수 있다.
l 서비스 설정의 기본 1. 서비스 포트: 873 2. 내부 사용 Shell (RSH,SSH) 초기 configuration에서 선택 적용할 수 있다. 현재 Default로 Remote shell은 SSH를 적용하고 있다. 3. /etc/rsyncd.conf, 각종 rsync option을 설정해 주는 부분이다.
l RSYNC에서 사용되는 Algorithm의 구성 1. Rolling Checksum (16-bit hash of the 32-bit rolling checksum) 2. Checksum searching 은 3단계에 나누어서 데이터를 비교한다.
l RSYNC 란 무엇인가? ”rsync Algorithm”을 사용해서 원격지 파일을 가장 빠른 방법으로 가져오게 된다. 단순히 건너편 원격지의 파일 차이점만을 보내는 것에 의해 운영이 된다. 전체 파일정보를 가져와서 처리하는 것이 없이 진행 된다. 이것은 언뜻 보기에 두개의 파일을 local access하는 것 없이 파일 비교를 한다는 것이 이해가 안될지 모르지만 “rsync Algorithm”을 확인하면 이것이 가능하다는 것을 알 수 있다.
l RSYNC Server 취약성 점검 1. netstat를 사용해서 현재 TCP port 873을 점검한다. 아무런 값이 없다면 rsync server가 동작하지 않는 것이다.
2. Rsync Algorithm
알파서버 그리고 베타서버가 있다고 가정한다. 알파서버는 파일 A에 access하고 베타서버는 파일 B에 access한다. 그리고 그 파일 두개는 “similar”하다. 두 서버사이는 느린 네트워크로 연결되어 있다. (느린 네트워크에서 동작한다는 가정 하에 진행)
Checksum만을 가지고서 변경된 블록과 동일한 블록에 대한 reference만을 전송하는 것으로 네트워크 속도가 느린 환경에서 변경된 데이터의 빠른 복사가 가능하게 된다.
The rsync algorithm consists of the following steps:
1) 베타 서버가 S bytes의 overlapping되지 않은 고정된 블록사이즈에 연속으로 file B를 분할한다. (S bytes는 500~1000사이의 가장 최적의 상태)
2) 베타 서버에서는 이들 블록을 두개의 checksum으로 계산한다. Rolling 32-bit checksum, strong 128-bit MD4 checksum으로 계산한다.
3) 베타 서버가 알파서버에게 이들 checksum값을 전송한다.
4) 알파서버는 B블록의 하나를 가지고서 동일한 weak checksum과 strong checksum을 가진 S bytes 길이의 모든 블록을 파일 A에서 찾는다. 이것은 rolling checksum의 특수한 성질을 이용해서 가장 빠른 single pass로 진행된다.
5) 알파서버는 베타에게 A파일 copy를 구성하기위한 instruction을 보낸다. 각각의 instruction은 B의 블록 reference또는 문자데이타이다. 문자데이터는 B블록과 일치하지 않는 A의 부분들로 전송된다. (전송될 때는 checksum과 Block index들을 위한 작은 양의 데이터를 포함한다).
결과적으로 베타서버는 A를 복사해서 가지게 된다. 이것은 B에서 발견되지 않은 A의 부분들에 한정해서다. 그리고 이 Algorithm은 네트워크 부하를 최소화하기 위해서 단지 한번의 round trip만을 사용해서 전송한다.
참고)
파일의 변경부분만을 가지고서 변경 블록만을 전송하는 방식이 실제 데이터의 consistency를 보장하지는 못한다. 변경된 파일이 있을 경우 이 파일을 전체 전송하는 방식이 아니기 때문에 전송 중에 네트워크 장애로 인한 또는 Checksum 에러로 인한 파일 데이터의 consistency를 보장할 수 없다.
2.1 RSYNC Algorithm Picture1.
전제: 두개 파일 A와 B는 유사하다.

TITLE:
HOW TO USE RSYNC
CONTENTS:
http://samba.org/ftp/rsync/rsync-2.6.0.tar.gz
[root@quest root]# tar -xvzf rsync-2.6.0.tar.gz
[root@quest rsync-2.6.0]# ./configure
[root@quest rsync-2.6.0]# make
[root@quest rsync-2.6.0]# make install
mkdir -p /usr/local/bin
/usr/bin/install -c -m 755 rsync /usr/local/bin
mkdir -p /usr/local/man/man1
mkdir -p /usr/local/man/man5
/usr/bin/install -c -m 644 ./rsync.1 /usr/local/man/man1
/usr/bin/install -c -m 644 ./rsyncd.conf.5 /usr/local/man/man5
[root@quest rsync-2.6.0]#
[acl지원되는 최신 버전]
rsync-2.5.6.tar.gz
rsync-2.5.6-acl-2.diff.gz
[NOTE]
rsync-2.6.0은 default로 ssh를 사용한다. 기존의 rcp를 사용하기 위해서는 configuration
을 재구성해야 한다.
**********************************************************************
* As of v2.6.0, the default remote shell is ssh instead of rsh!! *
* To use previous default of rsh: ./configure --with-rsh=rsh *
**********************************************************************
rsync 2.6.0 configuration successful
[Installation]
현재 테스트는 rpm버전으로 진행을 했다.
rpm버전은 다음과 같다.
[root@quest data]# rpm -qa rsync
rsync-2.5.5-4
[root@quest data]# rpm -ql rsync
/etc/xinetd.d/rsync
/usr/bin/rsync
/usr/share/doc/rsync-2.5.5
/usr/share/doc/rsync-2.5.5/COPYING
/usr/share/doc/rsync-2.5.5/README
/usr/share/doc/rsync-2.5.5/tech_report.tex
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz
모든 설정은 백업할 서버와 백업대상 서버가 동일하다.
백업서버: BS -- backup server
백업소스서버: SU -- Source server(백업할 데이타가 있는 서버)
1. rsync
/etc/xinetd.d/rsync
disable = yes를 no로 바꾼다.
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
2. /etc/services
rsync의 port를 추가한다.
rsync 873/tcp # rsync
rsync 873/udp # rsync
3. host.allow
/etc/hosts.allow 를 설정한다.
BS(backup server)가 각각 백업할 데이터가 있는 서버(SU)에 접근할 수 있도록
각 SU서버에서 host.allow에 BS의 IP를 넣어 준다.
rsyncd : 1.2.3.182, local
4. xinetd의 재시작.
/etc/rc.d/init.d/xinetd restart
5. rsyncd.conf 파일의 생성.
백업소스가 있는 서버(SU)에서 /etc/rsyncd.conf를 생성한다.
내용은 /home/backup/data밑에 있는 곳을 원본 소스로 지정한다는 내용이다.
접근은 read only로 되어 있다 왜냐하면 파일이 read만 될 것이기 때문이다.
timeout은 접속되어 있는 시간을 말하는데 시간이 너무작게 되어 있을 경우에
전송이 timeout error가 발생할 수도 있다.
max connections은 연결하는 동시 접속 숫자이다.
[quest]
path = /home/backup/data
comment = Source-Server
uid = nobody
gid = nobody
use chroot = yes
read only = yes
hosts allow = 1.2.3.182
max connections = 2
timeout 600
6. 실행.
실행은 BS(백업서버)에서 실행하게 된다.
옵션에서
-a는 achive mode로 기존 속성이 넘어간다는 이야기이다.
-v는 verbose mode로서 작업내용을 상세하게 보여준다.
-z는 전송속도를 높이기 위해 압축수행 후 전송을 한다는 이야기 이다.
설정자료에 보면 압축을 할 경우 파일 사이즈가 크면 전송이 잘 안될 수도 있다
이럴 경우에는 z 옵션을 제거한다.
-r는 --recursive
This tells rsync to copy directories recursively. If you don't
specify this then rsync won't copy directories at all.
rsync -avz 1.2.3.184::quest/ /home/backup/data
rsync -avz foo:src/bar /data/tmp
rsync -avz foo:src/bar/ /data/tmp
rsync -Cavz . arvidsjaur:backup
SUB TITLE:
HOW TO MAKE rsyncd.conf
CONTENTS:
EXAMPLE1)
A simple rsyncd.conf file that allow anonymous rsync to a ftp area at /home/ftp would be:
[ftp]
path = /home/ftp
comment = ftp export area
A more sophisticated example would be:
uid = nobody
gid = nobody
use chroot = no
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
[ftp]
path = /var/ftp/pub
comment = whole ftp area (approx 6.1 GB)
[sambaftp]
path = /var/ftp/pub/samba
comment = Samba ftp area (approx 300 MB)
[rsyncftp]
path = /var/ftp/pub/rsync
comment = rsync ftp area (approx 6 MB)
[sambawww]
path = /public_html/samba
comment = Samba WWW pages (approx 240 MB)
[cvs]
path = /data/cvs
comment = CVS repository (requires authentication)
auth users = tridge, susan
secrets file = /etc/rsyncd.secrets
The /etc/rsyncd.secrets file would look something like this:
tridge:mypass
susan:herpass
EXAMPLE2)
The contents of a /etc/rsyncd.conf file may be:
#### rsyncd.conf file ####
uid = username
gid = usergid
pid file = /etc/rsyncd.pid
syslog facility = daemon
[modulename] #Module name could be any name
path = /path/to/yourdata
comment = user related any info
auth users = anonymous username
hosts allow = x.x.x.x
secrets file =/etc/rsyncd.secrets
max connection = 0
use chroot = true
timeout = 60
#### End of configuration file ####
EXAMPLE3)
[dell]
path = /home/backup/data
comment = Source-Server
uid = nobody
gid = nobody
use chroot = yes
read only = yes
hosts allow = 1.2.3.182
max connections = 2
timeout 600
If you have a problem with scripts or cron jobs that produce stderr
then I suggest you use your shell to redirect stderr and stdout.
For example you could do a cron line like this:
0 0 * * * /usr/local/bin/rsync -avz /foobar /foo > logfile 2>&1
this would send both stderr and stdout to "logfile".
The magic bit is the "2>&1" which says to redirect stderr to
to the same descriptor to which stdout is currently directed.
rsync는 전체 OS를 다 지원한다고 보면 됩니다.
아래의 binaries사이트는 실제 rsync 바이너리 파일입니다.
바이너리가 맞지 않을 경우에는 rsync source가 제공되므로 각 OS에서 컴파일 해서
사용하는 것이 좋을 것 같습니다.
그렇다면 O/S에 컴파일러가 없는지 있는지도 확인을 해야 할 것 같습니다.
http://samba.org/ftp/rsync/binaries/
| Index of /ftp/rsync/binaries |
HP-UX NOTES -----------
The HP-UX 10.10 "bundled" C compiler seems not to be able to cope with ANSI C. You may see this error message in config.log if ./configure fails:
(Bundled) cc: "configure", line 2162: error 1705: Function prototypes are an ANSI feature.
Install gcc or HP's "ANSI/C Compiler".
MAC OSX NOTES -------------
Mac OS X (Darwin) seems to have an IPv6 stack, but it does not completely implement the "New Sockets" API.
<http://www.ipv6.org/impl/mac.html> says that Apple do not support IPv6 yet. If your build fails, try again with --disable-ipv6.
IBM AIX NOTES -------------
IBM AIX has a largefile problem with mkstemp. See IBM PR-51921. The workaround is to append the below to config.h #ifdef _LARGE_FILES #undef HAVE_SECURE_MKSTEMP #endif
[참고]
http://samba.org/rsync/FAQ.html
yes, rsync uses a lot of memory. The majority of the memory is used to hole the list of files being transferred. This takes about 100 bytes per file, so if you are transferring 800,000 files then rsync will consume about 80M of memory. It will be higher if you use -H or --delete. To fix this requires a major rewrite of rsync. I do plan on doing that, but I don't know when I'll get to it. The usual reason for "out of memory" when running rsync is that you are transferring a _very_ large number of files. The size of the files doesn't matter, only the total number of files. As a rule of thumb you should expect rsync to consume about 100 bytes per file in the file list. This happens because rsync builds a internal file list structure containing all the vital details of each file. rsync needs to hold structure in memory because it is being constantly traversed. I do have a plan for how to rewrite rsync so that it consumes a fixed (small) amount of memory no matter how many files are transferred, but I haven't yet found a spare week of coding time to implement it!
> Why does rsync produce some things on stdout and some on stderr?
All messages which originate from the remote computer are sent to stderr. All informational messages from the local computer are sent to stdout. All error messages from the local computer are sent to stderr.
There is a reason to this system, and it would be quite difficult to change. The reason is that rsync uses a remote shell for execution. The remote shell provides stderr/stdout. The stdout stream is used for the rsync protocol. Mixing error messages into this stdout stream would involve lots of extra overhead and complexity in the protocol because each message would need to be escaped, which means non-messages would need to be encoded in some way. Instead rsync always sends remote messages to stderr. This means they appear on stderr at the local computer. rsync can't intercept them.
If you have a problem with scripts or cron jobs that produce stderr then I suggest you use your shell to redirect stderr and stdout. For example you could do a cron line like this:
0 0 * * * /usr/local/bin/rsync -avz /foobar /foo > logfile 2>&1
this would send both stderr and stdout to "logfile". The magic bit is the "2>&1" which says to redirect stderr to to the same descriptor to which stdout is currently directed.
|