brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: borg key export saves the key you need to open a Borg repository

Linux
~/tips/tip-backup-borg-key-export

borg key export /path/to/repo encrypted-key-backup

Exports the Borg encryption key to a file or paper, so a lost server doesn't lock you out.

An encrypted Borg backup is only as good as your access to its key. Without the key the repository can’t be opened, however well you remember the passphrase. So I’d run one command right after borg init and keep the result well away from the server.

borg key export /path/to/repo encrypted-key-backup
borg key export --paper /path/to/repo encrypted-key-backup.txt

The first writes the key to a file. The --paper format is made for printing and typing back in, with a check on every line to catch typos. --qr-html gives you a printable HTML page with a QR code plus the paper version. borg key import brings the key back when you need it. These are the Borg 1.4 commands from the stable docs.

How much you need this depends on the mode you chose at init. With keyfile encryption the key only lives on the machine that makes the backups, so if that machine dies with its disk, the copy on the other side can’t be read. With repokey the key sits in the repository itself, and the docs call an export not strictly needed, but it still guards against the repository becoming inaccessible when that key gets corrupted or lost.

Say your Unraid server sends Borg backups to a Hetzner Storage Box in Germany. I’d print the paper export and put it in a drawer at home, and keep the file version in a password manager.

The caveat: the export does not include your passphrase. The exported key stays encrypted, and getting back in takes both the export and the original passphrase. Store them in separate places and make sure you can find both when the server is gone.

Further reading: Borg docs: borg key export

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link