Skip to content

About

A layered, monitored 3-2-1 backup setup for a homelab, built from small shell scripts and systemd timers. Pull data, let a snapshotting filesystem own the history, push an encrypted copy offsite, and alert if any layer goes stale.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

homelab-backup

A layered, monitored 3-2-1 backup setup for a homelab, built from small shell scripts and systemd timers. Pull data, let a snapshotting filesystem own the history, push an encrypted copy offsite, and alert if any layer goes stale.

Three tiers:

  source host  --(pull)-->  local staging  --(snapshot)-->  point-in-time history
                                  |
                                  '--(borg)-->  encrypted, deduped offsite

Design decisions worth a look

The scripts are short; the reasoning is the point.

  • Pull, not push. The backup host reaches out to the source over SSH. A source box that gets compromised has no path to the backups or their history, it can't reach in and delete them.
  • Consistent SQLite dumps before rsync. A live .db copied mid-write is a torn, possibly corrupt file. backup-pull.sh runs SQLite's online .backup on the remote first, then rsyncs the clean .bak. No torn databases.
  • Snapshots are the history, not --link-dest. The pull uses rsync --delete to keep an exact mirror, then a CoW filesystem (ZFS via sanoid, or btrfs via btrbk) takes an atomic snapshot. That's cheaper than hardlink trees, prunes cleanly on a retention ladder, and the snapshot is taken after a complete pull, never mid-rsync.
  • Freshness is gated on success. The _last_success_timestamp marker (and its Prometheus textfile metric) is written only when every path pulled cleanly. So a partial or failed run leaves the timestamp stale, and monitoring alerts on it. A backup that silently half-fails is worse than one that loudly fails.
  • Offsite is encrypted and deduped. backup-offsite.sh uses borg (zstd, client-side encryption) to a remote repo, with its own retention. The passphrase is read from a file, never inline in the script.
  • Timers don't collide. The pull runs hourly; the offsite runs at a fixed early hour so it never overlaps a top-of-hour pull.

Layout

pull/backup-pull.sh          rsync data + consistent SQLite dumps + freshness marker
offsite/backup-offsite.sh    borg push to an encrypted offsite repo
snapshots/sanoid.conf.example   ZFS snapshot retention templates
snapshots/btrbk.conf.example    btrfs snapshot + off-box send config
systemd/                     .service + .timer for the pull and offsite jobs

Setup

  1. Pull: edit the CONFIG block in pull/backup-pull.sh (remote host, paths, SQLite DBs), install it to /usr/local/bin/, and enable backup-pull.timer.
  2. Snapshots: put sanoid.conf.example at /etc/sanoid/sanoid.conf (ZFS) or btrbk.conf.example at /etc/btrbk/btrbk.conf (btrfs), adjust the datasets/retention. The pull calls sanoid --cron after a successful run.
  3. Offsite: edit the repo + BORG_PASSPHRASE file path in offsite/backup-offsite.sh, install it, and enable backup-offsite.timer.

Monitoring

Each job writes a *_last_success_timestamp_seconds metric into the node_exporter textfile directory. Alert on time() - backup_pull_last_success_timestamp_seconds and its offsite counterpart to catch a backup that has stopped running. Pairs directly with homelab-monitoring.

License

MIT, see LICENSE.

About

A layered, monitored 3-2-1 backup setup for a homelab, built from small shell scripts and systemd timers. Pull data, let a snapshotting filesystem own the history, push an encrypted copy offsite, and alert if any layer goes stale.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages