Skip to content
System

BorgBackup: check that a Linux backup actually restores

Avatar illustré de Julien Macé 3 min read
Archive de sauvegarde Linux reliée à un disque de restauration séparé
BorgBackup restauration de sauvegarde Linux

A configuration file disappears, a service does not restart anymore, and the Borg backup seems reassuring. However, an archive visible in BorgBackup does not prove that you will be able to recover the right file in the right place.

The least risky method is to restore into an empty directory, read the result, and then compare before touching the active path. This way, you will know if the repository, the password, the archive, and the restored data are actually usable.

Linux backup archive linked to a separate restore disk
A Borg restoration is first done in an isolated directory.

Prepare an Isolated Restoration Directory

This procedure assumes a Borg repository already initialized and encrypted. Use the same account, the same SSH key, and the same means to provide the passphrase as your backup task. If you are restoring system files, the extraction must have the necessary rights to read their owners and permissions.

Before launching Borg, note four elements: the exact URL of the repository, the name of the archive, the path to recover, and a test location with enough free space. A disk mounted under /srv or /var/tmp is better than / or /etc.

export BORG_REPO='ssh://[email protected]/./srv/borg/server1'
mkdir -p /srv/restore-borg-test
findmnt -T /srv/restore-borg-test
df -h /srv/restore-borg-test

findmnt should show the filesystem that will receive the extraction. df -h prevents filling a local partition with an archive larger than expected. The documentation for BorgBackup details the format of repositories and archives.

List the Archive and Check the Borg Repository

Start by reading. Borg must open the repository and display archives without key, path, or authentication errors. Then, copy the exact name of the chosen archive into the ARCHIVE variable.

borg list
export ARCHIVE='2026-08-31T02:15:00'
borg list ::"$ARCHIVE"
borg check --repository-only

The last command checks the structure of the repository, but it does not replace a restoration. A check with --verify-data reads the data again and can be long on a remote repository. Plan it outside of a backup period or heavy disk activity.

borg check --verify-data

Extract a File in the Test Directory

Choose a useful file, for example, the configuration of a service. The paths listed by Borg generally do not start with /. First, verify that the requested file actually belongs to the archive, then simulate the extraction.

borg list ::"$ARCHIVE" etc/my-service/config.yml
borg extract --dry-run ::"$ARCHIVE" etc/my-service/config.yml

The --dry-run mode displays the planned work without creating the file. If it raises neither decryption errors nor missing paths, move to the test directory before the actual extraction. The borg extract command then recreates the tree under the current folder.

cd /srv/restore-borg-test
borg extract ::"$ARCHIVE" etc/my-service/config.yml
stat etc/my-service/config.yml
sha256sum etc/my-service/config.yml

Compare Before Putting the File Back into Production

The restored file is now readable outside of production. If an active version still exists, compare them before any copy. Differences can be normal after a recent change. They must be understood, not overwritten reflexively.

diff -u /etc/my-service/config.yml 
  /srv/restore-borg-test/etc/my-service/config.yml

For a folder, replace diff -u with diff -ru. Keep the test restoration until the end of the incident. Copying directly from the archive to /etc, /var/lib, or a database can overwrite a newer version and complicate rollback.

For a cloud backup managed with another tool, the same principle applies: the article on Rclone under Linux also applies a restoration in a separate location. Borg is a good choice when you need deduplication and encryption, but I would always favor regular test extraction over a backup report marked as successful.

Share Facebook X WhatsApp LinkedIn Pinterest Reddit Email