티스토리 뷰

IT/OS

ssh와 rsync를 이용한 백업

NineKY 2007. 7. 6. 17:32

ssh rsync를 이용한 백업

 rsync rsh ssh 같은 인증 서비스를 이용하여 서버 클러스터링이나 백업을 할수 있는 데몬이며, 주로 서버 클러스터링으로 여러대의 서버를 운영하는 경우 각 호스트 간의 자료를 공유하는데 사용됩니다.

 

관련파일

/etc/xinetd.d/rsync

xinetd에서 실행되는 데몬 설정파일

/usr/bin/rsync

Rsync 실행파일 위치

/etc/ssh/ssh_config

Ssh 설정파일

/usr/bin/ssh

Ssh 실행파일 위치

/root/.ssh/

SSH 인증키

 

SSH설정

백업서버에서 대상서버로 접속시 root password 대신 ssh의 인증키를 활용하는 방법.

백업서버에서 인증키를 생성하여 대상서버로 보낸다.

[root@localhost ]# ssh-keygen -d

Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa): à 엔터

Enter passphrase (empty for no passphrase): à 엔터

Enter same passphrase again:  à 엔터

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

19:a2:d9:8b:4c:db:85:62:1d:78:46:46:10:24:a2:33 root@localhost.localdomain

[root@localhost .ssh]# pwd

/root/.ssh

[root@localhost .ssh]# ls

authorized_keys  id_dsa  id_dsa.pub  id_rsa  id_rsa.pub  known_hosts

 à root아래 .ssh/id_dsa  /.ssh/id_dsa.pub 라는 파일이 생성됨.

 두 파일을 대상서버의 /root/.ssh/ 아래로 카피한다.

접속 테스트
[root@localhost home]# ssh 192.168.3.222

Last login: Sat Nov  4 12:02:07 2006 from 192.168.3.174

 

rsync클라이언트로 서버 동기화

 형식 : ‘rsync –av 원격지 : rsync서비스명 /로컬서버경로

[root@localhost home]# rsync -avPz --stats -l -t -e ssh root@192.168.3.222:/home /home

receiving file list ...

6 files to consider

 

Number of files: 6

Number of files transferred: 0

Total file size: 6609096 bytes

Total transferred file size: 0 bytes

Literal data: 0 bytes

Matched data: 0 bytes

File list size: 144

Total bytes sent: 16

Total bytes received: 160

 

sent 16 bytes  received 160 bytes  352.00 bytes/sec

total size is 6609096  speedup is 37551.68

  à 192.168.0.1의 홈디렉토리의 파일을 로컬서버의 /home/sshclient아래로 압축전송 합니다.

 

옵션

-v

verbose(상세출력)

-a

archive mode

-u

update only(새로운 파일을 덮어쓰지 않음)

--delete

서버쪽에 없고 클라이언트 쪽에만 있는 파일을 지움

-z

compress(전송시 압축함)

--daemon

데몬모드로 운영함(inetd.conf에 지정할 때 필요)

-r

recursive(하위디렉토리 까지 포함)

-l

심볼릭 링크 재 생성

-p

퍼미션 업데이트

-t

변경시간 전송(표기 않으면 전송한 시간으로 바뀜)

-g

그룹이름 변경

-e

-e 옵션은 rsh ssh를 사용할때 써주는 옵션입니다. (--password-file 옵션을 사용하시면 암호파일의 위치를 지정해줄수있습니다.)

 

 

crontab 설정

0 4 * * * rsync –avz 192.168.0.1::test /home/gni/test   à 매일 4 동기화

 

 

 
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함