Disaster recovery framework
Unwind

© Lead Image © lucato, 123RF.com
A simple Bash shell script can be a very powerful tool: Relax-and-Recover generates rescue media from running systems, takes care of backups, and helps when migrating computers to new hardware or converting to virtual machines.
If you are you looking to migrate the system and data on your sad, old laptop to a new device or you have a server that's been standing in the corner for years consuming electricity that would be better off as a virtual machine, the simple Relax-and-Recover [1] shell script can help. This disaster recovery framework for Linux licensed under GPLv2 creates rescue disks (USB sticks, CDs, PXE boot images) and saves the data – optionally in cooperation with an external backup solution.
During subsequent recovery of the data, the tool proves to be a flexible partner that also takes hardware changes into account. Relax-and-Recover is thus not just an emergency tool, it is also a useful migration tool. Physical computers thus become virtual machines through Physical-to-Virtual (P2V) migration; the way back to physical hardware with Virtual-to-Physical (V2P) migration is also possible, and you can even migrate from one virtualization solution to another through Virtual-to-Virtual (V2V).
Our test team worked on Debian 8 ("jessie") and Ubuntu 16.04 (Xenial Xerus) with Relax-and-Recover current stable version 1.17.2 and the latest version 1.18 from the GitHub repository (March 2016) [2]. We produced a rescue medium and a backup of a desktop computer. We also backed up a legacy server, combining the script with an external backup solution to do so. After this, the rescue systems and backups formed the basis for converting the physical hardware to virtual machines.
Well Prepared
Although Relax-and-Recover comes with a number of Linux distributions, the latest version is not necessarily on tap. The developers offer complete packages of the current versions on the project website [1]. You need to take care to resolve the dependencies on your system yourself. Usually, the package manager points out the missing components.
Alternatively, you can check out the program from the GitHub repository [2]. For this purpose, you need to install the git, syslinux, extlinux, and binutils packages and then execute the following commands:
git clone https://github.com/rear/rear.git cd rear make deb
On RPM-based systems, the package-building command is make rpm
. After installing, rear
resides in the /usr/sbin
directory; you need to be root to start the script.
The next task is to format the backup device, which overwrites all the data. Relax-and-Recover comes with its own command to do so; to launch the process, type the command followed by device name of the removable medium, which must not be mounted (Listing 1). It is important to type Yes exactly as shown, otherwise Relax-and-Recover will quit.
Listing 1
Launching Relax-and-Recover
Formatting is not entirely without problems. On one of the test systems, a USB stick needed a fresh partition table before the medium was accepted. If the software quits with an error, it immediately refers you to the logfile, which contains detailed information about the problem. If all goes well, the tool formats the stick with the filesystem specified in the output and labels it REAR-000 (Figure 1).
Rescue the Desktop!
A backup of your own work computer would be a good first trial of the software. After formatting your USB device, go to the configuration file /etc/rear/local.conf
, which only contains a few comments by the developers. Using a text editor, you can define, for example, the following requirements:
OUTPUT=USB BACKUP=NETFS BACKUP_URL=usb:///dev/disk/by-label/REAR-000
The rescue initramfs that contains the required startup files should end up on the USB medium. Alternative options for OUTPUT
are ISO
, PXE
, RAMDISK
, or OBDR
(see the manual [3] for details). Additionally, the type of backup is defined: NETFS
is the internal Relax-and-Recover method, which creates a simple tar.gz
archive of all data on the system. In this case Relax-and-Recover stores the rescue image and the backup itself on the device labeled REAR-000.
The next step depends on whether you only need a bootable rescue system or a system with a full backup on top. Listing 2 shows how to create the first alternative. The -v
option enables verbose message output. In this case, Relax-and-Recover only generates a bootable medium, which you can use to recover the basic environment of your system (e.g., disk layout, drivers, network card configuration), without programs and data, which are then backed up in a second step.
Listing 2
Rescue Disk
It is much more convenient to let Relax-and-Recover perform the backup task, too. If the USB removable drive is large enough, the command rear mkbackup
backs up everything to a single medium. If you don't have not enough space there, external hard drives or network drives can be used. The location for the backup is defined by the BACKUP_URL
variable in the /etc/rear/local.conf
configuration file. It expects values that begin with file://
, nfs://
, tape://
, or cifs://
. You can enter authentication information for Samba shares in the /etc/rear/.cifs
file (again, take a look at the manual [3] for a sample configuration).
After starting the rescue system, a selection menu (Figure 2) appears listing available rescue images and, in a second step, existing backups. You can also decide whether Relax-and-Recover should do everything automatically or if you want to intervene, in which case you log in as root without a password. The recovery process is launched by rear recover
. Again, the -v
switch ensures detailed output.

In the course of the restore, the program creates the partitions and reformats them with the original filesystem. The swap space ends up at the same location, and the script mounts the device and then restores the data. Finally, Relax-and-Recover installs the GRUB bootloader. Before rebooting the computer, you can see the results of your work in /mnt/local
, as the script reveals (Figure 3).

Teamwork
After the reboot, the system will be in the same state it was before calling rear mkrescue
or rear mkbackup
. Interaction is possible and necessary if the disk size has changed; you need to edit the /var/lib/rear/layout/diskrestore.sh
script generated by the restore in a text editor. Thanks to detailed logfiles and the ability to change scripts on the fly during the recover
process, you can even move systems to larger or smaller hard disks, although you can run into problems if you move to an enhanced IDE (EIDE) disk.
Relax-and-Recover is also at home in data centers, where it can back up or migrate servers with a significantly larger amount of data storage, compared with a desktop PC. You can even integrate an existing backup solution. Relax-and-Recover works with, among others, Bacula, Bareos, HP Data Protector, CommVault Galaxy (versions 5 to 7, and possibly later versions), Symantec NetBackup, EMC (formerly Legato) NetWorker, and IBM Tivoli Storage Manager.
Teamwork with an external backup program is not just an elegant way to combine the recovery and restore process, it also offers other benefits. The NETFS
backup method, with its simple .tar.gz
archive, does not take into account running databases and lock files. If you do not want to create a database dump manually and stop processes before running Relax-and-Recover, you will probably prefer a complete solution that takes care of exactly such problems.
The test team combined Bareos [4], a Bacula fork, with Relax-and-Recover and added the following information to the /etc/rear/local.conf
configuration file:
OUTPUT=ISO OUTPUT_URL=nfs://<IP>/<Share>/<Hostname> BACKUP=BAREOS BAREOS_CLIENT=<Bareosclient-fd>
The ISO image as a rescue system resides on a computer accessible via NFS. After a server crash, or when migrating to a virtual machine, the ISO boots via PXE – given an appropriately configured TFTP server. BAREOS_CLIENT
defines the name of the Bareos file daemon, which is responsible for backing up the client data.
The file daemon itself and its configuration are stored in the ISO image; it then autonomously takes care of restoring the data later on. A mandatory requirement, however, is that it access the backup server via bconsole
, which is the tool that communicates with the Bareos Director.
One other consideration in this scenario is that everything beyond a minimum rescue system is best stored in the backup, including directories such as /etc
, /usr
, and /var
, but not /tmp
, /proc
, and the like. This will ensure that the system administrator finds everything again as expected.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
Fedora 39 Beta is Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.
-
Star Labs Reveals a New Surface-Like Linux Tablet
If you've ever wanted a tablet that rivals the MS Surface, you're in luck as Star Labs has created such a device.
-
SUSE Going Private (Again)
The company behind SUSE Linux Enterprise, Rancher, and NeuVector recently announced that Marcel LUX III SARL (Marcel), its majority shareholder, intends to delist it from the Frankfurt Stock Exchange by way of a merger.