Chapter 27. Relax-and-Recover (ReaR)

When a software or hardware failure breaks the system, the system administrator faces three tasks to restore it to the fully functioning state on a new hardware environment:
  1. booting a rescue system on the new hardware
  2. replicating the original storage layout
  3. restoring user and system files
Most backup software solves only the third problem. To solve the first and second problems, use Relax-and-Recover (ReaR), a disaster recovery and system migration utility.
Backup software creates backups. ReaR complements backup software by creating a rescue system. Booting the rescue system on a new hardware allows you to issue the rear recover command, which starts the recovery process. During this process, ReaR replicates the partition layout and filesystems, prompts for restoring user and system files from the backup created by backup software, and finally installs the boot loader. By default, the rescue system created by ReaR only restores the storage layout and the boot loader, but not the actual user and system files.
This chapter describes how to use ReaR.

27.1. Basic ReaR Usage

27.1.1. Installing ReaR

Install the rear package and its dependencies by running the following command as root:
~]# yum install rear genisoimage syslinux

27.1.2. Configuring ReaR

ReaR is configured in the /etc/rear/local.conf file. Specify the rescue system configuration by adding these lines:
OUTPUT=output format
OUTPUT_URL=output location
Substitute output format with rescue system format, for example, ISO for an ISO disk image or USB for a bootable USB.
Substitute output location with where it will be put, for example, file:///mnt/rescue_system/ for a local filesystem directory or sftp://backup:password@ for an SFTP directory.

Example 27.1. Configuring Rescue System Format and Location

To configure ReaR to output the rescue system as an ISO image into the /mnt/rescue_system/ directory, add these lines to the /etc/rear/local.conf file:
See section "Rescue Image Configuration" of the rear(8) man page for a list of all options.

ISO-specific Configuration

Using the configuration in Example 27.1, “Configuring Rescue System Format and Location” results into two equivalent output files in two locations:
  • /var/lib/rear/output/ - rear's default output location
  • /mnt/rescue_system/HOSTNAME/rear-localhost.iso - output location specified in OUTPUT_URL
However, usually you need only one ISO image. To make ReaR create an ISO image only in the directory specified by a user, add these lines to /etc/rear/local.conf:
ISO_DIR="output location"
Substitute output location with the desired location for the output.

27.1.3. Creating a Rescue System

The following example shows how to create a rescue system with verbose output:
~]# rear -v mkrescue
Relax-and-Recover 1.17.2 / Git
Using log file: /var/log/rear/rear-rhel7.log
mkdir: created directory '/var/lib/rear/output'
Creating disk layout
Creating root filesystem layout
TIP: To login as root via ssh you need to set up /root/.ssh/authorized_keys or SSH_ROOT_PASSWORD in your configuration file
Copying files and directories
Copying binaries and libraries
Copying kernel modules
Creating initramfs
Making ISO image
Wrote ISO image: /var/lib/rear/output/rear-rhel7.iso (124M)
Copying resulting files to file location
With the configuration from Example 27.1, “Configuring Rescue System Format and Location”, ReaR prints the above output. The last two lines confirm that the rescue system has been successfully created and copied to the configured backup location /mnt/rescue_system/. Because the system's host name is rhel7, the backup location now contains directory rhel7/ with the rescue system and auxiliary files:
~]# ls -lh /mnt/rescue_system/rhel7/
total 124M
-rw-------. 1 root root  202 Jun 10 15:27 README
-rw-------. 1 root root 166K Jun 10 15:27 rear.log
-rw-------. 1 root root 124M Jun 10 15:27 rear-rhel7.iso
-rw-------. 1 root root  274 Jun 10 15:27 VERSION
Transfer the rescue system to an external medium to not lose it in case of a disaster.

27.1.4. Scheduling ReaR

To schedule ReaR to regularly create a rescue system using the cron job scheduler, add the following line to the /etc/crontab file:
minute hour day_of_month month day_of_week root /usr/sbin/rear mkrescue
Substitute the above command with the cron time specification (described in detail in Section 24.1.2, “Scheduling a Cron Job”).

Example 27.2. Scheduling ReaR

To make ReaR create a rescue system at 22:00 every weekday, add this line to the /etc/crontab file:
0 22 * * 1-5 root /usr/sbin/rear mkrescue

27.1.5. Performing a System Rescue

To perform a restore or migration:
  1. Boot the rescue system on the new hardware. For example, burn the ISO image to a DVD and boot from the DVD.
  2. In the console interface, select the "Recover" option:
    Rescue system: menu

    Figure 27.1. Rescue system: menu

  3. You are taken to the prompt:
    Rescue system: prompt

    Figure 27.2. Rescue system: prompt


    Once you have started recovery in the next step, it probably cannot be undone and you may lose anything stored on the physical disks of the system.
  4. Run the rear recover command to perform the restore or migration. The rescue system then recreates the partition layout and filesystems:
    Rescue system: running "rear recover"

    Figure 27.3. Rescue system: running "rear recover"

  5. Restore user and system files from the backup into the /mnt/local/ directory.

    Example 27.3. Restoring User and System Files

    In this example, the backup file is a tar archive created per instructions in Section, “Configuring the Internal Backup Method”. First, copy the archive from its storage, then unpack the files into /mnt/local/, then delete the archive:
    ~]# scp root@ /mnt/local/
    ~]# tar xf /mnt/local/backup.tar.gz -C /mnt/local/
    ~]# rm -f /mnt/local/backup.tar.gz
    The new storage has to have enough space both for the archive and the extracted files.
  6. Verify that the files have been restored:
    ~]# ls /mnt/local/
    Rescue system: restoring user and system files from the backup

    Figure 27.4. Rescue system: restoring user and system files from the backup

  7. Ensure that SELinux relabels the files on the next boot:
    ~]# touch /mnt/local/.autorelabel
    Otherwise you may be unable to log in the system, because the /etc/passwd file may have the incorrect SELinux context.
  8. Finish the recovery by entering exit. ReaR will then reinstall the boot loader. After that, reboot the system:
    Rescue system: finishing recovery

    Figure 27.5. Rescue system: finishing recovery

    Upon reboot, SELinux will relabel the whole filesystem. Then you will be able to log in to the recovered system.