On this page
- What makes Borg different from a plain copy?
- Where should the backup repository live?
- How do I install Borg on both machines?
- How do I connect the server to the repository host securely?
- How do I create the repository and the first archive?
- Why must I export the repository key?
- How do I keep a sensible history and check it?
- How do I restore files?
- How do I run it every night?
- Questions
What makes Borg different from a plain copy?
Borg splits files into chunks, stores each unique chunk once, compresses it and encrypts it on your server before it is sent. Daily archives therefore cost only the space of what changed, yet each archive is a complete, browsable point in time. If a file was damaged on Monday and backed up Tuesday, Sunday's version is still there.
A plain mirror made with rsync lacks that history. BitcoinVPS also offers optional daily server backups as a paid add-on (restored through a support ticket); Borg complements that with file level history you control yourself. The daily backups tutorial compares both routes.
Where should the backup repository live?
On a different machine from the one you protect: a second VPS in another city, a home server or NAS, or any host you can reach over SSH that has Borg installed. A repository on the same disk does not survive a destroyed server or a mistaken reinstall. A small storage-heavy plan works well as a target; the repository grows with unique data, not with the number of archives.
How do I install Borg on both machines?
Distribution packages carry the stable 1.x series, which is what this guide uses. Borg 2 changes command syntax, so keep both ends on the same major version.
# Ubuntu 24.04 / 22.04, Debian 12 / 13
sudo apt update
sudo apt install borgbackup
# Rocky Linux 9, AlmaLinux 9 (from EPEL)
sudo dnf install epel-release
sudo dnf install borgbackup
borg --versionOn the target, create a dedicated user that will own the repositories, for example sudo useradd -m -s /bin/bash borg, then sudo -u borg mkdir -p /home/borg/repos so the repository has a parent folder.
How do I connect the server to the repository host securely?
Generate a key for root on the source server (root can read every file), then restrict that key on the target so it can only run borg serve in one folder.
# on the source server
sudo ssh-keygen -t ed25519 -N "" -f /root/.ssh/borg_ed25519
sudo cat /root/.ssh/borg_ed25519.pubOn the target, add one line to /home/borg/.ssh/authorized_keys (shown wrapped here, keep it on one line):
command="borg serve --restrict-to-path /home/borg/repos/web1 --append-only",restrict ssh-ed25519 AAAA... root@web1--append-only means a compromised source can add archives but cannot delete old ones. Pruning is then done from the target side (or by temporarily removing the flag). Finally tell SSH which key to use by adding a host block to /root/.ssh/config on the source:
Host backup-target
HostName 198.51.100.24
User borg
IdentityFile /root/.ssh/borg_ed25519How do I create the repository and the first archive?
Store the passphrase in a root-only file, initialise the repository once, then create an archive.
sudo install -m 600 /dev/null /root/.borg-pass
sudo sh -c "openssl rand -base64 32 > /root/.borg-pass"
export BORG_REPO=ssh://backup-target/./repos/web1
export BORG_PASSCOMMAND="cat /root/.borg-pass"
sudo -E borg init --encryption=repokey-blake2
sudo -E borg create --stats --compression zstd,3 \
::{hostname}-{now:%Y-%m-%d_%H%M} \
/etc /home /srv /var/www /root \
--exclude "/home/*/.cache" --exclude "*.tmp"The --stats summary shows original, compressed and deduplicated sizes. Back up database dumps rather than live database files: run pg_dump or mysqldump into /srv/dumps just before borg create.
Why must I export the repository key?
With repokey mode, the encryption key sits inside the repository, protected by your passphrase. If the repository header is damaged, or if you lose the passphrase, every archive is unreadable. Export the key and keep it, together with the passphrase, somewhere off both servers (a password manager is a good place):
sudo -E borg key export "$BORG_REPO" /root/borg-web1.key
sudo -E borg key export --paper "$BORG_REPO"The paper format can be printed and typed back in an emergency.
How do I keep a sensible history and check it?
borg prune thins out old archives by rule and borg compact frees the space; borg check verifies repository consistency.
sudo -E borg prune --list --keep-daily 7 --keep-weekly 4 --keep-monthly 6
sudo -E borg compact
sudo -E borg check --verify-data
sudo -E borg listWith an append-only key, run prune and compact on the target machine as the borg user (pointing at the local path), or from a separate admin key. A full --verify-data pass reads everything, so run it weekly or monthly rather than nightly.
How do I restore files?
Extraction writes into the current directory, so restore into an empty folder first and copy back what you need.
sudo -E borg list
mkdir -p /tmp/restore && cd /tmp/restore
sudo -E borg extract ::web1-2026-12-02_0300 srv/app/config.yml
# or browse an archive like a folder (needs FUSE support)
sudo mkdir -p /mnt/borg
sudo -E borg mount ::web1-2026-12-02_0300 /mnt/borg
ls /mnt/borg/srv
sudo -E borg umount /mnt/borgMounting needs the FUSE bindings: sudo apt install python3-pyfuse3 on Ubuntu and Debian if the mount command complains. Test a restore regularly; a backup that has never been restored is only a hope.
How do I run it every night?
Put the steps in /usr/local/sbin/borg-nightly and trigger it with a systemd timer.
#!/bin/sh
set -e
export BORG_REPO=ssh://backup-target/./repos/web1
export BORG_PASSCOMMAND="cat /root/.borg-pass"
borg create --compression zstd,3 ::{hostname}-{now} /etc /home /srv /var/www /root
borg prune --keep-daily 7 --keep-weekly 4 --keep-monthly 6sudo chmod 700 /usr/local/sbin/borg-nightly
sudo systemctl edit --force --full borg-nightly.service # ExecStart=/usr/local/sbin/borg-nightly, Type=oneshot
sudo systemctl edit --force --full borg-nightly.timer # OnCalendar=*-*-* 03:00, Persistent=true
sudo systemctl enable --now borg-nightly.timer
journalctl -u borg-nightly.service -n 30Drop the prune line from the script if you use an append-only key. Timer syntax is covered in cron jobs and systemd timers.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Deduplicated backups with BorgBackup
How much space does Borg need on the target?
Roughly the compressed size of your data plus the daily changes kept by your prune rules. Text and databases shrink well; photos and video barely shrink.
Can I back up several servers into one repository?
It works, but separate repositories per server are simpler and avoid lock waits. Deduplication still happens within each repository.
What does "Failed to create/acquire the lock" mean?
Another Borg process is running, or one crashed. Confirm nothing is running, then clear it with borg break-lock (with BORG_REPO set).
Is Borg 2 ready to use?
Check the project release notes before switching. Its repository format and commands differ from 1.x, so a 1.x repository has to be transferred, not opened directly.
Does Borg send my data unencrypted?
No. With repokey or keyfile modes, chunks are encrypted on the source before they cross SSH, and the target never sees the key.