A boring backup routine for a small VPS
A one-gigabyte VPS does not need an elaborate backup system. It needs a routine that is boring enough that I actually follow it at two in the morning.
Copy before you change
Every change starts with a dated directory under /root/backup/. Configuration files, the application database and anything the change will touch go in there first. It takes seconds and removes most of the fear from editing a live machine.
B=/root/backup/$(date +%Y%m%d)-nginx
mkdir -p "$B" && cp -a /etc/nginx "$B/"
Keep the rollback next to the backup
A backup without a restore command is a puzzle for future me. I write a short rollback.sh into the same directory, so undoing a change is one command rather than an archaeology session.
Arm a timer for risky changes
When a change could cut off my own SSH session, I schedule the rollback before applying it:
systemd-run --on-active=900 /root/backup/.../rollback.sh
If everything still works, I cancel the timer. If I locked myself out, the machine fixes itself fifteen minutes later.
Test the restore
Once a quarter I restore a backup into a scratch directory and diff it against the live files. The first time I did this I found a backup script that had been silently skipping a directory for months.