[CentOS6] relax-and-recover backup

ReaR (Relax-and-Recover) 를 사용 하여 OS backup 을 진행 하고 pxe-boot 를 이용하여

System 을 복구 할수 있습니다.

rear site : http://relax-and-recover.org/

rear 참고 page : https://github.com/rear/rear

rear 참고 사항: 백업 대상 system 에만 설치하고 복구시에는 pxe-boot 를 이용합니다.

본 문서에서는 pxe-boot 설명은 대략 적인 내용만 하고 차후에 pxe-boot 를 다루도록 하겠습니다.

 

 

  • rear package 설치

  • epel-release package 를 설치 한후 rear 을 설치 합니다.
[root@centos66 ~]# yum install -y epel-release
[root@centos66 ~]# yum install -y rear

 

  • rear 설정 local.conf 파일을 설정 합니다.
  • PXE image 를 생성 하며 image 생성 nfs 주소를 설정 합니다.
  • nfs 주소 설정시 기존에 사용하던 pxe-boot machine 을 사용 하는것이 좋습니다.
  • BACKUP_PROG_EXCLUDE 에서 제외할 디렉토리를 선택 합니다.
[root@centos66 ~]# vi /etc/rear/local.conf
# Default is to create Relax-and-Recover rescue media as ISO image
# set OUTPUT to change that
# set BACKUP to activate an automated (backup and) restore of your data
# Possible configuration values can be found in /usr/share/rear/conf/default.conf
#
# This file (local.conf) is intended for manual configuration. For configuration
# through packages and other automated means we recommend creating a new
# file named site.conf next to this file and to leave the local.conf as it is.
# Our packages will never ship with a site.conf.


OUTPUT=PXE
OUTPUT_URL="nfs://192.168.100.10/data/restore"
BACKUP=NETFS
BACKUP_URL="nfs://192.168.100.10/data/restore"
BACKUP_PROG_EXCLUDE=('/backup/*' '/proc/*' '/dev/*' '/lost+found/*' '/mnt/*' '/media/*' '/sys/*')
[root@centos66 ~]#

 

  • rear 에서 사용할 root ssh-keygen  을 생성 합니다. 
[root@centos66 ~]# cd /root/.ssh/
[root@centos66 .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
6c:4f:d0:52:18:53:b8:bf:9c:ad:f5:d4:78:4d:31:d7 root@centos66
The key's randomart image is:
+--[ RSA 2048]----+
|        o=o      |
|        o+      .|
|        o..    oE|
|       ..o      +|
|        S..     .|
|       . o.    +.|
|         ..+. o +|
|          +..o . |
|          ..  .  |
+-----------------+
[root@centos66 .ssh]#
[root@centos66 .ssh]# cat id_rsa.pub >> authorized_keys
[root@centos66 .ssh]# chmod 600 authorized_keys
[root@centos66 .ssh]# ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 05:3d:74:2b:f9:49:5b:d3:91:49:3f:ec:e0:d9:9e:d7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
Last login: Wed Apr  3 17:10:36 2019 from 192.168.0.1
[root@centos66 ~]#

 

  • rear backup 을 진행 합니다. 
[root@centos66 ~]# rear -v mkbackup
Relax-and-Recover 1.17.2 / Git
Using log file: /var/log/rear/rear-centos66.log
Creating disk layout
Creating root filesystem layout
Copying files and directories
Copying binaries and libraries
Copying kernel modules
Creating initramfs
Copied kernel+initrd (61M) to /var/lib/rear/output
Created pxelinux config 'rear-centos66' and symlinks for MAC adresses in /var/lib/rear/output
Copying resulting files to nfs location
Encrypting disabled
Creating tar archive '/tmp/rear.TTOIfb0jOk1DyHJ/outputfs/centos66/backup.tar.gz'
Archived 1400 MiB [avg 6797 KiB/sec]OK
Archived 1400 MiB in 212 seconds [avg 6765 KiB/sec]
[root@centos66 ~]#

 

  • 백업 확인
[root@rhel70 ~]# chmod -R 777 /data
[root@rhel70 ~]# cd /data/restore/
[root@rhel70 restore]# ll
total 0
drwxrwxrwx 2 nfsnobody nfsnobody 185 Apr  4 01:15 centos66

[root@rhel70 restore]# cd centos66/
[root@rhel70 centos66]# ll
total 1503904
-rwxrwxrwx 1 nfsnobody nfsnobody    8106798 Apr  4 01:15 backup.log
-rwxrwxrwx 1 nfsnobody nfsnobody 1468774648 Apr  4 01:15 backup.tar.gz
-rwxrwxrwx 1 nfsnobody nfsnobody   58774023 Apr  4 01:12 centos66.initrd.cgz
-rwxrwxrwx 1 nfsnobody nfsnobody    4152336 Apr  4 01:12 centos66.kernel
-rwxrwxrwx 1 nfsnobody nfsnobody        268 Apr  4 01:12 centos66.message
-rwxrwxrwx 1 nfsnobody nfsnobody        516 Apr  4 01:12 README
-rwxrwxrwx 1 nfsnobody nfsnobody        468 Apr  4 01:12 rear-centos66
-rwxrwxrwx 1 nfsnobody nfsnobody     162404 Apr  4 01:12 rear.log
-rwxrwxrwx 1 nfsnobody nfsnobody        268 Apr  4 01:12 VERSION
[root@rhel70 centos66]#

 

  • pxe-boot 설정
  • pxeboot-server 의 경우 toilet 를 이용하여 생성 하였습니다. 🙂
  • 2번 라인에 CentOS 6.6 Restore 로 설정을 합니다.
[root@rhel70 ~]# cd /data/tftpboot/linux-install/
* RHEL & CentOS pxe-install
 ______  _______ _                 _       ____
|  _ \ \/ / ____| |__   ___   ___ | |_    / ___|  ___ _ ____   _____ _ __
| |_) \  /|  _| | '_ \ / _ \ / _ \| __|___\___ \ / _ \ '__\ \ / / _ \ '__|
|  __//  \| |___| |_) | (_) | (_) | ||_____|__) |  __/ |   \ V /  __/ |
|_|  /_/\_\_____|_.__/ \___/ \___/ \__|   |____/ \___|_|    \_/ \___|_|

Default number 1 RHEL 7.6 install

1. RHEL 7.6-64bit install
2. CentOS 6.6 Restore

 

  • default 파일 내용은 백업 디렉토리 rear-$hostname 파일에서 확인 가능 합니다.
[root@rhel70 centos66]# cat rear-centos66
default hd
prompt 1
timeout 300

label hd
localboot -1
say ENTER - boot local hard disk
say --------------------------------------------------------------------------------
display /centos66.message
say ----------------------------------------------------------
say rear = disaster recover this system with Relax and Recover
label rear
        kernel /centos66.kernel
        append initrd=/centos66.initrd.cgz root=/dev/ram0 vga=normal rw selinux=0 console=ttyS0,9600 console=tty0
[root@rhel70 centos66]#

 

  • default 파일 수정
[root@rhel70 linux-install]# cd pxelinux.cfg/
[root@rhel70 pxelinux.cfg]# pwd
/data/tftpboot/linux-install/pxelinux.cfg
[root@rhel70 pxelinux.cfg]# vi default
~ 중략 
LABEL 2
    kernel centos66/centos66.kernel
        append initrd=centos66/centos66.initrd.cgz root=/dev/ram0 vga=normal rw selinux=0 console=ttyS0,9600 console=tty0

 

  • kernel 이미지 디렉토리에 파일을 카피 합니다.
[root@rhel70 linux-install]# pwd
/data/tftpboot/linux-install
[root@rhel70 linux-install]# cp -arp /data/restore/centos66 .

 

  • 디렉토리 권한 변경 및 pxe-boot 를 실행 합니다.
[root@rhel70 ~]# chmod -R 777 /data
[root@rhel70 ~]# systemctl restart nfs
[root@rhel70 ~]# systemctl restart xinetd
[root@rhel70 ~]# systemctl restart dhcpd

 

  • pxe-boot test 를 진행 합니다.
  • 2 번을 눌러 CentOS 6.6 을 복구 합니다.

 

  • 1번을 입력 합니다.

 

  • rear recover 를 입력 하여 백업한 os 로 설치 합니다.

 

  • rear recover 실행 화면

 

  • 복구 완료 화면
  • 시스템을 리부팅 합니다.

 

  • 작업 완료후 로그인 합니다.

 

CentOS 7 Version Test ;

 

  • 패키지 설치
[root@www1 ~]# yum install -y epel-release
[root@www1 ~]# yum clean all & yum list

[root@www1 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@www1 ~]# yum install -y syslinux syslinux-extlinux rear

 

  • ssh-keygen  설정
[root@www1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:tnLcXylU9p0fDuBdVwEUQrRFoSYnavyH/S6hVldcmiQ root@www1
The key's randomart image is:
+---[RSA 2048]----+
|          o+oB+.o|
|            E . o|
|         o * o++o|
|      . . * oo+++|
|       +S  ..o.oo|
|      .o.oo+ .o.o|
|      . +o+o+ o..|
|       o o.o.o   |
|        .   +o   |
+----[SHA256]-----+
[root@www1 ~]# cd .ssh/
[root@www1 .ssh]# cat id_rsa.pub >> authorized_keys
[root@www1 .ssh]# chmod 600 authorized_keys

[root@www1 .ssh]# ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:fW1qDoTOUqdHZ9TlQsUdWQKdKSEhStuYd6Zd9jGABYQ.
ECDSA key fingerprint is MD5:3e:35:b5:89:a0:d6:57:82:e8:3d:48:aa:34:e5:82:de.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Last login: Fri Apr  5 18:30:46 2019 from 192.168.0.1
[root@www1 ~]# logout
Connection to localhost closed.
[root@www1 .ssh]#

 

  • 백업실행전 pxe-boot system 에 nfs mount point 를 백업 대상 system 에 임시로 마운트를 해봅니다.
  • rear 백업 실행
[root@www1 ~]# mount -t nfs 192.168.100.10:/data/restore /mnt
[root@www1 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/sda3                      17G  6.7G   11G  40% /
devtmpfs                      895M     0  895M   0% /dev
tmpfs                         910M     0  910M   0% /dev/shm
tmpfs                         910M   10M  900M   2% /run
tmpfs                         910M     0  910M   0% /sys/fs/cgroup
/dev/sda1                    1014M  194M  821M  20% /boot
tmpfs                         182M     0  182M   0% /run/user/0
192.168.100.10:/data/restore   20G  7.3G   13G  37% /mnt
[root@www1 ~]# umount /mnt/


[root@www1 ~]# rear -v mkbackup
Relax-and-Recover 2.4 / Git
Using log file: /var/log/rear/rear-www1.log
Using backup archive '/tmp/rear.j7Kop3mGgWOjFRG/outputfs/www1/backup.tar.gz'
Creating disk layout
Using guessed bootloader 'GRUB' (found in first bytes on /dev/sda)
Creating root filesystem layout
Skipping 'virbr0': not bound to any physical interface.
Copying logfile /var/log/rear/rear-www1.log into initramfs as '/tmp/rear-www1-partial-2019-04-05T18:37:05+0900.log'
Copying files and directories
Copying binaries and libraries
Copying kernel modules
Copying all files in /lib*/firmware/
Creating recovery/rescue system initramfs/initrd initrd.cgz with gzip default compression
Created initrd.cgz with gzip default compression (199441250 bytes) in 22 seconds
Copied kernel+initrd 197M to /var/lib/rear/output
Created pxelinux config 'rear-www1' and symlinks for MAC adresses in /var/lib/rear/output
Copying resulting files to nfs location
Saving /var/log/rear/rear-www1.log as rear-www1.log to nfs location
Creating tar archive '/tmp/rear.j7Kop3mGgWOjFRG/outputfs/www1/backup.tar.gz'
Archived 2570 MiB [avg 7455 KiB/sec] OK
Archived 2570 MiB in 354 seconds [avg 7434 KiB/sec]
Exiting rear mkbackup (PID 10986) and its descendant processes
Running exit tasks
[root@www1 ~]#

 

  • pxe-boot system 설정
  • /data/restore/www1 으로 이동후 rear-www1 파일을 확인 합니다.
[root@rhel70 restore]# cd
[root@rhel70 ~]# cd /data/restore/www1/
[root@rhel70 www1]# cat rear-www1
    default hd
prompt 1
timeout 300

label hd
localboot -1
say ENTER - boot local hard disk
say --------------------------------------------------------------------------------
    display /www1.message
    say ----------------------------------------------------------
    say rear = disaster recover this system with Relax-and-Recover
    label rear
        kernel /www1.kernel
        append initrd=/www1.initrd.cgz root=/dev/ram0 vga=normal rw selinux=0 console=ttyS0,9600 console=tty0
[root@rhel70 www1]#

 

  • pex-boot 설정파일을 수정 합니다.
  • boot.msg 파일 및 pxelinux.cfg/default 파일 수정
[root@rhel70 ~]# cd /data/tftpboot/linux-install/
[root@rhel70 linux-install]# vi boot.msg
Default number 1 RHEL 7.6 install

1. RHEL 7.6-64bit install
2. CentOS 6.6 Restore
3. CentOS www1 Restore



[root@rhel70 linux-install]# cd pxelinux.cfg/
[root@rhel70 pxelinux.cfg]# vi default

LABEL 3
    kernel www1/www1.kernel
        append initrd=www1/www1.initrd.cgz root=/dev/ram0 vga=normal rw selinux=0 console=ttyS0,9600 console=tty0

 

  • pxe-boot 설정
  • 백업 system 파일 복사
  • 디렉토리 권한 수정
[root@rhel70 ~]# cd /data/tftpboot/linux-install/
[root@rhel70 linux-install]# cp -r /data/restore/www1 .
[root@rhel70 linux-install]# chmod -R 777 /data

 

  • 복구 테스트
[root@rhel70 ~]# systemctl restart dhcpd
[root@rhel70 ~]# systemctl restart nfs-server
[root@rhel70 ~]# systemctl restart xinetd

 

  • 3 CentOS www Restore 를 선택 합니다.

 

  • network interface 정보를 설정 합니다.
  • 백업 장비와 신규장비의 network interface 맵핑 하는 설정 이며, restore 완료후 설정 하여도 됩니다.

 

  • network interface 설정

 

  • restore 를 진행 합니다.

 

  • 별도의 설정은 필요 없으며 자동으로 restore 가 진행 됩니다. 🙂

 

  • init 6 로 재부팅후 system 을 확인 합니다.

 

댓글 남기기