15.4. Maintaining Versioned Backup Repositories
rsync trees and tar files preserve versions only if someone keeps making them, naming them, and deleting the old ones correctly. A backup repository automates that: named archives accumulate against a deduplicated chunk store, a retention policy prunes them, and every chunk is checksummed so damage is detectable. This section builds the repository on the backup host, reaches it through an account whose only power is to run Borg's server mode, schedules the backups, and runs the retention and verification cycle.
15.4.1. Creating an Encrypted Repository with BorgBackup
Borg stores archives inside a repository. Each archive is a
snapshot of the paths given to borg create; the repository splits
file contents into chunks, compresses and encrypts each chunk on the
client, and stores it once, keyed by content. A second archive of
mostly unchanged data sends only the chunks it is missing - the
practice archives below transfer under a kilobyte of new data for a
43 kB tree.
Figure 15.3. The repository model and the two key custody modes. Conceptual schematic.
The encryption mode is chosen once, at borg init, and it decides
where the key lives:
| Mode | Key location | Consequence |
|---|---|---|
repokey |
stored inside the repository, protected by the passphrase | the passphrase alone must be guarded; a stolen repository copy plus a leaked passphrase exposes data |
keyfile |
stored on the client, protected by the passphrase | the repository alone is unreadable; the key file becomes a second secret that must be backed up (Section 15.5.3) |
authenticated |
integrity check only, no confidentiality | for data that must be readable without the client |
none |
no encryption or authentication | only for throwaway or already-encrypted targets |
A -blake2 suffix on any encrypted mode selects BLAKE2b instead of
SHA-256 for content-addressing; it changes the chunk IDs' hash, not
the security of the encryption. The walkthrough uses keyfile-blake2:
the repository on backup1 is then useless to anyone who steals only
the server, and the key file's custody is handled explicitly.
The repository lives on backup1, reached over SSH with a key that is only allowed to run Borg's server mode. Build that transport first, on client1, as root - two keys, with two different authorities:
# install -d -m 700 /etc/borg/ssh
# ssh-keygen -q -t ed25519 -N "" -f /etc/borg/ssh/id_ed25519_writer
# install -d -m 700 /root/.ssh
# ssh-keygen -q -t ed25519 -N "" -f /root/.ssh/id_ed25519_admin
All four commands are silent. The writer key in /etc/borg/ssh is the
identity the scheduled backup service will use to create archives.
The retention key in /root/.ssh performs every operation that
deletes or prunes, and later reaches the vault copy in Section 15.5;
holding it on a separate administrative host is the production shape,
and it stays on client1 here only so one machine can exercise both
roles. -N "" gives the keys no passphrases of their own - their
protection is the restricted authorized_keys entries on the server.
Record the writer key's identity:
# ssh-keygen -lf /etc/borg/ssh/id_ed25519_writer.pub
256 SHA256:v0CfIw1L54/j8Ad+kzXP3X7wmzVwUgvHflTFl6Teis0 root@client1 (ED25519)
Next, establish backup1's host identity rather than trusting whatever key answers on the network. On backup1, in an administrative session you already trust, as root:
# ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
256 SHA256:Xm8Moru9Y7izRhthpU3RAR+dfKwe7mOzZauAb9YZD88 root@trixie (ED25519)
That is the server's own key file read from the server itself. On client1, as root, collect what the network presents:
# ssh-keyscan -t ed25519 backup1
# backup1:22 SSH-2.0-OpenSSH_10.0p2 Debian-7+deb13u4
backup1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINGRrPZuKqIN9W+xyy5GMKjMbxTctqcwJpjgYflUHGcd
| Option | Description |
|---|---|
-t ed25519 |
request only this key type, keeping the output to one line |
ssh-keyscan fetches the host key but proves nothing by itself; the
collected key is trusted because its fingerprint matches the value
read from the server's own file in the trusted session. On the first
SSH connection to an unknown host, OpenSSH prints the fingerprint and
asks for exactly this comparison, then records the key in
~/.ssh/known_hosts; after that, any changed key is reported loudly
instead of silently accepted, and a changed key means investigating
the server before continuing, not deleting the old record. The
known-host record that results, in /root/.ssh/known_hosts, is the
one collected line:
backup1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINGRrPZuKqIN9W+xyy5GMKjMbxTctqcwJpjgYflUHGcd
Confirm that host-key checking is in force for this connection:
# ssh -G backup1 | grep -i stricthostkeychecking
stricthostkeychecking ask
ssh -G prints the effective configuration for the destination and
grep selects the one setting; ask is OpenSSH's default, meaning
unknown keys prompt and changed keys fail. Nothing in this chapter
disables it.
Give the writer key a fixed identity for the backup1 host name, as
the contents of /root/.ssh/config on client1:
Host backup1
User borgsvc
IdentityFile /etc/borg/ssh/id_ed25519_writer
IdentitiesOnly yes
With this, any SSH connection to backup1 from root on client1 uses
the writer key and the borgsvc account, and Borg inherits it
automatically. IdentitiesOnly yes prevents other keys in an agent
from being offered instead.
Now the server side. On backup1, as root, create the dedicated account and its directories:
# useradd -m -s /bin/bash borgsvc
# install -d -m 700 -o borgsvc -g borgsvc /home/borgsvc/.ssh /var/lib/borgsvc /var/lib/borgsvc/repos
Both commands are silent. The account's shell does not matter much -
its key will never reach a shell - but its repositories live under
/var/lib/borgsvc/repos, outside the home directory. Install the
client's writer public key as the account's entire
authorized_keys, with the forced command. The contents of
/home/borgsvc/.ssh/authorized_keys on backup1:
command="borg serve --restrict-to-path /var/lib/borgsvc/repos --append-only",restrict ssh-ed25519 <writer public key>
The placeholder stands for the entire one-line contents of
/etc/borg/ssh/id_ed25519_writer.pub copied from client1 - the key
type, the base64 key, and its comment - because key material is
unique per installation. Fix ownership and mode:
# chown -R borgsvc:borgsvc /home/borgsvc/.ssh && chmod 700 /home/borgsvc/.ssh && chmod 600 /home/borgsvc/.ssh/authorized_keys
The compound is silent. The line's two halves do the whole job:
command="borg serve ..." means this key can never open a shell - SSH
runs the forced command, with the client's requested repository path
passed to it by Borg; --restrict-to-path confines every repository
operation to the named directory; --append-only sets a storage
behavior whose exact limits are the subject of Section 15.5.1; and
restrict disables port forwarding, agent forwarding, X11
forwarding, and PTY allocation for this key. Section 15.5.4
demonstrates the confinement being tested.
Check that the restricted transport works before using it for real. On client1, as root:
# ssh -o BatchMode=yes backup1 borg --version
borg 1.4.0
The forced command answers with the server's Borg version: the
connection authenticated with the writer key, host verification passed
against the known-host record, and the account's world is one command
wide. (BatchMode=yes only disables password prompts and keyboard
interaction in this one-shot check; it does not touch host-key
checking.)
Create the repository, on client1, as root:
# BORG_PASSPHRASE=handbook-pass borg init --encryption=keyfile-blake2 ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
IMPORTANT: you will need both KEY AND PASSPHRASE to access this repo!
Key storage location depends on the mode:
- repokey modes: key is stored in the repository directory.
- keyfile modes: key is stored in the home directory of this user.
For any mode, you should:
1. Export the borg key and store the result at a safe place:
borg key export REPOSITORY encrypted-key-backup
borg key export --paper REPOSITORY encrypted-key-backup.txt
borg key export --qr-html REPOSITORY encrypted-key-backup.html
2. Write down the borg key passphrase and store it at safe place.
The URL is ssh://user@host/absolute-path, so the repository is the
client1 directory inside the allowed path; borg init creates it.
BORG_PASSPHRASE supplies the passphrase non-interactively for this
session's commands - handbook-pass is a practice value; use a long
random one and store it as Section 15.5.3 describes. Without the
variable, Borg prompts for the passphrase and does not echo what is
typed. The notice Borg prints is the custody warning for keyfile
mode: the repository key was just written to root's Borg key
directory on client1, and from this moment the key file and the
passphrase are two secrets, both required. Do what the notice says
immediately, while the repository is empty and the operation is
cheap:
# BORG_PASSPHRASE=handbook-pass borg key export ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1 /home/john/debian-handbook/backup-restore/borg-client1.key
The command prints nothing and writes the exported key as a file in john's workspace. Install a durable operational copy:
# install -m 600 -o root -g root /home/john/debian-handbook/backup-restore/borg-client1.key /etc/borg/client1.key
The command prints nothing; confirm the placement:
# ls -l /etc/borg/client1.key
-rw------- 1 root root 813 Nov 21 00:21 /etc/borg/client1.key
install placed the key root-owned and mode 600, and ls -l
confirms it: 813 bytes. This copy is the one restore procedures point
at with BORG_KEY_FILE; Section 15.5.3 puts another copy on offline
media, and Borg's --paper and --qr-html export forms exist for
custody that prefers printout over files.
Put one file in john's source directory so the repository carries home-directory data too - on client1, in john's shell:
$ printf "example source file\n" >/home/john/debian-handbook/backup-restore/source/notes.txt
The redirection writes the file; nothing is printed. Create the first archive, on client1, as root:
# cd /home/john/debian-handbook/backup-restore && BORG_PASSPHRASE=handbook-pass borg create --stats --compression zstd,6 --exclude-from exclude.txt ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1200 /srv /etc/postgresql /home/john/debian-handbook/backup-restore/source
------------------------------------------------------------------------------
Repository: ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Archive name: client1-2026-11-20T1200
Archive fingerprint: 983994716d20fca6b7081842012dde75852319f8392221a5575e40ac81a06e0c
Time (start): Sat, 2026-11-21 00:21:42
Time (end): Sat, 2026-11-21 00:21:42
Duration: 0.73 seconds
Number of files: 10
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
This archive: 43.08 kB 15.30 kB 15.30 kB
All archives: 42.38 kB 14.64 kB 16.60 kB
Unique chunks Total chunks
Chunk index: 12 12
------------------------------------------------------------------------------
(Borg writes its status output to standard error; the block shows the
command's output as it appears in the terminal.) The cd puts the
shell where the relative exclude.txt resolves. borg create names
the archive after the ::, walks the three given paths, and stores
them relative - srv/..., etc/postgresql/...,
home/john/... - which is why restores later specify paths without a
leading slash.
| Option | Description |
|---|---|
--stats |
print the transfer and deduplication summary |
--compression zstd,6 |
compress chunks with zstd at level 6 |
--exclude-from FILE |
skip paths listed in FILE |
--one-file-system |
do not cross filesystem boundaries (used in Section 15.7.1) |
The numbers: the tree's 43.08 kB compressed to 15.30 kB, and with no
earlier archive to deduplicate against, all of it is new storage -
the second archive below shows the same tree costing 722 bytes. The
walkthrough creates several archives in one sitting, named for the
exercise, so that versioning and retention can be shown without
waiting for a schedule; on a real host the naming pattern
client1-YYYY-MM-DDTHHMM is filled in by the scheduler, once per
backup window.
Change the data so the next archive has something to deduplicate against - on client1, in john's shell:
$ printf "quarterly report final\n" >/srv/appdata/reports/quarterly.txt
The redirection writes the file; nothing is printed. As root, restore its ownership and take the second archive:
# chown john:www-data /srv/appdata/reports/quarterly.txt && chmod 0640 /srv/appdata/reports/quarterly.txt
Both parts are silent. Take the second archive:
# cd /home/john/debian-handbook/backup-restore && BORG_PASSPHRASE=handbook-pass borg create --stats --compression zstd,6 --exclude-from exclude.txt ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1300 /srv /etc/postgresql /home/john/debian-handbook/backup-restore/source
------------------------------------------------------------------------------
Repository: ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Archive name: client1-2026-11-20T1300
Archive fingerprint: 57cbaa2c23655cd9116d04122e5c9644b6e151cd2f60fc64787e02f015004550
Time (start): Sat, 2026-11-21 00:21:55
Time (end): Sat, 2026-11-21 00:21:56
Duration: 0.93 seconds
Number of files: 10
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
This archive: 43.07 kB 15.30 kB 722 B
All archives: 84.76 kB 29.29 kB 18.62 kB
Unique chunks Total chunks
Chunk index: 15 24
------------------------------------------------------------------------------
The same tree, one changed file, cost 722 bytes of new storage: every other chunk already existed in the repository, identified by content. List what the repository now holds:
# BORG_PASSPHRASE=handbook-pass borg list ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
client1-2026-11-20T1200 Sat, 2026-11-21 00:21:42 [983994716d20fca6b7081842012dde75852319f8392221a5575e40ac81a06e0c]
client1-2026-11-20T1300 Sat, 2026-11-21 00:21:55 [57cbaa2c23655cd9116d04122e5c9644b6e151cd2f60fc64787e02f015004550]
Two archives with names and fingerprints. Find out what changed between them:
# BORG_PASSPHRASE=handbook-pass borg diff ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1200 client1-2026-11-20T1300
+23 B -25 B [ctime: Sat, 2026-11-21 00:21:07 -> Sat, 2026-11-21 00:21:49] [mtime: Sat, 2026-11-21 00:21:05 -> Sat, 2026-11-21 00:21:47] srv/appdata/reports/quarterly.txt
Exactly one path differs, with the size delta and the timestamps that
changed with it - the revision made in between. borg diff between
two archive names inside the same repository is the tool for
"what did the backup actually capture". Look inside one archive:
# BORG_PASSPHRASE=handbook-pass borg list ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1300
drwxr-xr-x root root 0 Sat, 2026-11-21 00:19:49 srv
drwxr-xr-x john john 0 Sat, 2026-11-21 00:19:53 srv/appdata
drwx------ root root 0 Sat, 2026-11-21 00:19:47 srv/appdata/lost+found
drwxr-xr-x john john 0 Sat, 2026-11-21 00:20:55 srv/appdata/reports
-rw-r----- john www-data 23 Sat, 2026-11-21 00:21:47 srv/appdata/reports/quarterly.txt
drwxr-xr-x john john 0 Sat, 2026-11-21 00:20:02 srv/appdata/config
-rw-r----- www-data www-data 51 Sat, 2026-11-21 00:19:54 srv/appdata/config/app.conf
hrw-r----- www-data www-data 0 Sat, 2026-11-21 00:19:54 srv/appdata/config/app.conf.bak link to srv/appdata/config/app.conf
lrwxrwxrwx root root 8 Sat, 2026-11-21 00:20:02 srv/appdata/config/app.conf.current -> app.conf
drwxrwsr-x john john 0 Sat, 2026-11-21 00:19:53 srv/appdata/shared
drwxr-x--- postgres postgres 0 Sat, 2026-11-21 00:20:18 srv/appdata/dumps
-rw-rw-r-- postgres postgres 1709 Sat, 2026-11-21 00:20:18 srv/appdata/dumps/inventory.dump
drwxr-xr-x postgres postgres 0 Sat, 2026-11-21 00:15:20 etc/postgresql
drwxr-xr-x postgres postgres 0 Sat, 2026-11-21 00:15:20 etc/postgresql/17
drwxr-xr-x postgres postgres 0 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main
-rw-r--r-- postgres postgres 317 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/start.conf
-rw-r--r-- postgres postgres 143 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/pg_ctl.conf
-rw-r----- postgres postgres 2640 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/pg_ident.conf
-rw-r----- postgres postgres 5924 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/pg_hba.conf
-rw-r----- postgres postgres 315 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/environment
drwxr-xr-x postgres postgres 0 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/conf.d
-rw-r--r-- postgres postgres 31238 Sat, 2026-11-21 00:15:22 etc/postgresql/17/main/postgresql.conf
drwxr-xr-x john john 0 Sat, 2026-11-21 00:21:35 home/john/debian-handbook/backup-restore/source
-rw-rw-r-- john john 20 Sat, 2026-11-21 00:21:35 home/john/debian-handbook/backup-restore/source/notes.txt
Every preservation target from Section 15.3.1 appears: the hard link
prints with its link to relationship, the symlink carries its
target, shared keeps its setgid rws, the postgres-owned dump
directory keeps mode r-x---, and both the service configuration
under /etc/postgresql and john's home file are present. The ACL and
extended attribute on app.conf do not show in this listing format;
Section 15.6.2 proves them by extracting and re-running the baseline
inspections. This listing is also the restore catalog: the paths it
prints are exactly the patterns a selective borg extract accepts.
15.4.2. Backing Up to a Restricted Remote Account
The account built in Section 15.4.1 deserves its design stated in one
place, because every property in this chapter depends on it.
borgsvc has no password, no shell access, and no command of its own:
its authorized_keys line replaces whatever the client asks to run
with borg serve, and --restrict-to-path /var/lib/borgsvc/repos
makes every repository operation - init, create, list, extract, and
also delete and prune - apply only inside that directory tree. The
restrict option removes everything except that command: no
forwarding of ports, agents, or X11, no PTY, no scp, no shell. A
stolen writer key can do Borg operations on one directory and
nothing else.
The URL the client uses decides which account and path are reached:
ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1 names the
account, the host, and an absolute path the forced command will be
given. To use a different identity for one command without editing
/root/.ssh/config, Borg accepts the whole SSH invocation through
the BORG_RSH environment variable - Section 15.4.4 uses it to run
retention with the retention key, and Section 15.5.2 uses it to reach
the vault. borg serve --help lists the server-side options the
forced command can carry, including a per-repository
--restrict-to-repository (stricter than --restrict-to-path, which
allows the whole directory tree) and --storage-quota, which caps
how much the account can store - a useful ceiling for a backup
account whose client you do not fully control.
Two consequences of the design are worth stating now. First, the
restriction is per-account, not per-key: any key installed for
borgsvc gains the same one-command world, so the account's
authorized_keys is the whole access-control list and stays as short
as the line installed in Section 15.4.1. Second, the writer account
can still delete what it can write - append-only or not. That limit
is demonstrated rather than assumed in Section 15.5.1, and it is the
reason the vault account exists at all.
15.4.3. Scheduling Backups and Capturing Failures
A backup schedule is a systemd timer plus a script, following the
pattern of Chapter 10: the timer triggers a
oneshot service, the service runs one backup, and a failure leaves
the unit in a failed state where systemctl and the journal show it
- the property a silent cron line lacks. The credentials the script
needs live in root-owned files, not in the script itself.
Store the passphrase and the exclusion list where the service can read them, on client1, as root:
# printf '%s\n' 'handbook-pass' >/etc/borg/passphrase && chmod 600 /etc/borg/passphrase
# cp /home/john/debian-handbook/backup-restore/exclude.txt /etc/borg/exclude.txt && chmod 600 /etc/borg/exclude.txt
Both commands are silent: the redirection writes the passphrase file
and chmod restricts it to root, then the exclusion list is copied
beside it. The backup script is a distinct artifact - the contents
of /usr/local/sbin/borg-backup-client1 on client1:
#!/bin/sh
set -eu
export BORG_PASSPHRASE="$(cat /etc/borg/passphrase)"
REPO="ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1"
ARCHIVE="client1-$(date +%Y-%m-%dT%H%M%S)"
exec borg create --stats --compression zstd,6 \
--exclude-from /etc/borg/exclude.txt \
"$REPO::$ARCHIVE" /srv /etc/postgresql \
/home/john/debian-handbook/backup-restore/source
Make it executable:
# chmod 755 /usr/local/sbin/borg-backup-client1
The command prints nothing. The script reads the passphrase from the
root-owned file into the environment for one run, names each archive
with the scheduler's own timestamp, and backs up the same three paths
as the manual archives so the retention example in Section 15.4.4
sees a uniform series. set -eu makes any failure - a missing
passphrase file, an unreachable repository - exit nonzero, which is
what turns a broken backup into a visible unit failure. The unit that
runs it, /etc/systemd/system/borg-backup.service on client1:
[Unit]
Description=Back up client1 to the Borg repository
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/borg-backup-client1
Nice=10
IOSchedulingClass=idle
And the timer, /etc/systemd/system/borg-backup.timer on client1:
[Unit]
Description=Daily Borg backup for client1
[Timer]
OnCalendar=daily
RandomizedDelaySec=15m
Persistent=true
[Install]
WantedBy=timers.target
Nice=10 and IOSchedulingClass=idle keep the backup politely out
of the way of interactive work, as Chapter 9
describes. OnCalendar=daily fires at midnight, RandomizedDelaySec
spreads the load, and Persistent=true runs a missed backup at the
next boot, so a machine that was asleep at midnight still backs up.
Load the units and enable the timer:
# systemctl daemon-reload
# systemctl enable --now borg-backup.timer
Created symlink '/etc/systemd/system/timers.target.wants/borg-backup.timer' → '/etc/systemd/system/borg-backup.timer'.
daemon-reload is silent; enable --now creates the timer's symlink
and starts it. Run the service once by hand to test the whole chain
without waiting for midnight:
# systemctl start borg-backup.service
The start is silent - the oneshot runs and exits. Inspect it:
# systemctl status --no-pager borg-backup.service
○ borg-backup.service - Back up client1 to the Borg repository
Loaded: loaded (/etc/systemd/system/borg-backup.service; static)
Active: inactive (dead) since Sat 2026-11-21 00:22:43 UTC; 1s ago
Invocation: a3c4bc344d0e48388f29c89cdef8e5d2
TriggeredBy: ● borg-backup.timer
Process: 10055 ExecStart=/usr/local/sbin/borg-backup-client1 (code=exited, status=0/SUCCESS)
Main PID: 10055 (code=exited, status=0/SUCCESS)
Mem peak: 66.9M
CPU: 370ms
Nov 21 00:22:43 client1 borg-backup-client1[10055]: ------------------------------------------------------------------------------
Nov 21 00:22:43 client1 borg-backup-client1[10055]: Original size Compressed size Deduplicated size
Nov 21 00:22:43 client1 borg-backup-client1[10055]: This archive: 43.09 kB 15.29 kB 645 B
Nov 21 00:22:43 client1 borg-backup-client1[10055]: All archives: 127.14 kB 43.93 kB 19.27 kB
Nov 21 00:22:43 client1 borg-backup-client1[10055]: Unique chunks Total chunks
Nov 21 00:22:43 client1 borg-backup-client1[10055]: Chunk index: 16 36
Nov 21 00:22:43 client1 borg-backup.service: Deactivated successfully.
Nov 21 00:22:43 client1 systemd[1]: Finished borg-backup.service - Back up client1 to the Borg repository.
Nov 21 00:22:43 client1 systemd[1]: borg-backup.service: Consumed 370ms CPU time, 66.9M memory peak.
The ○ marker and inactive (dead) mean the oneshot completed;
status=0/SUCCESS is the run's exit code, and the log excerpt shows
the archive statistics the script's --stats printed. systemctl
status on a completed oneshot exits 3, an expected nonzero status
for "unit is not running", not a failure of the backup. Check the
timer's next firing:
# systemctl list-timers --no-pager borg-backup.timer
NEXT LEFT LAST PASSED UNIT ACTIVATES
Sun 2026-11-22 00:10:39 UTC 23h - - borg-backup.timer borg-backup.service
1 timers listed.
Pass --all to see loaded but inactive timers, too.
The timer is armed for the next midnight window with its randomized delay.
Now break it deliberately, because a schedule is only trustworthy if its failures are loud. Move the passphrase out of place:
# mv /etc/borg/passphrase /etc/borg/passphrase.off
The command is silent. Trigger a run:
# systemctl start borg-backup.service
Job for borg-backup.service failed because the control process exited with error code.
See "systemctl status borg-backup.service" and "journalctl -xeu borg-backup.service" for details.
The start command itself reports the failure. The status:
# systemctl status --no-pager borg-backup.service
× borg-backup.service - Back up client1 to the Borg repository
Loaded: loaded (/etc/systemd/system/borg-backup.service; static)
Active: failed (Result: exit-code) since Sat 2026-11-21 00:22:55 UTC; 1s ago
Invocation: c78be4a97a774687ba45f62487173c
TriggeredBy: ● borg-backup.timer
Process: 10138 ExecStart=/usr/local/sbin/borg-backup-client1 (code=exited, status=2)
Main PID: 10138 (code=exited, status=2)
Mem peak: 66.8M
CPU: 354ms
Nov 21 00:22:50 client1 systemd[1]: Starting borg-backup.service - Back up client1 to the Borg repository...
Nov 21 00:22:50 client1 borg-backup-client1[10139]: cat: /etc/borg/passphrase: No such file or directory
Nov 21 00:22:55 client1 borg-backup-client1[10138]: passphrase supplied in BORG_PASSPHRASE, by BORG_PASSCOMMAND or via BORG_PASSPHRASE_FD is incorrect.
Nov 21 00:22:55 client1 systemd[1]: borg-backup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 21 00:22:55 client1 systemd[1]: borg-backup.service: Failed with result 'exit-code'.
Nov 21 00:22:55 client1 systemd[1]: Failed to start borg-backup.service - Back up client1 to the Borg repository.
Nov 21 00:22:55 client1 systemd[1]: borg-backup.service: Consumed 354ms CPU time, 66.8M memory peak.
The × marker and failed state are visible from systemctl
--failed on any later day - nothing failed silently. The log lines
show the exact cause: the script's cat found no passphrase file, and
Borg then rejected the empty value. The same diagnosis works from the
journal alone, as Chapter 8 describes:
# journalctl -u borg-backup.service --no-pager -n 12
Nov 21 00:22:43 client1 borg-backup-client1[10055]: Chunk index: 16 36
Nov 21 00:22:43 client1 borg-backup-client1[10055]: ------------------------------------------------------------------------------
Nov 21 00:22:43 client1 systemd[1]: borg-backup.service: Deactivated successfully.
Nov 21 00:22:43 client1 systemd[1]: Finished borg-backup.service - Back up client1 to the Borg repository.
Nov 21 00:22:43 client1 systemd[1]: borg-backup.service: Consumed 370ms CPU time, 66.9M memory peak.
Nov 21 00:22:50 client1 systemd[1]: Starting borg-backup.service - Back up client1 to the Borg repository...
Nov 21 00:22:50 client1 borg-backup-client1[10139]: cat: /etc/borg/passphrase: No such file or directory
Nov 21 00:22:55 client1 borg-backup-client1[10138]: passphrase supplied in BORG_PASSPHRASE, by BORG_PASSCOMMAND or via BORG_PASSPHRASE_FD is incorrect.
Nov 21 00:22:55 client1 systemd[1]: borg-backup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 21 00:22:55 client1 systemd[1]: borg-backup.service: Failed with result 'exit-code'.
Nov 21 00:22:55 client1 systemd[1]: Failed to start borg-backup.service - Back up client1 to the Borg repository.
Nov 21 00:22:55 client1 systemd[1]: borg-backup.service: Consumed 354ms CPU time, 66.8M memory peak.
The last twelve lines hold both the successful run and the failed one, with the failing step named. Repair and rerun:
# mv /etc/borg/passphrase.off /etc/borg/passphrase
# systemctl start borg-backup.service
Both commands are silent - the backup runs again and succeeds. Confirm the unit left the failed state:
# systemctl is-failed borg-backup.service
inactive
is-failed prints the unit's state and exits nonzero when that state
is anything but failed: inactive with exit status 1 is the healthy
answer here, meaning the oneshot finished and is no longer marked
failed. The two manual runs each created a timestamped archive -
client1-2026-11-21T002235 from the first and
client1-2026-11-21T002302 from this second one - and both appear
in the next section's prune listing.
15.4.4. Pruning, Compacting, Checking, and Planning Repository Capacity
Retention deletes archives on purpose, so two rules govern it. It runs against a stated policy, not by hand-picking; and it runs with the retention key, not the writer key - deletion authority is deliberately kept apart from backup creation, for the reasons Section 15.5 turns into a recovery property. Create two more archives so the policy has something to remove. On client1, as root:
# cd /home/john/debian-handbook/backup-restore && BORG_PASSPHRASE=handbook-pass borg create --stats --compression zstd,6 --exclude-from exclude.txt ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1400 /srv /etc/postgresql /home/john/debian-handbook/backup-restore/source
------------------------------------------------------------------------------
Repository: ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Archive name: client1-2026-11-20T1400
Archive fingerprint: e2951d848cd3bd64d1dc29baa1411cc127acfdf3483cd3de88934486bb0359e7
Time (start): Sat, 2026-11-21 00:23:18
Time (end): Sat, 2026-11-21 00:23:18
Duration: 0.01 seconds
Number of files: 10
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
This archive: 43.07 kB 15.28 kB 641 B
All archives: 211.90 kB 73.22 kB 20.56 kB
Unique chunks Total chunks
Chunk index: 18 60
------------------------------------------------------------------------------
Create the fourth archive the same way, named
client1-2026-11-20T1500:
# cd /home/john/debian-handbook/backup-restore && BORG_PASSPHRASE=handbook-pass borg create --stats --compression zstd,6 --exclude-from exclude.txt ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1::client1-2026-11-20T1500 /srv /etc/postgresql /home/john/debian-handbook/backup-restore/source
------------------------------------------------------------------------------
Repository: ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Archive name: client1-2026-11-20T1500
Archive fingerprint: 34649f801e067fd57ddffd7e9f20cb5f728bd56361325ce0ba2cf9d647f7d3aa
Time (start): Sat, 2026-11-21 00:23:29
Time (end): Sat, 2026-11-21 00:23:29
Duration: 0.01 seconds
Number of files: 10
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
This archive: 43.07 kB 15.28 kB 641 B
All archives: 254.28 kB 87.86 kB 21.20 kB
Unique chunks Total chunks
Chunk index: 19 72
------------------------------------------------------------------------------
Its summary differs from the third only in the running totals. The repository now holds six archives: the four named for the exercise and the two the scheduled service created. Run retention with the retention key - on client1, as root:
# BORG_RSH='ssh -i /root/.ssh/id_ed25519_admin -o IdentitiesOnly=yes' BORG_PASSPHRASE=handbook-pass borg prune --list --keep-last 3 ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Keeping archive (rule: secondly #1): client1-2026-11-20T1500 Sat, 2026-11-21 00:23:29 [34649f801e067fd57ddffd7e9f20cb5f728bd56361325ce0ba2cf9d647f7d3aa]
Keeping archive (rule: secondly #2): client1-2026-11-20T1400 Sat, 2026-11-21 00:23:18 [e2951d848cd3bd64d1dc29baa1411cc127acfdf3483cd3de88934486bb0359e7]
Keeping archive (rule: secondly #3): client1-2026-11-21T002302 Sat, 2026-11-21 00:23:07 [4f5bc6329c22cfb84a31c7011ac0bd4dae95e28a92022c9b82e4ef97ec5ebf67]
Pruning archive (1/3): client1-2026-11-21T002235 Sat, 2026-11-21 00:22:39 [dc588d35097eafefa374dc872026c5aa1736e9e1d204f9c157d82e82e193077]
Pruning archive (2/3): client1-2026-11-20T1300 Sat, 2026-11-21 00:21:55 [57cbaa2c23655cd9116d04122e5c9644b6e151cd2f60fc64787e02f015004550]
Pruning archive (3/3): client1-2026-11-20T1200 Sat, 2026-11-21 00:21:42 [983994716d20fca6b7081842012dde75852319f8392221a5575e40ac81a06e0c]
| Option | Description |
|---|---|
--keep-last N |
always keep the N most recent archives |
--keep-daily N |
keep the newest archive on each of the last N distinct days that have one |
--keep-weekly N |
same rule per ISO week |
--keep-monthly N |
same rule per month |
--list |
print each archive with the rule that kept or pruned it |
--dry-run |
show what a prune would remove without removing it |
BORG_RSH replaces the SSH command Borg runs, so this one invocation
authenticates with the retention key from /root/.ssh instead of the
writer key that /root/.ssh/config selects - same repository, same
account, deliberately different authority. --keep-last 3 kept the
three newest archives - including client1-2026-11-21T002302, which
the timer's script created - and removed the three oldest, with
--list naming the rule beside each. The "secondly" label in the
output is how prune reports the finest time bucket when the archives
all fall inside one day; a real schedule's policy is calendar-based
instead:
# BORG_RSH='ssh -i /root/.ssh/id_ed25519_admin -o IdentitiesOnly=yes' borg prune --list --keep-daily 7 --keep-weekly 4 --keep-monthly 6 ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
That command is the production form of the policy - one archive per
day for a week, one per week for a month, one per month for half a
year - with --dry-run as the safe rehearsal. Prune marks archives
deleted; the space is returned by compaction:
# BORG_PASSPHRASE=handbook-pass borg compact ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
The command is silent. borg compact rewrites segment files without
the deleted archives' chunks; Borg 1.4 separates this from prune so
large repositories can compact on their own schedule rather than
inside every retention run. Verify the repository's integrity:
# BORG_PASSPHRASE=handbook-pass borg check --verify-data ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
The command is silent on success. borg check validates the
repository's structure and the archives' metadata;
--verify-data additionally reads every stored chunk and checks its
authentication code, which is what turns "the server says the files
are fine" into "the bytes are provably intact". It costs a full read
of the repository, so it belongs on a schedule - weekly is a common
choice, added as a second timer like the backup's - rather than in
the backup path. Summarize the repository:
# BORG_PASSPHRASE=handbook-pass borg info ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Repository ID: 36b606e9207f5c0742bb840f28bd9e9ef199bfd3d929d18751195a71c7301145
Location: ssh://borgsvc@backup1/var/lib/borgsvc/repos/client1
Encrypted: Yes (key file BLAKE2b)
Key file: /root/.config/borg/keys/backup1__var_lib_borgsvc_repos_client1
Cache: /root/.cache/borg/36b606e9207f5c0742bb840f28bd9e9ef199bfd3d929d18751195a71c7301145
Security dir: /root/.config/borg/security/36b606e9207f5c0742bb840f28bd9e9ef199bfd3d929d18751195a71c7301145
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
All archives: 127.14 kB 43.93 kB 17.88 kB
Unique chunks Total chunks
Chunk index: 14 36
The Key file: line records where the client-side key lives -
/root/.config/borg/keys/, named after the location - and
Section 15.7.3 makes that dependency visible by removing it. The
capacity lines say the practice tree's three archives hold 127 kB
original, 17.88 kB after deduplication, in 14 unique chunks. Measure
the real footprint on the server - on backup1, as root:
# du -sh /var/lib/borgsvc/repos/client1 && df -h /var/lib/borgsvc
228K /var/lib/borgsvc/repos/client1
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 98G 971M 92G 2% /
The directory uses 228K on a filesystem with 92G available. Capacity
planning for a repository follows from three numbers, all visible in
the commands above: the original data size, the deduplicated size of
one backup window's new data, and the retention window. The practice
tree's whole-root archive in Section 15.7.1 measures the scale-up -
26,772 files and 973 MB of system stored as 431 MB of unique chunks -
so a week of daily whole-root backups with modest daily change is
roughly that archive plus a week's worth of deltas, plus headroom for
the day the change is large. Two guardrails keep the arithmetic
honest: df watched on the server, since a full repository fails
every backup at once, and Borg's --storage-quota on the writer
account as the hard ceiling that turns a runaway client into a
single account's problem.