borg extract vs mount + rsync: which restore to use
Use borg extract. mount + rsync pays off only when few files changed, none carry ACLs and the repository is far away; here is how to tell, with a calculator.
A restore from a borg repository goes one of two ways. borg extract pulls the whole archive in one stream. borg mount exposes it over FUSE, and rsync copies only the files that differ from what is already on disk.
Use extract. Reach for mount + rsync only when the files are still on disk, few of them changed, and none carry ACLs, which borg mount on 1.x drops. "Few" means fewer than the round trips a full extract would take: the extract time divided by your ping to the repository, both in milliseconds.
Put your own link in and the article speaks in your numbers:
A full extract takes at least, s
mount + rsync is faster if fewer files changed than
| Situation | Choice |
|---|---|
| Empty disk, new machine, disaster recovery | extract |
| Anything with ACLs: the system, services | extract on borg 1.x |
| borg 2.0 (beta) | extract |
| Repository on a local disk | either, the difference is seconds |
| Files in place, few changed, no ACLs | mount + rsync |
| A link that loses packets | mount + rsync wins far longer |
When mount + rsync is faster
mount + rsync skips unchanged files almost for free: only the archive's metadata is read, so 200 thousand unchanged files cost 3–4 seconds even over a WAN. Every changed file, though, costs one network round trip plus about 0.2 ms: 31 ms per file over a WAN with 30 ms latency, 0.7 ms over a LAN. extract downloads everything in one stream at the speed of the link. So the question is only how many files changed, and the archive tells you in seconds:
borg mount REPO::<archive> /mnt/borg
rsync -ain --delete /mnt/borg/home/user/ \
/home/user/ | grep -c '^>f'Compare that count with the number above: the extract time in milliseconds divided by your ping plus 0.2 ms. The extract time is a lower bound from size and bandwidth; over a 1 Gbit/s LAN a real extract moves 200–880 Mbit/s, and timing one directory of known size onto a real disk is more honest than the estimate. Compression helps less than its ratio: over a WAN, lz4 made the extract about 2× faster, zstd about 1.5×. For files of 100 KB and more the real threshold is up to 2.7× lower, because reading their data through FUSE costs more than the round trip alone.
Packet loss changes the picture: extract is one TCP stream and suffers, mount + rsync barely notices. At 1 % loss a 28-second extract takes 433 seconds, while syncing 1 % changed files goes from 18 to 26 seconds. ping -c 100 <host> reports the loss; on such a link only a timed extract counts. With every file changed, mount + rsync over the network was 1.2 to 16 times slower than extract.
When the count is under the threshold and the tree has no ACLs (getfacl -Rs /path 2>/dev/null | head prints nothing), the restore is:
sudo rsync -aHXS --delete --backup \
--backup-dir=/home/.restore-trash-$(date +%F) \
/mnt/borg/home/user/ /home/user/
borg umount /mnt/borg--backup-dir keeps everything overwritten or deleted. Never add -c: it reads every file in full through FUSE.
What borg mount loses
On borg 1.x, with the rsync columns over a mounted archive:
| Kept by | extract |
extract --sparse |
rsync -a |
rsync -aHXS |
|---|---|---|---|---|
| ACLs | yes | yes | lost | lost |
| xattrs, capabilities | yes | yes | lost | yes |
| hard links | yes | yes | two copies | yes |
| sparse file, 512 MB with 4 KB used | 512 MB | 8 MB | 512 MB | 4 KB |
borg mount on 1.x does not show ACLs at all, so no rsync flag can bring them back, and losing one widens access: a file with mode 644 and an ACL giving a group write access shows 664 as its plain mode; after mount + rsync the ACL is gone and 664 stays. borg 2 shows ACLs through mount. extract restores everything, with --sparse for sparse files and --numeric-ids on a fresh system where your users do not exist yet.
borg 2.0.0b25
mount fetches whole pack files of about 50 MB, so as soon as 1 % of scattered files is needed, mount + rsync takes as long as extract. Mounting itself takes up to 28 seconds over a WAN against 4 on borg 1.4, and its daemon mode hangs on large files, while -f works. On borg 2: extract. borg 1.2 behaves like 1.4.