[MDRM] data영역 백업하기

1. 정보

  • MDRM 4.5.7 이 전
  • MDRM 4.5.8 이 후
  • 패지키 변경으로 인한 백업 방식

2. 차이점

  • 4.5.7 이전
drwxr-xr-x 11 root     root     4096 May 14 08:49 config
-rw-r--r--  1 root     root      923 Nov 27  2019 hosts
drwxr-xr-x  2 root     root      266 Jul 30 14:57 license
drwxr-xr-x 23 root     root     4096 Sep 14 16:50 logs
drwxr-xr-x  2 root     root      226 Jan 13  2020 nagios
drwxr-xr-x  2 root     root       73 Dec 30  2019 plugins
drwxr-xr-x  4 postgres postgres   30 Jan 15  2019 postgresql
drwxr-xr-x  7 root     root      102 Jan 15  2019 repository
drwxr-xr-x  3 root     root       17 Jan 15  2019 tomcat
  • 4.5.8 이 후
total 4
drwxr-xr-x 6 root     root     4096 Aug 27 09:41 config
drwxr-xr-x 2 root     root       56 Aug 27 11:09 license
drwxr-xr-x 9 root     root      307 Sep 14 00:00 logs
drwxr-xr-x 2 root     root       31 Aug 27 09:41 nagios
drwxr-xr-x 8 root     root      147 Aug 27 09:41 package(추가됨)
drwxr-xr-x 2 root     root        6 Jul 25  2019 plugins
drwxr-xr-x 4 postgres postgres   30 Jul 25  2019 postgresql
drwxr-xr-x 8 root     root      116 Aug  7 17:17 repository
drwxr-xr-x 3 root     root       17 Jul 25  2019 tomcat

3. 원인

root@poc-mdrm:data > du -sh package/
1.4G    package/
root@poc-mdrm:package > ls -l
total 8976
-rwxr-xr-x 1 root root     136 Aug 27 09:41 alert-start.sh
drwxr-xr-x 4 root root     143 Aug 27 09:41 drbd
drwxr-xr-x 3 root root      19 Aug 27 09:41 gam_agent
drwxr-xr-x 2 root root    4096 Aug 27 09:41 images
-rwxr-xr-x 1 root root   20161 Aug 27 09:41 install.sh
drwxr-xr-x 2 root root      28 Aug 27 09:41 jre
-rwxr-xr-x 1 root root 9161949 Aug 27 09:41 manual.pdf
drwxr-xr-x 3 root root      19 Aug 27 09:41 mccs
drwxr-xr-x 4 root root      34 Aug 27 09:41 wind-nrpe
  • package의 용량이 상대적으로 높음
  • package 디렉토리에는 4.5.7 이전과는 다르게 drbd, gam_agent, mccs 등의 패키지를 포함하고 있음
  • 이는 버전업 혹은 패치 된 패키지를 보관하고 있기 때문에 생긴 디렉토리

4. 백업

  • 기존하고 동일하게 풀백업하는 방법
tar zcfP mdrm_backup_$(date +"%m%d%y").tgz /mdrm_data
  • package 디렉토리를 제외 한 백업
tar zcfP mdrm_backup_$(date +"%m%d%y").tgz /mdrm_data --exclude /mdrm_data/package

유의사항

  • 패키지 내용의 업데이트가 한 번이라도 있을 경우에는 필히 풀백업 필수

5. 백업 스크립트

  • 하기의 백업 스크립트 저장 후 실행
#!/bin/bash
# @author: jckim@mantech.co.kr
# Last edit day : 2020-08-27

# Log time format
LOG_DATE(){ date +"%m/%d %H:%M:%S"; }

_spinner() {
  case $1 in
    start)
      echo -ne "${2} "
      # start spinner
      i=1
      sp='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
      delay=0.15
      while :; do
        printf "\b${sp:i++%${#sp}:1}"
        sleep $delay
      done
    ;;
    stop)
      if [ -z ${3} ]; then
        echo "spinner is not running.."
        exit 1
      fi
      kill $3 >/dev/null 2>&1
      # inform the user uppon success or failure
      if [ $2 -eq 0 ]; then
        echo " [DONE]"
      else
        echo " [FAIL]"
        exit 1
      fi
    ;;
  esac
}

_start_spinner() {
  # $1 : msg to display
  _spinner "start" "${1}" &
  # set global spinner pid
  _sp_pid=$!
  disown
}

_stop_spinner() {
  # $1 : command exit status
  _spinner "stop" $1 $_sp_pid
  unset _sp_pid
}

_EXCLUDE_BACKUP() {
  _start_spinner 'Exclude backup starting ... '
  STARTTIME=$(date +%s)
  tar zcfP mdrm_backup_$(date +"%m%d%y").tgz /mdrm_data --exclude /mdrm_data/package
  ENDTIME=$(date +%s)
  _stop_spinner $?
  echo "It takes $(($ENDTIME - $STARTTIME)) seconds to complete this task..."
  ls -lh | grep mdrm_backup_$(date +"%m%d%y").tgz
}

_FULL_BACKUP() {
  _start_spinner 'Full backup starting ... '
  STARTTIME=$(date +%s)
  tar zcfP mdrm_full_backup_$(date +"%m%d%y").tgz /mdrm_data
  ENDTIME=$(date +%s)
  _stop_spinner $?
  echo "It takes $(($ENDTIME - $STARTTIME)) seconds to complete this task..."
  ls -lh | grep mdrm_full_backup_$(date +"%m%d%y").tgz  
}

clear
echo "ᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔ"
echo "select backup type"
echo "ᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔ"
echo "1) mdrm data exclude package backup"
echo "2) mdrm data full backup"
echo "ᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔ"
printf "select backup type) "
read BACKUP_TYPE

case ${BACKUP_TYPE} in
  1) clear && _EXCLUDE_BACKUP ;;
  2) clear && _FULL_BACKUP ;;
  *) exit 0 ;;
esac
  • 실행화면(1,2를 선택하여 백업)
ᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔ
select backup type
ᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔ
1) mdrm data exclude package backup
2) mdrm data full backup
ᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔᚔ
select backup type)