20160429 리눅스 관리자
모의해킹 침해대응 전문가 과정 / 2016. 5. 1. 18:43
=========================================메모=========================================
=========================================복습=========================================
=========================================강의=========================================
=========================================복습=========================================
=========================================강의=========================================
9. 백업과 복구
tar CMD
# tar cvf file.tar file1 file2 file3
# tar tvf file.tar
# tar xvf file.tar
tar CMD
# tar cvf file.tar file1 file2 file3
# tar tvf file.tar
# tar xvf file.tar
# tar cvzf file.tar.gz file1 file2 file3
# tar tvzf file.tar.gz
# tar xvzf file.tar.gz
# tar tvzf file.tar.gz
# tar xvzf file.tar.gz
# tar cvjf file.tar.bz2 file1 file2 file3
# tar tvjf file.tar.bz2
# tar xvjf file.tar.bz2
# tar tvjf file.tar.bz2
# tar xvjf file.tar.bz2
=========================================실습=========================================
[EX4] tar 명령어를 이용한 운영체제 전체 백업
운영체제를 백업하기 위해서 /proc, /mnt, /media, tmp 디렉토리는 포함하지 않아도 된다. 제외할 디렉토리의
경우 ‘--exclude=’로 영역을 지정해준다. 지정된 영역을 제외한 나머지 부분이 ‘<백업파일명>.tar.gz'으로
백업되는 것이다.
경우 ‘--exclude=’로 영역을 지정해준다. 지정된 영역을 제외한 나머지 부분이 ‘<백업파일명>.tar.gz'으로
백업되는 것이다.
(명령어 형식)
# tar cvzpf /backup<백업파일명>.tar.gz --exclude=<제외할 디렉토리> --absolute-name /
# tar cvzpf /backup<백업파일명>.tar.gz --exclude=<제외할 디렉토리> --absolute-name /
# du -sh /
# df -h
# time tar cvzf /RootBackup/full_backup.tar.gz \
> --exclude=/proc \
> --exclude=/tmp \
> --exclude=/media \
> --exclude=/RootBackup \
> --absolute-name /
> --exclude=/proc \
> --exclude=/tmp \
> --exclude=/media \
> --exclude=/RootBackup \
> --absolute-name /
(생략)
/lib/libm.so.6
/lib/libcidn-2.5.so
/lib/libglib-2.0.so.0.1200.3
/lib/libdmraid.so
/lib/libgcc_s.so.1
/lib/libdevmapper-event.so.1.02
/lib/libattr.so.1
/lib/libdbus-1.so.3.4.0
/lib/libpam.so.0
tar: Error exit delayed from previous errors
/lib/libm.so.6
/lib/libcidn-2.5.so
/lib/libglib-2.0.so.0.1200.3
/lib/libdmraid.so
/lib/libgcc_s.so.1
/lib/libdevmapper-event.so.1.02
/lib/libattr.so.1
/lib/libdbus-1.so.3.4.0
/lib/libpam.so.0
tar: Error exit delayed from previous errors
real 11m1.348s
user 3m17.448s
sys 0m56.964s
user 3m17.448s
sys 0m56.964s
rsync 서비스를 이용한 백업
(1) rsync 서비스를 이용한 로컬 데이터 백업 및 서버 동기화
여러 대의 서버를 분산하여 서버 데이터를 동기화하는데 rsync 유틸리티가 많이 사용된다. rsync는 루트 권한없 이 서버로부터 데이터로 빠르게 전송받을 수 있으며, 원격 서버와 미러 서버와 전송 데이터를 비교하여 변화된
데이터를 저장할 수 있다. 또한 SSH를 이용하면 rsync 서버가 구축되어 있지 않아도 미러링을 할 수 있는 이점 이 있다.
데이터를 저장할 수 있다. 또한 SSH를 이용하면 rsync 서버가 구축되어 있지 않아도 미러링을 할 수 있는 이점 이 있다.
rsync 서버는 xinetd 방식으로 동작한다.
----- ServerA ----- ----- ServerB -----
rsync --daemon(873)
/etc/rsyncd.conf
rsync --daemon(873)
/etc/rsyncd.conf
/Mirror_Backup <------------------> /Backup
# rsync -avz --delete -e ssh ServerA:/Mirror_Backup /Backup
# rsync -avz --delete -e ssh ServerA:/Mirror_Backup /Backup
(a) rsync 서버 설정 과정
(ㄱ) /etc/rsyncd.conf 생성
(ㄴ) /etc/xinetd.d/rsync 수정
(ㄷ) xinetd 서비스 재시작
(b) rsync 클라이언트
(ㄱ) rsync 명령어를 이용한다.
(ㄱ) rsync 명령어를 이용한다.
(2) rsync 명령어
(명령어 형식)
# rsync -avz --delete -e ssh <원격서버:데이터경로>[SRC] <백업경로>[DEST] (source -> destination)
# rsync -avz --delete -e ssh 192.168.0.250:/backup /backup
# rsync -avz --delete -e ssh <원격서버:데이터경로>[SRC] <백업경로>[DEST] (source -> destination)
# rsync -avz --delete -e ssh 192.168.0.250:/backup /backup
Options
-a, --archive archive mode; same as -rlptgoD (no -H)
-v, --verbose increase verbosity
-z, --compress compress file data during the transfer
--delete delete files that don't exist on the sending side
-r, --recursive recurse into directories
-I, --ignore-times don't skip files that match in size and mod-time
-p, --perms preserve permissions
-o, --owner preserve owner (super-user only)
-g, --group preserve group
-t, --times preserve times
-D same as --devices --specials
-a, --archive archive mode; same as -rlptgoD (no -H)
-v, --verbose increase verbosity
-z, --compress compress file data during the transfer
--delete delete files that don't exist on the sending side
-r, --recursive recurse into directories
-I, --ignore-times don't skip files that match in size and mod-time
-p, --perms preserve permissions
-o, --owner preserve owner (super-user only)
-g, --group preserve group
-t, --times preserve times
-D same as --devices --specials
[EX1] 로컬서버의 로컬 디렉토리와 로컬 디렉토리 동기화
(명령어 형식)
# rsync -avz --delete -e ssh /backup/ /test101/
# rsync -avz --delete -e ssh /backup/ /test101
# rsync -avz --delete -e ssh /backup/ /test101
# rsync -avz --delete -e ssh /backup /test101
# rsync -avz --delete -e ssh IP:/backup/ /test100/
# rsync -avz --delete -e ssh IP:/backup/ /test100
# rsync -avz --delete -e ssh IP:/backup/ /test100
# rsync -avz --delete -e ssh IP:/backup /test100
만약 rsync 프로그램이 설치되어 있지 않다면 프로그램을 설치해 준다.
# rpm -q rsync
# yum install rsync
[root@linux220 ~]# df -h
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext3 36G 3.7G 30G 11% /
/dev/sda8 ext3 487M 11M 451M 3% /data1
/dev/sda7 ext3 487M 11M 451M 3% /data2
/dev/sda6 ext3 487M 11M 451M 3% /data3
/dev/sda5 ext3 487M 11M 451M 3% /data4
/dev/sda3 ext3 487M 11M 451M 3% /home
tmpfs tmpfs 506M 0 506M 0% /dev/shm
/dev/hdc iso9660 3.9G 3.9G 0 100% /media/CentOS_5.5_Final
[root@linux220 ~]# ls /backup
back-0419.tar.gz home.0428_205001.tar.gz incremental2.tar.gz
backup.list home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
[root@linux220 ~]#
[root@linux220 ~]# ls /RootBackup
full_backup.tar.gz
[root@linux220 ~]# rsync -avz --delete -e ssh 172.16.6.220:/backup /test100
ssh: connect to host 172.16.6.220 port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [receiver=3.0.6]
[root@linux220 ~]# ls /test100
ls: /test100: 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# vi /etc/profile
[root@linux220 ~]# cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# Functions and aliases go in /etc/bashrc
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
UID=`id -ru`
fi
if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
UID=`id -ru`
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
ulimit -S -c 0 > /dev/null 2>&1
if [ -x /usr/bin/id ]; then
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTSIZE=1000
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
INPUTRC=/etc/inputrc
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
unset i
unset pathmunge
unset pathmunge
#
# (1) Sfecific Configuration
#
export HISTTIMEFORMAT="%F %T "
[root@linux220 ~]# cd /etc/profile.d
[root@linux220 /etc/profile.d]# pwd
/etc/profile.d
[root@linux220 /etc/profile.d]# ls
colorls.csh gnome-ssh-askpass.csh lang.csh test.sh
colorls.sh gnome-ssh-askpass.sh lang.sh vim.csh
glib2.csh krb5-workstation.csh less.csh vim.sh
glib2.sh krb5-workstation.sh less.sh which-2.sh
[root@linux220 /etc/profile.d]# rm -f test.sh
[root@linux220 /etc/profile.d]# cd
[root@linux220 ~]# ls
Desktop bin install.log.syslog workspace
RPM-GPG-KEY-test dead.letter mbox yum.log
anaconda-ks.cfg install.log mnt
[root@linux220 ~]# vi ~/.bash_profile
[root@linux220 ~]# cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
PATH=$PATH:/test
PATH=$PATH:/test
export PATH
unset USERNAME
[root@linux220 ~]# vi ~/.bashrc
[root@linux220 ~]# cat ~/.bashrc
# .bashrc
unset USERNAME
[root@linux220 ~]# vi ~/.bashrc
[root@linux220 ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#
# Specific Configuration
#
export PS1='[\u@\h \w]\$ '
alias ls='ls --color=tty -h'
alias pps='ps -ef | head -1 ; ps -ef | grep $1'
alias vi='/usr/bin/vim'
alias grep='grep -i --color'
alias a='cd /test && rm -rf /test/*'
alias b='cp /etc/passwd file1 ; cp file1 file2 ; cp file1 file3'
alias c='clear'
alias df='df -h -T'
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
# Specific Configuration
#
export PS1='[\u@\h \w]\$ '
alias ls='ls --color=tty -h'
alias pps='ps -ef | head -1 ; ps -ef | grep $1'
alias vi='/usr/bin/vim'
alias grep='grep -i --color'
alias a='cd /test && rm -rf /test/*'
alias b='cp /etc/passwd file1 ; cp file1 file2 ; cp file1 file3'
alias c='clear'
alias df='df -h -T'
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
linux220.example.com (Linux release 2.6.18-409.el5 #1 SMP Tue Mar 15 18:22:22 EDT 2016) (3)
login: root
Password:
Last login: Fri Apr 29 16:06:09 on :0
You have mail.
|---> /etc/bashrc read
[root@linux220 ~]# exit
logout
|---> ~/.bash_logout read
Connection closed by foreign host.
[root@linux220 ~]# vi /etc/bashrc
[root@linux220 ~]# cat /etc/bashrc
# /etc/bashrc
Password:
Last login: Fri Apr 29 16:06:09 on :0
You have mail.
|---> /etc/bashrc read
[root@linux220 ~]# exit
logout
|---> ~/.bash_logout read
Connection closed by foreign host.
[root@linux220 ~]# vi /etc/bashrc
[root@linux220 ~]# cat /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# Environment stuff goes in /etc/profile
# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
unset i
unset pathmunge
fi
# vim:ts=4:sw=4
[root@linux220 ~]#
[root@linux220 ~]# bash
[root@linux220 ~]# ps
PID TTY TIME CMD
5188 pts/2 00:00:00 bash
5297 pts/2 00:00:00 bash
5309 pts/2 00:00:00 ps
[root@linux220 ~]# exit
exit
unset pathmunge
fi
# vim:ts=4:sw=4
[root@linux220 ~]#
[root@linux220 ~]# bash
[root@linux220 ~]# ps
PID TTY TIME CMD
5188 pts/2 00:00:00 bash
5297 pts/2 00:00:00 bash
5309 pts/2 00:00:00 ps
[root@linux220 ~]# exit
exit
[root@linux220 ~]# chkconfig sshd on
[root@linux220 ~]# service sshd restart
sshd 를 정지 중: [실패]
sshd (을)를 시작 중: [ OK ]
[root@linux220 ~]# service sshd restart
sshd 를 정지 중: [실패]
sshd (을)를 시작 중: [ OK ]
② /backup(원본) 디렉토리와 /test100/backup(미러) 디렉토리를 동기화
[root@linux220 ~]# rsync -avz --delete -e ssh 172.16.6.220:/backup /test100
receiving incremental file list
created directory /test100
backup/
backup/back-0419.tar.gz
backup/backup.list
backup/backup.log
backup/full_backup.tar.gz
backup/home.0428_205001.tar.gz
backup/home.0428_205101.tar.gz
backup/home.0428_205201.tar.gz
backup/incremental1.tar.gz
backup/incremental2.tar.gz
backup/incremental3.tar.gz
backup/linux220.tar.gz
backup/lv1.tar.gz
sent 243 bytes received 7407857 bytes 4938733.33 bytes/sec
total size is 7404478 speedup is 1.00
[root@linux220 ~]# ls /test100
backup
[root@linux220 ~]# ls /backup /test100/backup
/backup:
back-0419.tar.gz home.0428_205001.tar.gz incremental2.tar.gz
backup.list home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
total size is 7404478 speedup is 1.00
[root@linux220 ~]# ls /test100
backup
[root@linux220 ~]# ls /backup /test100/backup
/backup:
back-0419.tar.gz home.0428_205001.tar.gz incremental2.tar.gz
backup.list home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
/test100/backup:
back-0419.tar.gz home.0428_205001.tar.gz incremental2.tar.gz
backup.list home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
back-0419.tar.gz home.0428_205001.tar.gz incremental2.tar.gz
backup.list home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
③ /backup 디렉토리에서 backup.list 파일 삭제
[root@linux220 ~]# rm -rf /backup/backup.list
[root@linux220 ~]# ls /backup
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
④ /backup(원본) 디렉토리와 /test100/backup(미러) 디렉토리를 동기화
[root@linux220 ~]# rsync -avz --delete -e ssh 172.16.6.220:/backup /test100
receiving incremental file list
deleting backup/backup.list
backup/
receiving incremental file list
deleting backup/backup.list
backup/
sent 15 bytes received 356 bytes 742.00 bytes/sec
total size is 7404349 speedup is 19957.81
[root@linux220 ~]# ls /backup /test100/backup
/backup:
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
total size is 7404349 speedup is 19957.81
[root@linux220 ~]# ls /backup /test100/backup
/backup:
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
/test100/backup:
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
[root@linux220 ~]#
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
[root@linux220 ~]#
⑤ 로컬에 존재하는 디렉토리 미러링
[root@linux220 ~]# rsync -avz --delete -e ssh 172.16.6.220:/backup/ /test101/
receiving incremental file list
created directory /test101
./
back-0419.tar.gz
backup.log
full_backup.tar.gz
home.0428_205001.tar.gz
home.0428_205101.tar.gz
home.0428_205201.tar.gz
incremental1.tar.gz
incremental2.tar.gz
incremental3.tar.gz
linux220.tar.gz
lv1.tar.gz
sent 223 bytes received 7407647 bytes 14815740.00 bytes/sec
total size is 7404349 speedup is 1.00
total size is 7404349 speedup is 1.00
[root@linux220 ~]# ls /backup /test101
/backup:
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
/backup:
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
/test101:
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
back-0419.tar.gz home.0428_205101.tar.gz incremental3.tar.gz
backup.log home.0428_205201.tar.gz linux220.tar.gz
full_backup.tar.gz incremental1.tar.gz lv1.tar.gz
home.0428_205001.tar.gz incremental2.tar.gz
(주의) 아래 사항의 차이점을 이해 해야 한다.
# rsync -avz --delete -e ssh /backup/ /test101/ (# rsync -avz --delete -e ssh /backup/ /test101)
-> (ㄱ) /test101 디렉토리가 없으면 생성된다.
-> (ㄴ) /backup 디렉토리의 내용과 /test101 디렉토리의 내용은 동일하다. (/backup = /test101)
-> (ㄱ) /test101 디렉토리가 없으면 생성된다.
-> (ㄴ) /backup 디렉토리의 내용과 /test101 디렉토리의 내용은 동일하다. (/backup = /test101)
# rsync -avz --delete -e ssh /backup /test101
-> (ㄱ) /test101 디렉토리가 없으면 생성된다.
-> (ㄴ) /test101 디렉토리안에 backup 디렉토리가 생성된다. (/backup = /test101/backup)
-> (ㄱ) /test101 디렉토리가 없으면 생성된다.
-> (ㄴ) /test101 디렉토리안에 backup 디렉토리가 생성된다. (/backup = /test101/backup)
[EX2] rsync 서버 구축 및 rsync 명령어 사용
ssh를 이용한 rsync데이터 동기화를 위해서는 서버에 ssh서버가 작동 하고 있어야 한다.
rsync 서버를 구축하기 위해서는 rsync 설정파일인 /etc/rsyncd.conf 파일을 설정해야 한다.
(a) rsync 서버 설정 과정 (SRC)
(ㄱ) /etc/rsyncd.conf 생성
(ㄴ) /etc/xinetd.d/rsync 수정
(ㄷ) xinetd 서비스 재시작
(ㄱ) /etc/rsyncd.conf 생성
(ㄴ) /etc/xinetd.d/rsync 수정
(ㄷ) xinetd 서비스 재시작
(b) rsync 클라이언트 (DEST)
(ㄱ) rsync 명령어를 이용한다.
(ㄱ) rsync 명령어를 이용한다.
[root@linux220 ~]# rpm -q rsync
rsync-3.0.6-6.el5_11
[root@linux220 ~]# rpm -ql rsync
/etc/xinetd.d/rsync
/usr/bin/rsync
/usr/share/doc/rsync-3.0.6
/usr/share/doc/rsync-3.0.6/COPYING
/usr/share/doc/rsync-3.0.6/NEWS
/usr/share/doc/rsync-3.0.6/OLDNEWS
/usr/share/doc/rsync-3.0.6/README
/usr/share/doc/rsync-3.0.6/support
/usr/share/doc/rsync-3.0.6/support/Makefile
/usr/share/doc/rsync-3.0.6/support/atomic-rsync
/usr/share/doc/rsync-3.0.6/support/cvs2includes
/usr/share/doc/rsync-3.0.6/support/deny-rsync
/usr/share/doc/rsync-3.0.6/support/file-attr-restore
/usr/share/doc/rsync-3.0.6/support/files-to-excludes
/usr/share/doc/rsync-3.0.6/support/git-set-file-times
/usr/share/doc/rsync-3.0.6/support/logfilter
/usr/share/doc/rsync-3.0.6/support/lsh
/usr/share/doc/rsync-3.0.6/support/mnt-excl
/usr/share/doc/rsync-3.0.6/support/munge-symlinks
/usr/share/doc/rsync-3.0.6/support/rrsync
/usr/share/doc/rsync-3.0.6/support/rsyncstats
/usr/share/doc/rsync-3.0.6/support/savetransfer.c
/usr/share/doc/rsync-3.0.6/tech_report.tex
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz
[root@linux220 ~]# man rsyncd.conf
Formatting page, please wait...
[root@linux220 ~]# scp 172.16.9.252:/etc/rsyncd.conf /etc/rsyncd.conf
root@172.16.9.252's password:
rsyncd.conf 100% 133 0.1KB/s 00:00
[root@linux220 ~]# vi /etc/rsyncd.conf
[root@linux220 ~]# caat /etc/rsyncd.conf
bash: caat: command not found
[root@linux220 ~]# cat /etc/rsyncd.conf
uid=nobody
gid=nobody
user chroot=no
max connections=30
timeout=600
rsync-3.0.6-6.el5_11
[root@linux220 ~]# rpm -ql rsync
/etc/xinetd.d/rsync
/usr/bin/rsync
/usr/share/doc/rsync-3.0.6
/usr/share/doc/rsync-3.0.6/COPYING
/usr/share/doc/rsync-3.0.6/NEWS
/usr/share/doc/rsync-3.0.6/OLDNEWS
/usr/share/doc/rsync-3.0.6/README
/usr/share/doc/rsync-3.0.6/support
/usr/share/doc/rsync-3.0.6/support/Makefile
/usr/share/doc/rsync-3.0.6/support/atomic-rsync
/usr/share/doc/rsync-3.0.6/support/cvs2includes
/usr/share/doc/rsync-3.0.6/support/deny-rsync
/usr/share/doc/rsync-3.0.6/support/file-attr-restore
/usr/share/doc/rsync-3.0.6/support/files-to-excludes
/usr/share/doc/rsync-3.0.6/support/git-set-file-times
/usr/share/doc/rsync-3.0.6/support/logfilter
/usr/share/doc/rsync-3.0.6/support/lsh
/usr/share/doc/rsync-3.0.6/support/mnt-excl
/usr/share/doc/rsync-3.0.6/support/munge-symlinks
/usr/share/doc/rsync-3.0.6/support/rrsync
/usr/share/doc/rsync-3.0.6/support/rsyncstats
/usr/share/doc/rsync-3.0.6/support/savetransfer.c
/usr/share/doc/rsync-3.0.6/tech_report.tex
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz
[root@linux220 ~]# man rsyncd.conf
Formatting page, please wait...
[root@linux220 ~]# scp 172.16.9.252:/etc/rsyncd.conf /etc/rsyncd.conf
root@172.16.9.252's password:
rsyncd.conf 100% 133 0.1KB/s 00:00
[root@linux220 ~]# vi /etc/rsyncd.conf
[root@linux220 ~]# caat /etc/rsyncd.conf
bash: caat: command not found
[root@linux220 ~]# cat /etc/rsyncd.conf
uid=nobody
gid=nobody
user chroot=no
max connections=30
timeout=600
[Backup]
comment=Rsync Backup Server
path=/backup1
read only=no
[root@linux220 ~]# mkdir /backup1 /backup2
[root@linux220 ~]# vi /etc/xinetd.d/rsync
[root@linux220 ~]# cat /etc/xinetd.d/rsync
# 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
}
[root@linux220 ~]# disable = yes -> no
[root@linux220 ~]# service xinetd restart
xinetd 를 정지 중: [ OK ]
xinetd (을)를 시작 중: [ OK ]
[root@linux220 ~]# cat /etc/services | grep rsync
rsync 873/tcp # rsync
rsync 873/udp # rsync
airsync 2175/tcp # Microsoft Desktop AirSync Protocol
airsync 2175/udp # Microsoft Desktop AirSync Protocol
[root@linux220 ~]# telnet localhost 873
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
@RSYNCD: 30.0
quit
@ERROR: protocol startup error
Connection closed by foreign host.
[root@linux220 ~]#
comment=Rsync Backup Server
path=/backup1
read only=no
[root@linux220 ~]# mkdir /backup1 /backup2
[root@linux220 ~]# vi /etc/xinetd.d/rsync
[root@linux220 ~]# cat /etc/xinetd.d/rsync
# 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
}
[root@linux220 ~]# disable = yes -> no
[root@linux220 ~]# service xinetd restart
xinetd 를 정지 중: [ OK ]
xinetd (을)를 시작 중: [ OK ]
[root@linux220 ~]# cat /etc/services | grep rsync
rsync 873/tcp # rsync
rsync 873/udp # rsync
airsync 2175/tcp # Microsoft Desktop AirSync Protocol
airsync 2175/udp # Microsoft Desktop AirSync Protocol
[root@linux220 ~]# telnet localhost 873
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
@RSYNCD: 30.0
quit
@ERROR: protocol startup error
Connection closed by foreign host.
[root@linux220 ~]#
④ 클라이언트에서 rsync 명령어 수행
----- 172.16.9.252 ----- ----- 172.16.6.220 -----
/backup1/(내용) -----------------> # rsync -avz --delete -e ssh 192.168.0.250::Backup /backup1
----- 172.16.9.252 ----- ----- 172.16.6.220 -----
/backup1/(내용) -----------------> # rsync -avz --delete -e ssh 192.168.0.250::Backup /backup1
(At linux252.example.com) 172.16.9.252
# cp -r /etc/init.d/* /backup1
# ls /backup1
(At linux220.example.com) 172.16.6.220
# rsync -avz --delete -e ssh 172.16.9.252::Backup /backup1
(# rsync -avz --delete -e ssh 172.16.9.252:/backup1/ /backup1/)
:서비스명 = /경로 (/etc/rsyncd.conf 에 정의가 되어있음)
:Backup = /backup1
[root@linux220 ~]# rsync -avz --delete -e ssh 172.16.9.252::Backup /backup1
root@172.16.9.252's password:
receiving incremental file list
./
NetworkManager
acpid
anacron
apmd
atd
auditd
autofs
avahi-daemon
avahi-dnsconfd
bluetooth
capi
conman
cpuspeed
crond
cups
cups-config-daemon
dc_client
dc_server
dhcpd
dhcrelay
dnsmasq
dovecot
dund
firstboot
functions
gpm
haldaemon
halt
hidd
hplip
hsqldb
httpd
ibmasm
innd
ip6tables
iptables
irda
irqbalance
iscsi
iscsid
isdn
kdump
killall
krb524
kudzu
lisa
lm_sensors
lvm2-monitor
mcstrans
mdmonitor
mdmpd
messagebus
microcode_ctl
multipathd
named
netconsole
netfs
netplugd
network
new
nfs
nfslock
nscd
ntpd
oddjobd
openibd
pand
pcscd
portmap
psacct
rawdevices
rdisc
readahead_early
readahead_later
restorecond
rpcgssd
rpcidmapd
rpcsvcgssd
rwhod
saslauthd
sendmail
setroubleshoot
single
smartd
smb
spamassassin
squid
sshd
syslog
tcsd
tux
vmware-tools
vmware-tools-thinprint
vncserver
vsftpd
wdaemon
winbind
wpa_supplicant
xfs
xinetd
ypbind
yum-cron
yum-updatesd
sent 1988 bytes received 138965 bytes 56381.20 bytes/sec
total size is 357507 speedup is 2.54
[root@linux220 ~]#
total size is 357507 speedup is 2.54
[root@linux220 ~]#
[root@linux220 ~]# ls /backup1
NetworkManager haldaemon microcode_ctl rwhod
acpid halt multipathd saslauthd
anacron hidd named sendmail
apmd hplip netconsole setroubleshoot
atd hsqldb netfs single
auditd httpd netplugd smartd
autofs ibmasm network smb
avahi-daemon innd new spamassassin
avahi-dnsconfd ip6tables nfs squid
bluetooth iptables nfslock sshd
capi irda nscd syslog
conman irqbalance ntpd tcsd
cpuspeed iscsi oddjobd tux
crond iscsid openibd vmware-tools
cups isdn pand vmware-tools-thinprint
cups-config-daemon kdump pcscd vncserver
dc_client killall portmap vsftpd
dc_server krb524 psacct wdaemon
dhcpd kudzu rawdevices winbind
dhcrelay lisa rdisc wpa_supplicant
dnsmasq lm_sensors readahead_early xfs
dovecot lvm2-monitor readahead_later xinetd
dund mcstrans restorecond ypbind
firstboot mdmonitor rpcgssd yum-cron
functions mdmpd rpcidmapd yum-updatesd
gpm messagebus rpcsvcgssd
(At linux252.example.com) 172.16.9.252
# cd /backup1
# rm -r [a-v]*
# ls
(At linux220.example.com) 172.16.6.220
# rsync -avz --delete -e ssh 172.16.9.252::Backup /backup1
[root@linux220 ~]# rsync -avz --delete -e ssh 172.16.9.252::Backup /backup1
root@172.16.9.252's password:
receiving incremental file list
deleting vsftpd
deleting vncserver
deleting vmware-tools-thinprint
deleting vmware-tools
deleting tux
deleting tcsd
deleting syslog
deleting sshd
deleting squid
deleting spamassassin
deleting smb
deleting smartd
deleting single
deleting setroubleshoot
deleting sendmail
deleting saslauthd
deleting rwhod
deleting rpcsvcgssd
deleting rpcidmapd
deleting rpcgssd
deleting restorecond
deleting readahead_later
deleting readahead_early
deleting rdisc
deleting rawdevices
deleting psacct
deleting portmap
deleting pcscd
deleting pand
deleting openibd
deleting oddjobd
deleting ntpd
deleting nscd
deleting nfslock
deleting nfs
deleting new
deleting network
deleting netplugd
deleting netfs
deleting netconsole
deleting named
deleting multipathd
deleting microcode_ctl
deleting messagebus
deleting mdmpd
deleting mdmonitor
deleting mcstrans
deleting lvm2-monitor
deleting lm_sensors
deleting lisa
deleting kudzu
deleting krb524
deleting killall
deleting kdump
deleting isdn
deleting iscsid
deleting iscsi
deleting irqbalance
deleting irda
deleting iptables
deleting ip6tables
deleting innd
deleting ibmasm
deleting httpd
deleting hsqldb
deleting hplip
deleting hidd
deleting halt
deleting haldaemon
deleting gpm
deleting functions
deleting firstboot
deleting dund
deleting dovecot
deleting dnsmasq
deleting dhcrelay
deleting dhcpd
deleting dc_server
deleting dc_client
deleting cups-config-daemon
deleting cups
deleting crond
deleting cpuspeed
deleting conman
deleting capi
deleting bluetooth
deleting avahi-dnsconfd
deleting avahi-daemon
deleting autofs
deleting auditd
deleting atd
deleting apmd
deleting anacron
deleting acpid
deleting NetworkManager
./
sent 31 bytes received 167 bytes 56.57 bytes/sec
total size is 18734 speedup is 94.62
[root@linux220 ~]# ls /backup1
wdaemon winbind wpa_supplicant xfs xinetd ypbind yum-cron yum-updatesd
total size is 18734 speedup is 94.62
[root@linux220 ~]# ls /backup1
wdaemon winbind wpa_supplicant xfs xinetd ypbind yum-cron yum-updatesd
(주의) 다음 명령어는 한대의 클라이언트에서만 수행한다.
# cp -r /backup1 /linuxXXX (XXX: 자신 서버의 자리번호, 예: linux200)
# rsync -avz --delete -e ssh /linuxXXX 172.16.9.252:/backup2
# cp -r /backup1 /linuxXXX (XXX: 자신 서버의 자리번호, 예: linux200)
# rsync -avz --delete -e ssh /linuxXXX 172.16.9.252:/backup2
[root@linux220 ~]# cp -r /backup1 /linux220
[root@linux220 ~]# rsync -avz --delete -e ssh /linux220 172.16.9.252:/backup2
root@172.16.9.252's password:
sending incremental file list
linux220/
linux220/wdaemon
linux220/winbind
linux220/wpa_supplicant
linux220/xfs
linux220/xinetd
linux220/ypbind
linux220/yum-cron
linux220/yum-updatesd
[root@linux220 ~]# rsync -avz --delete -e ssh /linux220 172.16.9.252:/backup2
root@172.16.9.252's password:
sending incremental file list
linux220/
linux220/wdaemon
linux220/winbind
linux220/wpa_supplicant
linux220/xfs
linux220/xinetd
linux220/ypbind
linux220/yum-cron
linux220/yum-updatesd
sent 8218 bytes received 168 bytes 2396.00 bytes/sec
total size is 18734 speedup is 2.23
total size is 18734 speedup is 2.23
[root@linux220 ~]# ssh 172.16.9.252 ls /backup2
root@172.16.9.252's password:
linux200
linux202
linux204
linux205
linux206
linux207
linux210
linux211
linux212
linux213
linux217
linux218
linux220
linux223
linux224
linux227
리눅스어드민 끝.
'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글
20160502 리눅스 네트워크 (0) | 2016.05.03 |
---|---|
20160429 리눅스 네트워크 (0) | 2016.05.01 |
20160428 리눅스 관리자 (0) | 2016.05.01 |
20160427 리눅스 관리자 (0) | 2016.04.28 |
20160426 리눅스 관리자 (0) | 2016.04.27 |