15.7. Recovering a Whole System
Everything so far restored pieces. Whole-system recovery rebuilds a
bootable machine: storage layout first, then the root filesystem,
then the boot chain, then the pieces that make the restored host
itself - fstab identifiers, host keys, and access to the backups
themselves. The rehearsal runs on the spare disk /dev/vdc, so
client1 keeps running throughout; a real recovery performs the same
steps from rescue media, which Chapter 16 covers,
with the repository copy and the exported key as the only inputs.
Figure 15.5. Rebuilding a system from a repository copy. Conceptual sequence; the commands are in the sections below.
15.7.1. Rebuilding Storage and Restoring the Root Filesystem
A root backup is an archive like any other, with one extra decision: what to exclude. The exclusions from Section 15.2.3 apply, and the root archive adds four of its own. Write the root exclusion list in john's workspace, on client1, in john's shell:
$ cd ~/debian-handbook/backup-restore
The command prints nothing; the workspace is the working directory again:
$ cat > root-exclude.txt <<'EOF'
/proc
/sys
/dev
/run
/tmp
/var/tmp
/var/cache
/var/lib/apt/lists
/var/lib/postgresql
/home/john/.cache/borg
/etc/borg
/root/.ssh
/home/john/debian-handbook/backup-restore/borg-client1.key
EOF
The here-document writes the file and prints nothing. The additions beyond Section 15.2.3, and why:
| Excluded path | Why |
|---|---|
/var/cache |
regenerable, and large enough to matter at whole-system scale |
/var/lib/postgresql |
live database files; the database comes back from the pg_dump export (Section 15.2.1), never from copied data files |
/etc/borg |
the backup system's own credentials and exclusion lists; restoring them onto a recovery host would overwrite that host's backup identity |
/root/.ssh |
the backup client's own keys - the identity that reaches backups should not travel inside them |
Note what is deliberately kept: /etc/ssh's host keys, the
machine's network configuration, and every account under /etc. A
recovered system should present its old SSH identity, come up on its
old network settings, and know its old users - Section 15.7.2 checks
the first of those. The exported key file's workspace copy is
excluded so the archive does not carry a second copy of a secret
already kept offline per Section 15.5.3.
Create the root archive, on client1, as root:
# cd /home/john/debian-handbook/backup-restore && time env BORG_PASSPHRASE=handbook-pass borg create --stats --compression zstd,6 --one-file-system --exclude-from root-exclude.txt ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-root-2026-11-20 /
------------------------------------------------------------------------------
Repository: ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Archive name: client1-root-2026-11-20
Archive fingerprint: 4016f27c4e1a73a5a51e2e2aa02ff17656330706020203d67deea28f6040ffcc
Time (start): Sat, 2026-11-21 00:26:12
Time (end): Sat, 2026-11-21 00:26:48
Duration: 35.49 seconds
Number of files: 26772
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
This archive: 972.94 MB 439.79 MB 430.88 MB
All archives: 973.02 MB 439.81 MB 432.39 MB
Unique chunks Total chunks
Chunk index: 25488 26906
------------------------------------------------------------------------------
real 0m43.520s
user 0m25.185s
sys 0m7.725s
The whole system - 26,772 files, 973 MB original - compressed to
440 MB and stored as 431 MB of new unique chunks in 43.5 seconds of
wall time on this hardware. --one-file-system keeps the archive on
the root filesystem: /srv/appdata is a separate volume and is not
in this archive, which is why the volume gets its own archives and
its own restore step below. Refresh the vault so the recovery source
is current - on backup1, as root, with the repository quiet:
# rsync -aHAX --numeric-ids /var/lib/borgsvc/repos/client1/ /var/lib/borgadmin/vault/client1/ && chown -R borgadmin:borgadmin /var/lib/borgadmin/vault/client1
The compound is silent, and it is the same refresh as Section 15.5.2.
Now build the recovery target. Everything on /dev/vdc is erased -
on client1, as root:
# wipefs -a /dev/vdc && parted -s /dev/vdc mklabel gpt && parted -s /dev/vdc unit MiB mkpart bios_grub 1 2 && parted -s /dev/vdc set 1 bios_grub on && parted -s /dev/vdc unit MiB mkpart root ext4 2 4095 && partprobe /dev/vdc
The chained steps are one layout operation, in order: erase old
signatures, write a GPT table, create a 1 MiB bios_grub partition
and flag it, create the root partition from 2 to 4095 MiB, and
re-read the table. The tiny first partition is where GRUB embeds its
core image on a GPT disk booted by legacy BIOS, as
Chapter 7 describes; a UEFI system instead gets
an EFI System Partition, and the file-restore steps below do not
change. The compound is silent. Create the root filesystem on the
second partition:
# mkfs.ext4 -L recovery /dev/vdc2
Creating filesystem with 1047808 4k blocks and 262144 inodes
Filesystem UUID: 57766658-c4fb-4c6b-83a2-efd9098e4d84
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
Selected output; the redrawn progress counters and the version banner
that mke2fs prints on standard error are omitted. Note the new
filesystem's UUID - the fstab fix in Section 15.7.2 uses it. Mount the
target:
# mkdir -p /mnt/recovery
# mount /dev/vdc2 /mnt/recovery
Both commands are silent. Restore the root filesystem from the vault - deliberately not from the writer's live repository, so the recovery path exercises the retention identity and the exported key, exactly as a real recovery host would. On client1, as root:
# cd /mnt/recovery
The command prints nothing; the extraction below writes into the current directory, which is now the root of the new filesystem:
# time env BORG_RSH='ssh -i /root/.ssh/id_ed25519_admin -o IdentitiesOnly=yes' BORG_PASSPHRASE=handbook-pass env BORG_KEY_FILE=/etc/borg/client1.key BORG_CONFIG_DIR=/root/.config/borg-vault BORG_CACHE_DIR=/root/.cache/borg-vault BORG_RELOCATED_REPO_ACCESS_IS_OK=yes borg extract --numeric-ids ssh://borgadmin@backup1/var/lib/borgadmin/vault/client1::client1-root-2026-11-20
real 0m30.255s
user 0m10.370s
sys 0m6.849s
The environment is the vault access set from Section 15.5.2, and
time measures the full root restore at 30.3 seconds for 26,772
files. Check what landed:
# cat /mnt/recovery/etc/hostname && stat -c "%U:%G %a %n" /mnt/recovery/home/john/debian-handbook/backup-restore/source/notes.txt
client1
john:john 664 /mnt/recovery/home/john/debian-handbook/backup-restore/source/notes.txt
The hostname file holds client1, and john's workspace file came
back with his ownership. The restored tree is a filesystem - but not
yet a system: /mnt/recovery/srv/appdata is an empty mountpoint
(the volume's contents were never in the root archive), and the disk
does not yet boot. Both are next.
15.7.2. Restoring Bootability and Host-Specific Configuration
The application volume first. The data archives from
Section 15.4.1 hold /srv - restore that tree onto a recreated
volume, on client1, as root. One compound builds the volume and
mounts it at the place the recovered root expects:
# lvcreate -l 100%FREE -n appdata-restore backupvg && mkfs.ext4 -L appdata-restore /dev/backupvg/appdata-restore && mkdir -p /mnt/recovery/srv/appdata && mount /dev/backupvg/appdata-restore /mnt/recovery/srv/appdata
Logical volume "appdata-restore" created.
Creating filesystem with 523264 4k blocks and 130816 inodes
Filesystem UUID: a6d5e5af-a59b-4d1d-949b-09195fab6d34
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
Selected output; the redrawn progress counters and the version
banner that mke2fs prints on standard error are omitted. The
volume takes the volume group's remaining free extents - and a real
recovery would use whatever storage the replacement machine has; the
file-level restore works onto any size that holds the data, which is
the advantage over image restore noted in Section 15.1.4. Extract the
data tree into it:
# cd /mnt/recovery
The command prints nothing; the extraction below writes into the current directory, which is the recovered root:
# time env BORG_PASSPHRASE=handbook-pass borg extract --numeric-ids ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1400 srv
real 0m4.878s
user 0m0.291s
sys 0m0.078s
This extraction comes from the writer's live repository - the data archives are not secret, and on a recovery host any reachable, current copy will do. Check the result against the live volume:
# stat -c "%U:%G %a %n" /mnt/recovery/srv/appdata/config/app.conf && cmp /srv/appdata/reports/quarterly.txt /mnt/recovery/srv/appdata/reports/quarterly.txt
www-data:www-data 640 /mnt/recovery/srv/appdata/config/app.conf
The configuration file's ownership returned intact, and cmp prints
nothing: the restored report file is byte-identical with the live
one. The database on this machine keeps running from its own dump
procedure (Section 15.6.3); on a rebuilt machine, the same dump load
is the final data step.
Now make the recovered tree describe its disk. The restored
/etc/fstab still names the old root filesystem's UUID, which
belongs to /dev/vda1 - the replacement must reference
57766658-c4fb-4c6b-83a2-efd9098e4d84, the UUID mkfs.ext4
reported in Section 15.7.1. Substitute it, on client1, as root:
# sed -i 's|UUID=be225267-eaf4-410c-9ffa-5cd32b221ce0|UUID=57766658-c4fb-4c6b-83a2-efd9098e4d84|' /mnt/recovery/etc/fstab
The command is silent; sed -i edits the file in place, replacing
the old UUID with the new one. Read the line back to see the result:
# grep '^UUID=' /mnt/recovery/etc/fstab
UUID=57766658-c4fb-4c6b-83a2-efd9098e4d84 / ext4 rw,discard,errors=remount-ro 0 1
The root entry now names the recovery disk. (A real rebuild reads
the new UUID from the mkfs output or blkid, exactly as was done
here; every other fstab entry - any data volume, any swap - gets the
same treatment, and volumes that no longer exist get their lines
removed or the boot will wait on them.)
The restored system's own identity needs no fixing - it came along in the archive, on purpose. Confirm the SSH host keys survived:
# cmp /etc/ssh/ssh_host_ed25519_key /mnt/recovery/etc/ssh/ssh_host_ed25519_key
cmp prints nothing: the recovered system will present the same
host key, so every client's known_hosts record from
Section 15.4.1 still proves its identity. Network configuration,
/etc/machine-id, and accounts are likewise ordinary files that were
restored; keep the machine-id when recovering the same host, and
regenerate it when the restore is meant to clone a second machine.
Finally, the boot chain. The chroot needs the kernel's virtual filesystems bound in place, on client1, as root:
# mkdir -p /mnt/recovery/proc /mnt/recovery/sys /mnt/recovery/dev /mnt/recovery/run /mnt/recovery/var/tmp && mount --bind /proc /mnt/recovery/proc && mount --bind /sys /mnt/recovery/sys && mount --bind /dev /mnt/recovery/dev
The compound is silent: the directories exist in the restored tree
(their contents were excluded as virtual, which is exactly why
they need borrowing from the running system), the bind mounts make
the chroot's view of processes, devices, and sysfs real, and the
/run and /var/tmp mountpoints are created for a fuller chroot
session even though the three commands below do not need them
bound. Rebuild the boot chain inside the restored system:
# chroot /mnt/recovery /bin/bash -c "update-initramfs -u -k all; update-grub; grub-install --target=i386-pc /dev/vdc"
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.12.86+deb13-amd64
Found initrd image: /boot/initrd.img-6.12.86+deb13-amd64
Adding boot menu entry for UEFI Firmware Settings ...
done
Installing for i386-pc platform.
Installation finished. No error reported.
The three commands inside the chroot, in order: update-initramfs
regenerates the initial ramdisk from the restored /boot,
update-grub regenerates grub.cfg from the restored /etc/default/
grub and the kernels it found, and grub-install writes GRUB's boot
code to the spare disk's boot record and its core image into the
bios_grub partition created in Section 15.7.1. Validate the
generated configuration:
# grub-script-check /mnt/recovery/boot/grub/grub.cfg
grub-script-check parses grub.cfg and prints nothing when it is
well-formed. The walkthrough verified the rebuilt chain this far;
completing the exercise boots the replacement disk and logs into it
before putting it into service - the final step of the rehearsal in
Section 15.7.4. Dismantle the recovery mounts, on client1, as root:
# umount /mnt/recovery/srv/appdata && umount /mnt/recovery/proc && umount /mnt/recovery/sys && umount /mnt/recovery/dev && umount /mnt/recovery
The compound is silent. The spare disk now holds a complete, boot-ready system with its data volume's archive available for the moment the volume is mounted again; the running system was never modified.
15.7.3. Recovering Backup Keys and Repository Access
Keyfile mode made the client's key directory a single point of
failure for repository access - the trade stated in Section 15.4.1.
Losing it loses nothing else: the exported key from /etc/borg and
the passphrase reopen any copy of the repository. Demonstrate the
failure first, on client1, as root, by moving the key cache aside:
# mv /root/.config/borg/keys /root/.config/borg/keys.off
The command is silent - and the client can no longer find its key:
# BORG_PASSPHRASE=handbook-pass borg list ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
No key file for repository ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1 found in /root/.config/borg/keys.
With the correct passphrase supplied and the repository perfectly healthy, access fails on the missing key alone. Restore access from the export made in Section 15.4.1:
# BORG_KEY_FILE=/etc/borg/client1.key BORG_PASSPHRASE=handbook-pass borg list ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
client1-2026-11-21T002302 Sat, 2026-11-21 00:23:07 [4f5bc6329c22cfb84a31c7011ac0bd4dae95e28a92022c9b82e4ef97ec5ebf67]
client1-2026-11-20T1400 Sat, 2026-11-21 00:23:18 [e2951d848cd3bd64d1dc29baa1411cc127acfdf3483cd3de88934486bb0359e7]
client1-root-2026-11-20 Sat, 2026-11-21 00:26:12 [4016f27c4e1a73a5a51e2e2aa02ff17656330706020203d67deea28f6040ffcc]
BORG_KEY_FILE points Borg at the exported key, the passphrase
unlocks it, and the repository lists again - including the
whole-root archive from Section 15.7.1. Put the key cache back so
ordinary commands keep working:
# mv /root/.config/borg/keys.off /root/.config/borg/keys
The command is silent. Two refinements complete the picture. On a
rebuilt machine, the same export can be re-imported into the key
cache with borg key import, after which commands work without
BORG_KEY_FILE. And the failure mode just demonstrated is exactly
why the offline key copy from Section 15.5.3 exists: a client that
loses its key directory, its /etc, or its whole disk reopens every
copy of the repository from the offline key and the passphrase,
neither of which lived on the client's storage alone.
15.7.4. Conducting Restore Exercises and Measuring Recovery Time
A restore exercise is a rehearsal with a stopwatch. Its findings are only as good as its realism: restore from the copy that a real disaster would leave - the vault or the offline disk, not the convenient live repository - use the key material that would actually survive, and finish the sequence the real event would demand, including a boot. The walkthrough measured its steps in the practice environment (two 1 GiB, single-vCPU guests on one host - small machines, so the values are demonstrations of measurement, not benchmarks):
| Operation | Measured wall time |
|---|---|
| Whole-root backup: 26,772 files, 973 MB original, 431 MB stored | 43.5 s |
| Whole-root restore to the spare disk | 30.3 s |
Application tree (/srv) restore |
4.8 s |
| Application data into the recreated volume | 4.9 s |
| Single file from the offline repository | 1.2 s |
Read against an RTO from Section 15.1.1, such numbers say which parts of recovery dominate (here, the root restore) and whether the objective is realistic at all. An exercise should also record what was faked: this walkthrough's whole-root restore ran on a spare disk of a running machine rather than from rescue media onto replacement hardware, it validated the rebuilt boot chain without booting it, and its database came back through a dump load rather than a service rebuild. Each simplification is fine for practice - and each is a line on the next exercise's plan.
Schedule exercises like backups, because untested restores decay: retention policies prune archives the drill depends on, software updates change tool behavior, and credentials rotate. A practical cadence restores a single file after every procedure change, a service each quarter, and rehearses the whole-system path at least yearly - with the offline copy, so the exercise also proves the media still read. Keep a short log per exercise: date, copy restored from, what was verified, what failed, wall time. The failures are the valuable output; a restore exercise that finds nothing was either perfect or too shallow to tell.
When the chapter's exercises are complete, remove the practice artifacts that exist only to demonstrate restores. On client1, as root:
# rm -rf /srv/restore-one /srv/restore /srv/restore-config /srv/restore-dump /srv/recovery-from-vault
On backup1, as root:
# rm -rf /srv/offline-restore
Both commands are silent. The staging trees are gone; the repository,
the vault, the offline disk, the recovery disk, and john's workspace
remain, and the practice volume backupvg/appdata and its archive
series are still available for further exercises. When the whole
practice environment is no longer needed, the three disposable disks
return to blank with the same wipefs command they started with.