Self-hosted backups: a 3-2-1 plan for your VPS and databases
5 min readInfrastructure · VPS · Self-hosting · Guides
Most people discover their backup strategy on the worst day of the year. A disk fails, a provider suspends an account, a script deletes the wrong folder, and the question changes from how do I run this server to what exactly do I still have. If the honest answer is a snapshot on the same machine, the answer is probably nothing.
This is a follow-up to my self-hosting posts on Coolify, Dokploy and RustDesk. Those tools make deploying easy, and easy deployment tends to hide how much state you now own: databases, uploaded files, configs and secrets. This post is a plan that a single person can run on a small VPS, built around the 3-2-1 rule and a habit most people skip: restoring.
The 3-2-1 rule
It is old, simple and still the right starting point. Keep three copies of your data: the live one and two backups. Store them on two different kinds of storage, so one failure mode cannot take both. Keep one copy off-site, in another location and ideally under another account, so a fire, a provider problem or a compromised login cannot reach it.
- Copy one: the running data on your VPS.
- Copy two: a local or provider-level backup, fast to restore from, such as a second disk or a provider snapshot.
- Copy three: an off-site, encrypted backup in object storage or on another machine you control.
- Optional but valuable: make the off-site copy hard to delete from the server it protects, so ransomware or a mistake cannot wipe the backups too.
A provider snapshot is useful, but it counts as the same ecosystem and often the same account. Treat it as a convenience for quick rollbacks, not as your off-site copy.
First, list what actually needs saving
Backups fail most often because of what was never included. Walk through your server and write down the state, separate from things you can rebuild.
- Databases - Postgres, MySQL, MongoDB, SQLite files. These need special handling, covered below.
- Uploaded files and app data - user uploads, Docker volumes and bind-mounted folders.
- Configuration - Compose files, Nginx configs,
.envfiles, cron jobs, systemd units. - Secrets and keys - SSH keys, TLS material, API tokens and the encryption key for the backups themselves.
- Not worth saving - the operating system, packages and container images, which you can reinstall.
Backing up databases the right way
Copying a live database's files while it is running can give you a corrupted, inconsistent copy that will not start. Use the database's own dump tool, which produces a consistent snapshot, and back up the dump file.
# Postgres running in Docker
docker exec db pg_dump -U postgres -Fc appdb > /backups/appdb-$(date +%F).dump
# MySQL / MariaDB
mysqldump --single-transaction -u root -p appdb > /backups/appdb-$(date +%F).sql
# SQLite: use the online backup, not a plain file copy
sqlite3 app.db ".backup '/backups/app-$(date +%F).db'"Dumps are logical backups, portable across versions and easy to restore into a fresh server. For very large databases, continuous archiving or point-in-time recovery lets you restore to a specific minute, but that adds real complexity. Start with nightly dumps and move up when your data size or tolerance for loss demands it.
Files: use a tool with deduplication and encryption
For files and dumps, tools like restic and BorgBackup are popular choices. They take incremental snapshots, deduplicate data so repeated backups cost little extra space, and encrypt everything before it leaves the server. Restic can write straight to S3-compatible object storage, an SFTP server or a local path.
export RESTIC_REPOSITORY=s3:https://objects.example.net/my-backups
export RESTIC_PASSWORD_FILE=/root/.restic-pass
restic init
restic backup /backups /srv/app/uploads /etc/nginx /srv/app/compose.yml
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
restic checkThe retention line decides how far back you can go: a week of dailies, a month of weeklies, half a year of monthlies in this example. Pick numbers that match how quickly you would notice a problem. If you only spot corruption after three weeks, seven days of history will not save you.
Run it on a schedule with a systemd timer or cron, and make it tell you when it fails. A silent backup job that broke in March is the most common failure of all. Send a success or failure ping to a monitoring service, or have the script email you on a non-zero exit code.
Failure scenarios worth planning for
These are scenarios, not stories from my servers. They are the failures a plan should answer, and each one points at a specific part of the 3-2-1 rule.
- The disk dies - the local copy and the live data go together. Recovery depends on the off-site copy.
- You delete the wrong thing - a quick restore from a recent local or snapshot copy is what you want, so keep one on the same network for speed.
- The VPS account is suspended or compromised - everything in that account is at risk. The off-site copy must live under different credentials.
- Ransomware or a bad script touches the backups too - if the server can freely delete its own backups, so can an attacker who gets in. Use write-only credentials or object lock where possible.
- A bug silently corrupts data for weeks - you only recover if your retention reaches back past the day it started.
- You forgot the encryption password - the backups exist and are useless. Store that key somewhere independent of the server.
The restore drill
This is the step that turns backups into a plan. Once a month, or at least after any change to the setup, restore on a different machine or a throwaway local container. Pull the latest snapshot, restore the database, start the app and check that it works and that recent data is present. Time it. Write the exact commands down. During an outage, you will be tired and stressed, and a tested checklist is worth far more than good intentions.
restic snapshots
restic restore latest --target /tmp/restore-test
createdb restoretest && pg_restore -d restoretest /tmp/restore-test/backups/appdb-2026-11-12.dumpWhere it bites
- Backing up the secret with the data - keep the backup password out of the same location as the backups.
- Costs creeping up - object storage is cheap but not free, and egress fees for restoring a large set can surprise you. Check your provider's current pricing.
- Backups of broken data - a backup faithfully preserves corruption. This is why version history matters.
- Docker volumes are not magic - they live on the host disk. A volume without a backup is still a single copy.
- Compliance - if you store personal data, backups are covered by the same privacy obligations, including deletion requests and encryption.
My rule: a backup is not finished until it has been restored once, and not trustworthy until it has been restored recently. Everything else in this post is machinery for making that sentence true.
Tools: restic.net, borgbackup.org

Written by
Shihab Hossain — Full-Stack Developer
I build thoughtful digital products from Bangladesh — fast web experiences with Next.js, Android apps with Flutter, and the infrastructure behind them.
Work with me