Command builder
Borg / Borgmatic command builder
Backups you set up once and forget — until you need to restore. Pick what you're doing and copy the exact command. Restore is front and centre.
Composed repo: —. Using a non-default SSH key or port options? Set BORG_RSH below.
⚠ Lose the passphrase (and key) and the backup is gone forever — there is no recovery. With keyfile modes the key lives only on this machine, so export and store it offsite.
Blank → list every archive in the repo. With a name → list the files inside that archive. (No :: = repo level; ::name = archive level — the distinction that trips everyone up.)
Extract: pull files straight back to disk. Best when you know the exact path.
Retention — how many to keep per period
⚠ Prune alone only deletes references — disk space isn't reclaimed until you run borg compact. The classic "I pruned but the disk is still full".
Remote & unattended (SSH, passphrase)
Restore — the part everyone forgets
- Extract vs Mount
- Extract pulls files back to disk — fastest when you know the exact path. Mount exposes the archive (or the whole repo) as a browsable folder via FUSE, so you can hunt for what you need in a file manager, copy it out, then
borg umount. - The extract gotcha
borg extracthas no output-directory flag — it always writes into your current directory. This builder generates themkdir -p … && cd …line so you don't dump a restore over your live files. (Borgmatic mode avoids this with--destination.)- Leading slash
- Paths inside an archive are stored relative —
home/joe/file, not/home/joe/file. The builder strips the leading slash for you.
Prune & compact
borg prune applies your --keep-* rules and removes old archives — but it only deletes references. Space is reclaimed only when you run borg compact afterwards. Always dry-run prune first, and use --glob-archives to scope it when several machines share one repo (otherwise prune compares unrelated archives).
Encryption & the passphrase
repokey stores the (encrypted) key inside the repo — the safe default for most people. keyfile keeps the key on the client only, so you must back it up offsite. Either way: a lost passphrase means permanently lost data — Borg has no recovery path. For cron, supply it via BORG_PASSCOMMAND (pulled from a secret store) rather than a plaintext BORG_PASSPHRASE.
Remote repositories (SSH)
A Borg repo can live on another server reached over SSH — the same commands work, you just point them at an ssh://user@host:port/path URL instead of a local path (a path without a leading slash is taken relative to the SSH login's home, written /./path). The remote server needs borg installed too. For unattended/cron runs, set BORG_RSH to choose the SSH key (e.g. ssh -i /root/.ssh/borg_key) and supply the passphrase via BORG_PASSCOMMAND — both under "Remote & unattended" above. Tip: an append-only SSH key on the server lets a client add backups but not delete them (ransomware protection); pruning then has to be done later with a full-access key.
Version note
These commands target Borg 1.2 / 1.4 (current stable in 2026), which uses the repo::archive syntax. Borg 2.0 is still beta and changes that to -r REPO … archive — don't mix the two.
Sources & references
- BorgBackup documentationBorgBackup
- Borg quick startBorgBackup
- borg extract — restoring filesBorgBackup
- Borgmatic documentationBorgmatic