I recently needed to completely reinstall one of my Hetzner servers with Proxmox, but first wanted to make sure I had a bulletproof backup of everything on it. After hitting a few roadblocks with Borg backup, here’s the solution I ended up with.
The main issue I ran into was trying to create the backup repository in /data/storage – turns out Borg can’t create a repository inside a directory it’s trying to backup (circular reference problem). The solution? Use Hetzner’s Storage Box service as the backup destination.
Setting up the backup
First, install Borg if you haven’t already:
apt update && apt install borgbackup
Then set up your Storage Box credentials as environment variables:
export STORAGE_USER="uXXXXXX" # Your storage box username
export STORAGE_HOST="uXXXXXX.your-storagebox.de" # Your storage box hostname
export BORG_REPO="ssh://${STORAGE_USER}@${STORAGE_HOST}:23/./backups/server-full"
export BORG_PASSPHRASE="choose-a-strong-passphrase"
The ./ in the path means “relative to home directory” – so it’ll create the backup in /home/uXXXXXX/backups/server-full on your Storage Box.
Creating the backup repository
First, create the directory on your Storage Box:
ssh -p 23 ${STORAGE_USER}@${STORAGE_HOST} mkdir -p backups
Then initialize the Borg repository:
borg init --encryption=repokey-blake2
This creates an encrypted repository that’ll hold all your backup archives.
Running the actual backup
Now for the main event – backing up your entire server:
borg create --progress --stats \
--exclude /dev \
--exclude /proc \
--exclude /sys \
--exclude /tmp \
--exclude /run \
--exclude /mnt \
--exclude /media \
--exclude /var/cache \
--exclude /swapfile \
::{hostname}-{now} \
/ /etc /root /home /var /usr/local /opt /srv /data
This excludes the system directories that shouldn’t be backed up and creates an archive named with your hostname and timestamp. The backup will take some time depending on your server size – grab a coffee!
Don’t forget the encryption key!
This is crucial – export and save your Borg encryption key:
borg key export :: /tmp/borg-key.txt
scp -P 23 /tmp/borg-key.txt ${STORAGE_USER}@${STORAGE_HOST}:backups/
Without this key, your backups are useless, so keep it safe!
Verifying and restoring
To verify your backup worked:
borg list
borg info ::{archive-name}
And when you need to restore after installing Proxmox:
borg mount ::{archive-name} /mnt/restore
# Then copy needed files back
The mount command lets you browse the backup like a normal filesystem – super handy for selective restoration.
Happy backing up!



Leave a Reply