ReaR linux backup and recover
Relax-and-Recover is an open-source tool to create computer backup archives and bootable ISO images of a Linux system. ReaR creates a bootable image consisting of the latest state of the system to be backed up. This image can be used for disaster recovery. ReaR was designed to be easy to setup and can be run through a cron
job with minimal effort if you have storage somewhere for storing backup images.
In my homelab, I have a suitable NFS server that can be used to store backup images. For more information on how to set up an NFS server see a previous post on the subject.
Install and Configure ReaR with Ansible
I have created an Ansible role to automate this configuration. I have a previous post about Ansible, check that out for information about Ansible. When you run the role against a Linux system, ReaR will be installed and configured with a cron job backup at a regular interval while the system is powered on.
Cron is a job scheduling utility present in Linux systems. The cron daemon will execute scheduled cron jobs at the intervals that the user or system configures. We will use a cron job to run ReaR backup jobs daily.
To use this ansible role, create a requirements.yml
file to pull the role from my public Github repo:
|
|
At the time of this post, the ansible role supports usage on RedHat family distributions and Debian family distributions. For RHEL 8 you will need the EPEL
repository enabled.
This does not support arm64 architecture so no Pis.
Create an ansible playbook to reference my role for execution playbook.yml
:
|
|
You can create an inventory file to limit the scope of execution inventory.ini
:
|
|
Playbook execution
|
|
You need to configure the variables to match an NFS server and NFS share that you already have access to. This NFS server will be used to store backup archives.
Configuration
Running the playbook will configure the backup job to run as a cron
job. The job runs the same command you can run manually to begin a backup job. This command will create the bootable media and backup the system.
|
|
The other options you can use with rear
are:
mkbackuponly
- create only the backup archivemkrescue
- create only the bootable image
Running rear
will utilize the configuration specififed in /etc/rear/local.conf
.
|
|
This configuration will create an iso image for disaster recovery and copy the backup archive to NFS storage specified in the BACKUP_URL
configuration. Directories can be excluded from backup with the BACKUP_PROG_EXCLUDE
option.
For more information and options, check the manual page man rear
.
The ansible role will use variables to populate the URLs used for .iso output and backup archives. Enter environment appropriate details in the playbook before executing.
|
|
Ansible variables are taken and used in the config file copied to the remote host. The template
ansible module takes a .j2 file and will copy it to the remote system
Recovery
To recover the system that was backed up, create a bootable drive or USB drive with the .iso image created by ReaR. For more information on how to create a bootable USB, see a previous post.
When booting from this image, there are two main options to manually recover the system or attempt an automatic recovery.
If the manual option is chosen, the system will boot a minimal linux system where you can run the command rear recover
to walk through the restoration.
When using either restoration method, if NFS storage was used, ReaR will automatically utilize the backup archive on the remote NFS server which is another feature that makes this quite a nice backup and recovery software.
Once the recovery completes, you can reboot the system without using the recovery drive. The restore operation outputs to a log file in /var/log/rear/recover/restore
.
Make sure to always test your backup images. There is nothing worse than trying to recover your system only to discover that the backup image is incomplete or corrupted.