ftp로 원격서버의 데이터 자동백업 > 리눅스 Tip

본문 바로가기
 

ftp로 원격서버의 데이터 자동백업

페이지 정보

작성자 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 9,343회 작성일 12-01-13 18:30

본문

ftp로 원격서버의 데이터 자동백업
scrap.gif
 

icon01.gif title22.gif

서버2에서 서버1의 데이터를 FTP로 가져와 백업하기

작업내용 : 서버2에서 매일(/etc/cron.daily/autoftp) 서버1로 ftp접속을 하여(/home/sspark/.autoftp.sh, /home/sspark/.ftpscript) 백업할 데이터들을 가져온후에 서버2에 날짜형식을 가진 디렉토리를 생성하여 저장하고, 서버1의 원본데이터는 삭제한다.

서버1에서는 매일매일 백업일 하기위해 /etc/cron.daily/NICE-daily-backup에서 /sbin/NICEBACKUP파일을 실행시켜 이 파일에 있는 내용대로 매일매일 백업이 되고 있다.

 

 

서버1에서 매일 백업되는 내용

다음과 같이 서버1의 /sbin/NICEBACKUP에는 백업해야할 내용에관한 명령어들이 들어있다.

[root@kebia_1 /root]# cat /sbin/NICEBACKUP
#!/bin/bash
#APACHE Server BACKUP
tar cvfpz /home/sspark/BACKUP/usr_local_apache.tar.gz /usr/local/apache
#Mysql DB Full BACKUP
tar cvfpz /home/sspark/BACKUP/usr_local_mysql.tar.gz /usr/local/mysql
#Filesystem BACKUP
tar cvfpz /home/sspark/BACKUP/etc.tar.gz /etc
tar cvfpz /home/sspark/BACKUP/var.tar.gz /var
tar cvfpz /home/sspark/BACKUP/home.tar.gz /home
#Mysql file BACKUP
/usr/local/mysql/bin/mysqldump -uroot -p11111 mysql > /home/sspark/BACKUP/mysql.sql
/usr/local/mysql/bin/mysqldump -uroot -p11111 kebia > /home/sspark/BACKUP/kebia.sql
chown -R sspark:sspark /home/sspark/BACKUP

아래와 같이 서버1에는 위의 백업을 매일 하기위해 /etc/cron.dailly에 NICE-daily-backup이란 파일이 존재한다.

[root@kebia_1 /root]# cat /etc/cron.daily/NICE-daily-backup
echo "NICE KOREA BACKUP"
echo `date`
/sbin/NICEBACKUP
echo "BACKUP is completed"
[root@kebia_1 /root]#

 

서버1에는 매일 아래 디렉토리에 다음과 같이 백업이 되고 있다.

[root@kebia_1 BACKUP]# pwd
/home/sspark/BACKUP
[root@kebia_1 BACKUP]# ll
-rw-r--r--    1 sspark   sspark    1514583 Apr  1 04:04 115.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark       9263 Apr  1 04:05 chapter.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark   12996153 Apr  1 04:05 e-gain.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark     556780 Apr  1 04:04 etc.tar.gz
-rw-r--r--    1 sspark   sspark    2007684 Apr  1 04:04 imt-2000.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark   11236021 Apr  1 04:04 nicekorea.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark      32128 Apr  1 04:04 owner.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark    2150591 Apr  1 04:04 picasso.co.kr.tar.gz
-rw-r--r--    1 sspark   sspark    3624831 Apr  1 04:04 sajik.com.tar.gz
-rw-r--r--    1 sspark   sspark   94379928 Apr  1 04:04 usr_local.tar.gz
-rw-r--r--    1 sspark   sspark    4471105 Apr  1 04:04 var.tar.gz
[root@kebia_1 BACKUP]#

 

 

서버2에는 서버1의 데이터를 매일 가져오기위해 /etc/cron.daily에서 매일실행하는 스크립트 autoftp가 아래와 같이 있다.

[root@kebia_2 /root]#
[root@kebia_2 /root]# cat /etc/cron.daily/autoftp
#!/bin/bash
/home/sspark/.autoftp.sh
[root@kebia_2 /root]#

 

서버2에 만들어져야할 파일2개

  autoftp.sh : ftp실행파일

  ftpscript : ftp명령어들

 

[root@kebia_2 sspark]# cat autoftp.sh
#!/bin/bash
ftp -n 211.220.193.181 < ./ftpscript
export backupdir=`date '+%y-%m-%d.%H-%M'`
mkdir /home/sspark/BACKUP/$backupdir
mv /home/sspark/tmp/* /home/sspark/BACKUP/$backupdir

[root@kebia_2 sspark]#

 

[root@kebia_2 sspark]# cat ftpscript
user sspark 11111
cd /home/sspark/BACKUP
lcd /home/sspark/tmp
bin
prompt
mget *.tar.gz
mdelete *.tar.gz
bye

[root@kebia_2 sspark]#

 

서버1에는 cron.daily에 /sbin/NICEBACKUP등으로 매일 또는 매주 또는 매월백업을 자동으로 되고 있어야한다.
서버1의 /home/sspark/BACKUP/200104010303 형식으로 디렉토리를 생성하게되어 저장된다.
그런후에는 서버1의 데이터를 삭제한다.

 

작업완료후에 서버2에는 서버1의 내용이 백업되어 있다.

 

[root@kebia_2 01-04-01.05-45]# pwd
/home/sspark/BACKUP/01-04-01.05-45
[root@kebia_2 01-04-01.05-45]# ll
-rw-r--r--    1 root     root      1514583 Apr  1 05:36 115.co.kr.tar.gz
-rw-r--r--    1 root     root         9263 Apr  1 05:36 chapter.co.kr.tar.gz
-rw-r--r--    1 root     root     12996153 Apr  1 05:37 e-gain.co.kr.tar.gz
-rw-r--r--    1 root     root       556780 Apr  1 05:37 etc.tar.gz
-rw-r--r--    1 root     root      2007684 Apr  1 05:37 imt-2000.co.kr.tar.gz
-rw-r--r--    1 root     root     11236021 Apr  1 05:38 nicekorea.co.kr.tar.gz
-rw-r--r--    1 root     root        32128 Apr  1 05:38 owner.co.kr.tar.gz
-rw-r--r--    1 root     root      2150591 Apr  1 05:38 picasso.co.kr.tar.gz
-rw-r--r--    1 root     root      3624831 Apr  1 05:38 sajik.com.tar.gz
-rw-r--r--    1 root     root     94379928 Apr  1 05:45 usr_local.tar.gz
-rw-r--r--    1 root     root      4471105 Apr  1 05:45 var.tar.gz
[root@kebia_2 01-04-01.05-45]#

 

서버2에서 ftp접속 및 작업이 끝난후 서버1의 내용(즉, 원본파일은 지워지게 된다.)

[root@kebia_1 BACKUP]# pwd
/home/sspark/BACKUP
[root@kebia_1 BACKUP]# ll
[root@kebia_1 BACKUP]# 

댓글목록

등록된 댓글이 없습니다.

Total 138건 2 페이지
리눅스 Tip 목록
번호 제목 글쓴이 조회 날짜
120 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 19506 06-05
119 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 17643 06-05
118 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 10974 04-06
117 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 11091 04-05
116 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 11867 04-04
115 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14789 04-04
114 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15344 03-12
113 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 11992 01-30
112 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 19761 01-13
111 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15844 01-13
110 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 20814 01-13
109 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15016 01-13
열람중 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 9344 01-13
107 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14975 01-13
106 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 9944 10-14
105 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15408 09-07
104 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 20847 09-07
103 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15070 09-07
게시물 검색