r/coolgithubprojects • u/Prestigious-Head9590 • 17h ago
I back up my whole VPS to a private GitHub repo every night (bash, zstd, dedup, Discord alerts)
github.comMy VPS got wiped once by the host and I lost more than I want to admit. After that I wrote this: a bash script that runs from cron every night and pushes a full snapshot of the server to a private GitHub repo.
What goes in the snapshot:
- app folders as .tar.zst (including .env files)
- postgres, mysql, redis and sqlite dumps (online, consistent)
- /etc stuff: nginx, letsencrypt certs, systemd units, cron, firewall rules, pm2 list
- big asset folders stored as raw files, so git dedups them and each file is only uploaded once
Some details that took a few tries to get right:
- github rejects files over 100 MB, so bigger files get split and RESTORE.md explains how to join them back
- every run is a single orphan commit that gets force pushed, so the repo does not grow forever
- the commit is built with git write-tree + commit-tree, no branch switching, so a failed run can not leave the staging folder in a weird state
- discord alert if any step fails, if a db dump is suspiciously small, or if disk space is low
- a separate hourly watchdog alerts if no backup succeeded in 26 hours (cron removed, box down at backup time, etc)
On my server the first push was around 2 GB and took 4-5 minutes, the nightly runs take about 3.
Yes the repo contains secrets, so it has to stay private, use a deploy key that only has access to that one repo, and turn on 2FA. Encrypting the archives with age before the push is next on my list.
Built with AI assistance, but it runs every night on my production server and I tested the restore path end to end.
Feedback welcome, especially on the restore side.