We will perform backups and restores for RedHat-based Linux servers using Relax-and-Recover (ReaR).
What can it do?
- Backup and restore of built Linux environments
- Disaster recovery
- Restoration of deleted files
- Peace of mind
Assumed Environment
- RedHat-based Linux
- Backup/Restore target server (192.168.100.1)
- Relax-and-Recover installed
- NFS server for storing backups (192.168.100.2)
- Public directory is /nfs
- Access permitted from 192.168.100.0/24
Building the NFS Server: 192.168.100.2
Build the NFS server.
dnf -y update
dnf -y install nfs-utils firewalld
nfs_dir=/nfs
mkdir -p ${nfs_dir}
echo "${nfs_dir} 192.168.100.0/24(rw,no_root_squash)" > /etc/exports
# echo "${nfs_dir} *(rw,no_root_squash)" > /etc/exports
exportfs -ra
systemctl enable --now rpcbind nfs-server firewalld
firewall-cmd --add-service=nfs --permanent
firewall-cmd --reload
Relax-and-Recover Installation: 192.168.100.1
dnf -y update
dnf -y install rear grub2-efi-x64-modules
# Additional installation for EFI (for grub2-mkstandalone command)
dnf -y install grub2-tools-extra
Relax-and-Recover Configuration
cp /etc/rear/local.conf /etc/rear/local.conf.bak
cat <<'EOF' > /etc/rear/local.conf
OUTPUT=ISO
BACKUP=NETFS
BACKUP_URL="nfs://192.168.100.2/nfs/"
BACKUP_PROG_EXCLUDE=("${BACKUP_PROG_EXCLUDE[@]}" '/media' '/var/tmp' '/var/crash' '/kdump')
LOGFILE="$LOG_DIR/rear-$HOSTNAME.log"
GRUB_RESCUE=1
EOF
# Add the following for EFI
echo 'USING_UEFI_BOOTLOADER=1' >> /etc/rear/local.conf
Configuration Items
-
OUTPUT
Output format of the rescue system -
BACKUP
Backup method used to create tar archives -
BACKUP_URL
Destination for the tar.gz backup files
Directories /media, /var/tmp, /var/crash, and /kdump are excluded from the backup scope.
Backup: 192.168.100.1
rear -v mkbackup
Restore
- Extract the rescue system (output as an ISO file, DVD, or USB).
- Boot from the rescue system.
- Select "Recover hostname".
- When the login prompt appears, enter root.
# Not necessary if there is a DHCP network (not needed if an IP address has already been acquired)
ip a
ip addr add 192.168.100.100/24 dev <network interface>
# Proceed with the restore.
rear recover
# At the root prompt
reboot
During restoration, the system automatically searches for the location of the backup files specified by BACKUP_URL, so perform the restore from a location that can reach the NFS server. It will automatically mount the NFS share, download the information, and expand it.
If you have not output the backup files to the location used in this example, you must mount them at the same location as BACKUP_URL before running the rear recover command. In the case of file:///backup, you would mount them at /backup. Since this is not recommended, specific details are omitted.
Other
If the rescue system's ISO file exceeds 4GB, the ISO file will be created, but it will not be possible to boot from it during restoration. Therefore, it is realistic to output the rescue system and the backup files as separate files (do not specify iso:// in BACKUP_URL).
rear mkbackup essentially means executing rear mkrescue + rear mkbackuponly. If you wish to output the rescue system or the backup files separately, execute them individually.
rear mkrescue
Using rear mkrescue may be considered if you are performing backups using tools other than Relax-and-Recover. However, since this diminishes the significance of using Relax-and-Recover, using mkrescue alone is unlikely.
If the storage layout has been changed, you must recreate the rescue system using rear mkrescue.
rear checklayout
This command is used to avoid unnecessary recreation of the rescue system. It only guarantees that the storage layout has not changed since the rescue system was last created, but you cannot rely entirely on all return codes.
rear mkbackuponly
This outputs backup.tar.gz. backup.tar.gz includes backups of files such as /boot, /etc, /usr, etc.
Periodic Backups
echo '0 4 * * * root rear mkbackup' >> /etc/crontab
Local Backups Without Using NFS
Note that you must ensure that devices like /backup are not restored during the restoration process. Details (whether mount-related points become targets for backup and restore) have not been verified.
cat <<'EOF' > /etc/rear/local.conf
OUTPUT=ISO
OUTPUT_URL=file:///backup
BACKUP=NETFS
BACKUP_URL=file:///backup
BACKUP_PROG_EXCLUDE=("${BACKUP_PROG_EXCLUDE[@]}" '/media' '/var/tmp' '/var/crash' '/kdump' '/backup')
LOGFILE="$LOG_DIR/rear-$HOSTNAME.log"
GRUB_RESCUE=1
EOF
When including backup files in the rescue system: since there is a possibility that booting will fail if the output ISO file exceeds 4GB, do not use the following method.
cat <<'EOF' > /etc/rear/local.conf
OUTPUT=ISO
OUTPUT_URL=file:///backup
BACKUP=NETFS
BACKUP_URL=iso:///backup
BACKUP_PROG_EXCLUDE=("${BACKUP_PROG_EXCLUDE[@]}" '/media' '/var/tmp' '/var/crash' '/kdump')
LOGFILE="$LOG_DIR/rear-$HOSTNAME.log"
GRUB_RESCUE=1
EOF
How to Change the Temporary Area During Backup
Specify TMPDIR at execution time as follows. You can also describe it in /etc/rear/local.conf.
TMPDIR="/tmp/myrear/dir" rear -v mkbackup
Error Output
ERROR: Cannot setup GRUB_RESCUE: Not enough disk space in /boot for Relax-and-Recover rescue system. Required:
Countermeasure: Do not put a value for GRUB_RESCUE in /etc/rear/local.conf (though I think it is better to have it; no error occurs in the default configuration).
GRUB_RESCUE=
Things to Keep in Mind
The method described in this article is a recovery procedure and flow established after careful consideration. As a standard practice, backups are isolated on a separate server via NFS, and restoration is also performed via the same NFS.
The following restoration flow is not impossible, but it is strongly discouraged. Considering it is a waste of time.
- Backing up to a disk within the same chassis
- Subsequently moving the backup to a separate server and performing a network-based restore
- Manual restoration from backup files
Environment
[root@localhost ~]# cat /etc/redhat-release
Rocky Linux release 9.2 (Blue Onyx)
[root@localhost ~]#
[root@localhost ~]# rear --version
Relax-and-Recover 2.6 / 2020-06-17
[root@localhost ~]#
262

被折叠的 条评论
为什么被折叠?



