Lesson 6 of 13 · 18m
The Tools: restic, borg, and Friends
restic and borg for files, pgBackRest and mariabackup for databases, Litestream for SQLite — matched to engine and restore target.
Backup tools are not interchangeable — each sits at a layer (blocks, files, database pages, logical rows) and each carries its own consistency and cost model. Match the tool to the engine and the restore target; the wrong layer is how you get torn copies and missing WAL.
File layer: restic and borg
restic is the general-purpose answer: every repository is deduplicated (content-defined chunking) and encrypted client-side — AES-256-CTR with Poly1305 authentication, mandatory, not optional. Backends are wherever you keep storage: s3:bucket/path, b2:, SFTP, or rclone: for anything rclone reaches. The working commands are restic backup /srv, restic snapshots, restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12, restic restore latest --target /restore, and restic check --read-data-subset=5% for integrity sampling — bare restic check verifies structure and indexes without hashing pack contents, so the --read-data* flags are the ones that actually read bytes. restic mount exposes the repo as a FUSE filesystem for browse-and-grab restores, and restic copy replicates selected snapshots between repositories — the clean way to make the second leg of 3-2-1 without re-reading the source.
borg is the same class — dedup, authenticated client-side encryption — with one feature restic lacks: borg serve --append-only. Front the repo with a forced SSH command and the source host can create archives but cannot delete them, which matters when the source is the thing likely to be compromised. One ops detail that bites: borg delete/forget mark space reclaimable, but borg compact is what returns it to the filesystem — a repo grows until someone schedules compaction.
rsync/rsnapshot still earn their place for dumb, inspectable copies: rsync -a --link-dest= hardlinks unchanged files into per-run trees — full-looking, incrementally priced. No encryption, no object store; it is a mirror of trees, so --delete propagates deletions. -a covers perms, ownership, and timestamps but not ACLs or xattrs — add -A/-X or SELinux labels and POSIX ACLs silently vanish from the copy. Cheap and honest, as long as the destination is a different failure domain.
Database layer: match the engine
Postgres. pg_dump/pg_restore are logical: pg_dump -Fc (custom format) or -Fd (directory, enables pg_restore -j parallel). Portable across major versions, selective-restore friendly (pg_restore -t orders), consistent via snapshot — but dump time and single-threaded writes stop scaling in the hundreds-of-gigabytes range. pg_basebackup -X stream is physical: the whole cluster plus the WAL needed to self-consistent-ize. pgBackRest, wal-g, and barman are the real backup managers: full/differential/incremental physical backups plus WAL archiving, which is what turns a base backup into point-in-time recovery. pgBackRest organizes clusters into stanzas, and pgbackrest check verifies WAL archiving is actually reaching the repo — the config-time cousin of a restore test.
MySQL/MariaDB. mariabackup (the Percona XtraBackup fork) does hot physical InnoDB backups — no lock, full cluster, prepare step on restore (--prepare replays the redo log into the copy). mysqldump --single-transaction is the logical path, consistent only for transactional engines; add --source-data/--master-data to record the binlog coordinates of the dump, which is what makes point-in-time replay possible on top of it.
SQLite. sqlite3 db ".backup out.db" is the online API. Litestream deserves naming: it streams WAL frames to object storage continuously, turning a file database into something with a near-zero RPO and per-second restore points. For the pile of small self-hosted apps that run on one SQLite file, it is the correct tool, full stop.
ZFS/Btrfs. zfs send -i incremental replication is the filesystem-native backup for pools — sanoid/syncoid automate the snapshot-plus-send cadence.
Choosing
Logical when you need portability, selective restores, or cross-version moves. Physical when the dataset is large or you need PITR. Dedup repo (restic/borg) for the filesystem layer around the databases — /etc, uploads, app trees. Engine-native streaming (Litestream, zfs send, WAL archive) where a file copy would tear. One deliberate tool per stateful thing; "nightly tar of /" is a consistency incident waiting for its day in court.
The sane default stack for a self-hosted Postgres app: pgBackRest pushing physical backups and WAL to object storage, restic covering /etc, /srv, and the app trees into a second repository under different credentials, Litestream on any SQLite stragglers. Each layer chosen because its consistency model matches what it protects — and each producing an artifact the restore runbook can name.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
Running a Minecraft Network: Four JVMs, One Box, and the Settings That Lie to You
Four servers on one host means four JVMs each sizing its thread pools for a machine it does not own. The measured cost of that, the systemd ordering that guarantees nothing, and the throttle that switches itself back on when your forwarding breaks.
Building a Minecraft Network: Four Servers Pretending to Be One Place
A proxy, a lobby, an SMP and a PvP arena is four JVMs that know nothing about each other. What actually has to be shared, why your permissions don't follow players, and the two LuckPerms defaults that silently share nothing at all.