본문 바로가기

OS/Linux

[리눅스/백업]ReaR 백업 설정하기

반응형

ReaR로 리눅스 OS 백업, 복구하기

 

ReaR로 OS 백업을 받기 위해서 nfs 서버에 백업을 받는다 가정하고 nfs를 설치해 준다.

NFS 서버 설치

[root@centos79 /]# systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

[root@centos79 /]# cat /etc/exports
/backup         *(rw,sync,no_root_squash)
   
[root@centos79 /]# systemctl enable --now nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

[root@centos79 /]# exportfs -v
/backup         <world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

[root@centos79 /]# systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
  Drop-In: /run/systemd/generator/nfs-server.service.d
           └─order-with-mounts.conf
   Active: active (exited) since Sat 2022-12-31 15:58:21 KST; 1min 52s ago
  Process: 1765 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
  Process: 1748 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 1746 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 1748 (code=exited, status=0/SUCCESS)
    Tasks: 0
   CGroup: /system.slice/nfs-server.service

Dec 31 15:58:21 centos79 systemd[1]: Starting NFS server and services...
Dec 31 15:58:21 centos79 systemd[1]: Started NFS server and services.

ReaR 설치

yum install rear

config 수정

$ cat /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=ISO
OUTPUT_URL=nfs://localhost/data
BACKUP=NETFS
BACKUP_URL=nfs://localhost/data

특정 폴더 제외시키기 위한 옵션 

BACKUP_PROG_EXCLUDE=( '/data/dir1/*' '/data/dir2/*' ) 

 

특정 File System 마운트 제외를 위한 옵션

EXCLUDE_MOUNTPOINTS=( "/test1" "/test2" )
EXCLUDE_COMPONENTS=( "fs:/test1" "fs:/test2" )
EXCLUDE_RECREATE=( "fs:/test1" "fs:/test2" )

OS 복구 후 부팅 시 에러 발생 -> mkfs, mount 통해 fs를 재생성하거나, /etc/fstab을 정확하게 맞춰줘야 정상 부팅됨

 

백업 실행

rear -d -v mkbackup

 

# ERROR: Error occurred during grub2-mkimage of BOOTX64.efi 에러 발생

[root@centos79 ~]# rear -d -v mkbackup
Relax-and-Recover 2.4 / Git
Using log file: /var/log/rear/rear-centos79.log
Using backup archive '/tmp/rear.xmsOCB9whV1WTB8/outputfs/centos79/backup.tar.gz'
Using UEFI Boot Loader for Linux (USING_UEFI_BOOTLOADER=1)
Creating disk layout
Using guessed bootloader 'EFI' (found in first bytes on /dev/sda)
Creating root filesystem layout
Handling network interface 'eth0'
eth0 is a physical device
Handled network interface 'eth0'
Skipping 'virbr0': not bound to any physical interface.
To log into the recovery system via ssh set up /root/.ssh/authorized_keys or specify SSH_ROOT_PASSWORD
Trying to find what to use as UEFI bootloader...
Trying to find a 'well known file' to be used as UEFI bootloader...
Using '/boot/efi/EFI/centos/grubx64.efi' as UEFI bootloader file
Copying logfile /var/log/rear/rear-centos79.log into initramfs as '/tmp/rear-centos79-partial-2022-12-31T16:37:21+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 (279470486 bytes) in 20 seconds
WARNING: /usr/lib/grub/x86_64-efi/moddep.lst not found, grub2-mkimage will likely fail. Please install the grub2-efi-x64-modules package to fix this.
ERROR: Error occurred during grub2-mkimage of BOOTX64.efi
Aborting due to an error, check /var/log/rear/rear-centos79.log for details
Exiting rear mkbackup (PID 30327) and its descendant processes
Running exit tasks
You should also rm -Rf --one-file-system /tmp/rear.xmsOCB9whV1WTB8
Terminated

grub2-efi-x64-modules 패키지 설치 해준다.

yum install grub2-efi-x64-modules

 

- 스크립트에서 저 부분을 찾는데 없어서 발생하는 에러

  • The script /usr/share/rear/lib/uefi-functions.sh checks if /usr/lib/grub*/x86_64-efi/moddep.lst file is present on the system or not.
  • If the file does not present on the system, It gives error.
[root@centos79 ~]# yum install grub2-efi-x64-modules
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package grub2-efi-x64-modules.noarch 1:2.02-0.87.0.2.el7.centos.11 will be installed
--> Processing Dependency: grub2-common = 1:2.02-0.87.0.2.el7.centos.11 for package: 1:grub2-efi-x64-modules-2.02-0.87.0.2.el7.centos.11.noarch
--> Running transaction check
---> Package grub2-common.noarch 1:2.02-0.86.el7.centos will be updated
--> Processing Dependency: grub2-common = 1:2.02-0.86.el7.centos for package: 1:grub2-tools-extra-2.02-0.86.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.86.el7.centos for package: 1:grub2-pc-2.02-0.86.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.86.el7.centos for package: 1:grub2-efi-x64-2.02-0.86.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.86.el7.centos for package: 1:grub2-tools-minimal-2.02-0.86.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.86.el7.centos for package: 1:grub2-tools-2.02-0.86.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.86.el7.centos for package: 1:grub2-pc-modules-2.02-0.86.el7.centos.noarch
---> Package grub2-common.noarch 1:2.02-0.87.0.2.el7.centos.11 will be an update
--> Running transaction check
---> Package grub2-efi-x64.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2-efi-x64.x86_64 1:2.02-0.87.0.2.el7.centos.11 will be an update
---> Package grub2-pc.x86_64 1:2.02-0.86.el7.centos will be updated
--> Processing Dependency: grub2-pc = 1:2.02-0.86.el7.centos for package: 1:grub2-2.02-0.86.el7.centos.x86_64
---> Package grub2-pc.x86_64 1:2.02-0.87.0.2.el7.centos.11 will be an update
---> Package grub2-pc-modules.noarch 1:2.02-0.86.el7.centos will be updated
---> Package grub2-pc-modules.noarch 1:2.02-0.87.0.2.el7.centos.11 will be an update
---> Package grub2-tools.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2-tools.x86_64 1:2.02-0.87.0.2.el7.centos.11 will be an update
---> Package grub2-tools-extra.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2-tools-extra.x86_64 1:2.02-0.87.0.2.el7.centos.11 will be an update
---> Package grub2-tools-minimal.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2-tools-minimal.x86_64 1:2.02-0.87.0.2.el7.centos.11 will be an update
--> Running transaction check
---> Package grub2.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2.x86_64 1:2.02-0.87.0.2.el7.centos.11 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================
 Package                                  Arch                      Version                                             Repository                  Size
=========================================================================================================================================================
Installing:
 grub2-efi-x64-modules                    noarch                    1:2.02-0.87.0.2.el7.centos.11                       updates                    1.1 M
Updating for dependencies:
 grub2                                    x86_64                    1:2.02-0.87.0.2.el7.centos.11                       updates                     34 k
 grub2-common                             noarch                    1:2.02-0.87.0.2.el7.centos.11                       updates                    733 k
 grub2-efi-x64                            x86_64                    1:2.02-0.87.0.2.el7.centos.11                       updates                    1.1 M
 grub2-pc                                 x86_64                    1:2.02-0.87.0.2.el7.centos.11                       updates                     34 k
 grub2-pc-modules                         noarch                    1:2.02-0.87.0.2.el7.centos.11                       updates                    860 k
 grub2-tools                              x86_64                    1:2.02-0.87.0.2.el7.centos.11                       updates                    1.8 M
 grub2-tools-extra                        x86_64                    1:2.02-0.87.0.2.el7.centos.11                       updates                    1.0 M
 grub2-tools-minimal                      x86_64                    1:2.02-0.87.0.2.el7.centos.11                       updates                    177 k

Transaction Summary
=========================================================================================================================================================
Install  1 Package
Upgrade             ( 8 Dependent packages)

Total download size: 6.8 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for updates
(1/9): grub2-2.02-0.87.0.2.el7.centos.11.x86_64.rpm                                                                               |  34 kB  00:00:00
(2/9): grub2-common-2.02-0.87.0.2.el7.centos.11.noarch.rpm                                                                        | 733 kB  00:00:00
(3/9): grub2-efi-x64-2.02-0.87.0.2.el7.centos.11.x86_64.rpm                                                                       | 1.1 MB  00:00:00
(4/9): grub2-pc-2.02-0.87.0.2.el7.centos.11.x86_64.rpm                                                                            |  34 kB  00:00:00
(5/9): grub2-efi-x64-modules-2.02-0.87.0.2.el7.centos.11.noarch.rpm                                                               | 1.1 MB  00:00:00
(6/9): grub2-pc-modules-2.02-0.87.0.2.el7.centos.11.noarch.rpm                                                                    | 860 kB  00:00:00
(7/9): grub2-tools-extra-2.02-0.87.0.2.el7.centos.11.x86_64.rpm                                                                   | 1.0 MB  00:00:00
(8/9): grub2-tools-minimal-2.02-0.87.0.2.el7.centos.11.x86_64.rpm                                                                 | 177 kB  00:00:00
(9/9): grub2-tools-2.02-0.87.0.2.el7.centos.11.x86_64.rpm                                                                         | 1.8 MB  00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                    8.5 MB/s | 6.8 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:grub2-common-2.02-0.87.0.2.el7.centos.11.noarch                                                                                    1/17
  Updating   : 1:grub2-tools-minimal-2.02-0.87.0.2.el7.centos.11.x86_64                                                                             2/17
  Updating   : 1:grub2-tools-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                     3/17
  Updating   : 1:grub2-tools-extra-2.02-0.87.0.2.el7.centos.11.x86_64                                                                               4/17
  Updating   : 1:grub2-pc-modules-2.02-0.87.0.2.el7.centos.11.noarch                                                                                5/17
  Updating   : 1:grub2-pc-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                        6/17
  Updating   : 1:grub2-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                           7/17
  Updating   : 1:grub2-efi-x64-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                   8/17
  Installing : 1:grub2-efi-x64-modules-2.02-0.87.0.2.el7.centos.11.noarch                                                                           9/17
  Cleanup    : 1:grub2-efi-x64-2.02-0.86.el7.centos.x86_64                                                                                         10/17
  Cleanup    : 1:grub2-2.02-0.86.el7.centos.x86_64                                                                                                 11/17
  Cleanup    : 1:grub2-pc-2.02-0.86.el7.centos.x86_64                                                                                              12/17
  Cleanup    : 1:grub2-tools-extra-2.02-0.86.el7.centos.x86_64                                                                                     13/17
  Cleanup    : 1:grub2-pc-modules-2.02-0.86.el7.centos.noarch                                                                                      14/17
  Cleanup    : 1:grub2-tools-2.02-0.86.el7.centos.x86_64                                                                                           15/17
  Cleanup    : 1:grub2-tools-minimal-2.02-0.86.el7.centos.x86_64                                                                                   16/17
  Cleanup    : 1:grub2-common-2.02-0.86.el7.centos.noarch                                                                                          17/17
  Verifying  : 1:grub2-common-2.02-0.87.0.2.el7.centos.11.noarch                                                                                    1/17
  Verifying  : 1:grub2-tools-minimal-2.02-0.87.0.2.el7.centos.11.x86_64                                                                             2/17
  Verifying  : 1:grub2-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                           3/17
  Verifying  : 1:grub2-tools-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                     4/17
  Verifying  : 1:grub2-tools-extra-2.02-0.87.0.2.el7.centos.11.x86_64                                                                               5/17
  Verifying  : 1:grub2-efi-x64-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                   6/17
  Verifying  : 1:grub2-pc-modules-2.02-0.87.0.2.el7.centos.11.noarch                                                                                7/17
  Verifying  : 1:grub2-pc-2.02-0.87.0.2.el7.centos.11.x86_64                                                                                        8/17
  Verifying  : 1:grub2-efi-x64-modules-2.02-0.87.0.2.el7.centos.11.noarch                                                                           9/17
  Verifying  : 1:grub2-tools-minimal-2.02-0.86.el7.centos.x86_64                                                                                   10/17
  Verifying  : 1:grub2-tools-extra-2.02-0.86.el7.centos.x86_64                                                                                     11/17
  Verifying  : 1:grub2-common-2.02-0.86.el7.centos.noarch                                                                                          12/17
  Verifying  : 1:grub2-efi-x64-2.02-0.86.el7.centos.x86_64                                                                                         13/17
  Verifying  : 1:grub2-2.02-0.86.el7.centos.x86_64                                                                                                 14/17
  Verifying  : 1:grub2-pc-2.02-0.86.el7.centos.x86_64                                                                                              15/17
  Verifying  : 1:grub2-tools-2.02-0.86.el7.centos.x86_64                                                                                           16/17
  Verifying  : 1:grub2-pc-modules-2.02-0.86.el7.centos.noarch                                                                                      17/17

Installed:
  grub2-efi-x64-modules.noarch 1:2.02-0.87.0.2.el7.centos.11

Dependency Updated:
  grub2.x86_64 1:2.02-0.87.0.2.el7.centos.11                                 grub2-common.noarch 1:2.02-0.87.0.2.el7.centos.11
  grub2-efi-x64.x86_64 1:2.02-0.87.0.2.el7.centos.11                         grub2-pc.x86_64 1:2.02-0.87.0.2.el7.centos.11
  grub2-pc-modules.noarch 1:2.02-0.87.0.2.el7.centos.11                      grub2-tools.x86_64 1:2.02-0.87.0.2.el7.centos.11
  grub2-tools-extra.x86_64 1:2.02-0.87.0.2.el7.centos.11                     grub2-tools-minimal.x86_64 1:2.02-0.87.0.2.el7.centos.11

Complete!

패키지 설치 후 실행하면 잘 넘어간다. 

백업 파일 확인

[root@centos79 centos79]# ls -al
total 4145092
drwxr-x---  2 root root        124 Dec 31 16:50 .
drwxr-xr-x. 3 root root         22 Dec 31 16:31 ..
-rw-------  1 root root   10253428 Dec 31 16:50 backup.log
-rw-------  1 root root 3906081105 Dec 31 16:50 backup.tar.gz
-rw-------  1 root root        202 Dec 31 16:44 README
-rw-------  1 root root  327153664 Dec 31 16:44 rear-centos79.iso
-rw-------  1 root root    1062549 Dec 31 16:44 rear-centos79.log
-rw-------  1 root root        265 Dec 31 16:44 VERSION

 


복구 

저장된 ISO를 이용하여 부팅한다. 

부팅되고 나면 복구용 OS에 들어가진다.

우선 테스트로 localhost로 넣었던 nas ip를 기존 nas를 설치해둔 ip로 변경을 한다. (처음부터 ip 넣었으면 관계없음.)

rear recover를 치고 기다리면 복구가 완료되고 리부팅을 하게 되면 복구가 완료된다.

 

 

참고 :

https://access.redhat.com/solutions/2115051

 

What is Relax and Recover(ReaR) and how can I use it for disaster recovery? - Red Hat Customer Portal

Red Hat Enterprise Linux now contains Relax and Recover(ReaR) which can be used for image based backups. What is it? Any example for using this backup utility?

access.redhat.com

https://access.redhat.com/solutions/3213391

 

Why does rear mkbackup fails with "Error occurred during grub2-mkimage of BOOTX64.efi" - Red Hat Customer Portal

When using ReaR utility, rear mkbackup or rear mkrescue commands fails with error Using '/boot/efi/EFI/redhat/grubx64.efi' as UEFI bootloader file Copying logfile /var/log/rear/rear-localhost.log into initramfs as '/tmp/rear-localhost-partial-2022-04-08T13

access.redhat.com

 

반응형